@@ -132,6 +132,7 @@ def test_negative_binomial(self):
132132 # arguments without truncation.
133133 self .prng .negative_binomial (0.5 , 0.5 )
134134
135+
135136class TestRandint (TestCase ):
136137
137138 rfunc = random .randint
@@ -157,7 +158,6 @@ def test_rng_zero_and_extremes(self):
157158 lbnd = 0 if dt is np .bool_ else np .iinfo (dt ).min
158159 ubnd = 2 if dt is np .bool_ else np .iinfo (dt ).max + 1
159160 tgt = ubnd - 1
160-
161161 assert_equal (self .rfunc (tgt , tgt + 1 , size = 1000 , dtype = dt ), tgt )
162162 tgt = lbnd
163163 assert_equal (self .rfunc (tgt , tgt + 1 , size = 1000 , dtype = dt ), tgt )
@@ -261,22 +261,26 @@ def test_randint(self):
261261
262262 def test_random_integers (self ):
263263 mt19937 .seed (self .seed )
264- actual = mt19937 .random_integers (- 99 , 99 , size = (3 , 2 ))
265- desired = np .array ([[31 , 3 ],
266- [- 52 , 41 ],
267- [- 48 , - 66 ]])
268- assert_array_equal (actual , desired )
264+ with warnings .catch_warnings ():
265+ warnings .simplefilter ("ignore" , DeprecationWarning )
266+ actual = mt19937 .random_integers (- 99 , 99 , size = (3 , 2 ))
267+ desired = np .array ([[31 , 3 ],
268+ [- 52 , 41 ],
269+ [- 48 , - 66 ]])
270+ assert_array_equal (actual , desired )
269271
270272 def test_random_integers_max_int (self ):
271273 # Tests whether random_integers can generate the
272274 # maximum allowed Python int that can be converted
273275 # into a C long. Previous implementations of this
274- # method have thrown an OverflowError when attemping
276+ # method have thrown an OverflowError when attempting
275277 # to generate this integer.
276- actual = mt19937 .random_integers (np .iinfo ('l' ).max ,
277- np .iinfo ('l' ).max )
278- desired = np .iinfo ('l' ).max
279- assert_equal (actual , desired )
278+ with warnings .catch_warnings ():
279+ warnings .simplefilter ("ignore" , DeprecationWarning )
280+ actual = mt19937 .random_integers (np .iinfo ('l' ).max ,
281+ np .iinfo ('l' ).max )
282+ desired = np .iinfo ('l' ).max
283+ assert_equal (actual , desired )
280284
281285 def test_random_integers_deprecated (self ):
282286 with warnings .catch_warnings ():
@@ -482,6 +486,10 @@ def test_exponential(self):
482486 [0.68717433461363442 , 1.69175666993575979 ]])
483487 assert_array_almost_equal (actual , desired , decimal = 15 )
484488
489+ def test_exponential_0 (self ):
490+ assert_equal (mt19937 .exponential (scale = 0 ), 0 )
491+ assert_raises (ValueError , mt19937 .exponential , scale = - 0. )
492+
485493 def test_f (self ):
486494 mt19937 .seed (self .seed )
487495 actual = mt19937 .f (12 , 77 , size = (3 , 2 ))
@@ -498,6 +506,10 @@ def test_gamma(self):
498506 [31.71863275789960568 , 33.30143302795922011 ]])
499507 assert_array_almost_equal (actual , desired , decimal = 14 )
500508
509+ def test_gamma_0 (self ):
510+ assert_equal (mt19937 .gamma (shape = 0 , scale = 0 ), 0 )
511+ assert_raises (ValueError , mt19937 .gamma , shape = - 0. , scale = - 0. )
512+
501513 def test_geometric (self ):
502514 mt19937 .seed (self .seed )
503515 actual = mt19937 .geometric (.123456789 , size = (3 , 2 ))
@@ -514,6 +526,10 @@ def test_gumbel(self):
514526 [1.10651090478803416 , - 0.69535848626236174 ]])
515527 assert_array_almost_equal (actual , desired , decimal = 15 )
516528
529+ def test_gumbel_0 (self ):
530+ assert_equal (mt19937 .gumbel (scale = 0 ), 0 )
531+ assert_raises (ValueError , mt19937 .gumbel , scale = - 0. )
532+
517533 def test_hypergeometric (self ):
518534 mt19937 .seed (self .seed )
519535 actual = mt19937 .hypergeometric (10.1 , 5.5 , 14 , size = (3 , 2 ))
@@ -548,6 +564,10 @@ def test_laplace(self):
548564 [- 0.05391065675859356 , 1.74901336242837324 ]])
549565 assert_array_almost_equal (actual , desired , decimal = 15 )
550566
567+ def test_laplace_0 (self ):
568+ assert_equal (mt19937 .laplace (scale = 0 ), 0 )
569+ assert_raises (ValueError , mt19937 .laplace , scale = - 0. )
570+
551571 def test_logistic (self ):
552572 mt19937 .seed (self .seed )
553573 actual = mt19937 .logistic (loc = .123456789 , scale = 2.0 , size = (3 , 2 ))
@@ -556,6 +576,10 @@ def test_logistic(self):
556576 [- 0.21682183359214885 , 2.63373365386060332 ]])
557577 assert_array_almost_equal (actual , desired , decimal = 15 )
558578
579+ def test_laplace_0 (self ):
580+ assert_ (mt19937 .laplace (scale = 0 ) in [0 , 1 ])
581+ assert_raises (ValueError , mt19937 .laplace , scale = - 0. )
582+
559583 def test_lognormal (self ):
560584 mt19937 .seed (self .seed )
561585 actual = mt19937 .lognormal (mean = .123456789 , sigma = 2.0 , size = (3 , 2 ))
@@ -564,6 +588,10 @@ def test_lognormal(self):
564588 [65.72798501792723869 , 86.84341601437161273 ]])
565589 assert_array_almost_equal (actual , desired , decimal = 13 )
566590
591+ def test_lognormal_0 (self ):
592+ assert_equal (mt19937 .lognormal (sigma = 0 ), 1 )
593+ assert_raises (ValueError , mt19937 .lognormal , sigma = - 0. )
594+
567595 def test_logseries (self ):
568596 mt19937 .seed (self .seed )
569597 actual = mt19937 .logseries (p = .923456789 , size = (3 , 2 ))
@@ -654,6 +682,10 @@ def test_normal(self):
654682 [4.18552478636557357 , 4.46410668111310471 ]])
655683 assert_array_almost_equal (actual , desired , decimal = 15 )
656684
685+ def test_normal_0 (self ):
686+ assert_equal (mt19937 .normal (scale = 0 ), 0 )
687+ assert_raises (ValueError , mt19937 .normal , scale = - 0. )
688+
657689 def test_pareto (self ):
658690 mt19937 .seed (self .seed )
659691 actual = mt19937 .pareto (a = .123456789 , size = (3 , 2 ))
@@ -701,6 +733,10 @@ def test_rayleigh(self):
701733 [11.06066537006854311 , 17.35468505778271009 ]])
702734 assert_array_almost_equal (actual , desired , decimal = 14 )
703735
736+ def test_rayleigh_0 (self ):
737+ assert_equal (mt19937 .rayleigh (scale = 0 ), 0 )
738+ assert_raises (ValueError , mt19937 .rayleigh , scale = - 0. )
739+
704740 def test_standard_cauchy (self ):
705741 mt19937 .seed (self .seed )
706742 actual = mt19937 .standard_cauchy (size = (3 , 2 ))
@@ -725,6 +761,10 @@ def test_standard_gamma(self):
725761 [7.54838614231317084 , 8.012756093271868 ]])
726762 assert_array_almost_equal (actual , desired , decimal = 14 )
727763
764+ def test_standard_gamma_0 (self ):
765+ assert_equal (mt19937 .standard_gamma (shape = 0 ), 0 )
766+ assert_raises (ValueError , mt19937 .standard_gamma , shape = - 0. )
767+
728768 def test_standard_normal (self ):
729769 mt19937 .seed (self .seed )
730770 actual = mt19937 .standard_normal (size = (3 , 2 ))
@@ -800,6 +840,10 @@ def test_weibull(self):
800840 [0.67057783752390987 , 1.39494046635066793 ]])
801841 assert_array_almost_equal (actual , desired , decimal = 15 )
802842
843+ def test_weibull_0 (self ):
844+ assert_equal (mt19937 .weibull (a = 0 ), 0 )
845+ assert_raises (ValueError , mt19937 .weibull , a = - 0. )
846+
803847 def test_zipf (self ):
804848 mt19937 .seed (self .seed )
805849 actual = mt19937 .zipf (a = 1.23 , size = (3 , 2 ))
@@ -1404,7 +1448,7 @@ def gen_random(state, out):
14041448 def test_multinomial (self ):
14051449 def gen_random (state , out ):
14061450 out [...] = state .multinomial (10 , [1 / 6. ]* 6 , size = 10000 )
1407- self .check_function (gen_random , sz = (10000 ,6 ))
1451+ self .check_function (gen_random , sz = (10000 , 6 ))
14081452
14091453# See Issue #4263
14101454class TestSingleEltArrayInput (TestCase ):
0 commit comments