@@ -132,6 +132,7 @@ def test_negative_binomial(self):
132
132
# arguments without truncation.
133
133
self .prng .negative_binomial (0.5 , 0.5 )
134
134
135
+
135
136
class TestRandint (TestCase ):
136
137
137
138
rfunc = random .randint
@@ -157,7 +158,6 @@ def test_rng_zero_and_extremes(self):
157
158
lbnd = 0 if dt is np .bool_ else np .iinfo (dt ).min
158
159
ubnd = 2 if dt is np .bool_ else np .iinfo (dt ).max + 1
159
160
tgt = ubnd - 1
160
-
161
161
assert_equal (self .rfunc (tgt , tgt + 1 , size = 1000 , dtype = dt ), tgt )
162
162
tgt = lbnd
163
163
assert_equal (self .rfunc (tgt , tgt + 1 , size = 1000 , dtype = dt ), tgt )
@@ -261,22 +261,26 @@ def test_randint(self):
261
261
262
262
def test_random_integers (self ):
263
263
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 )
269
271
270
272
def test_random_integers_max_int (self ):
271
273
# Tests whether random_integers can generate the
272
274
# maximum allowed Python int that can be converted
273
275
# into a C long. Previous implementations of this
274
- # method have thrown an OverflowError when attemping
276
+ # method have thrown an OverflowError when attempting
275
277
# 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 )
280
284
281
285
def test_random_integers_deprecated (self ):
282
286
with warnings .catch_warnings ():
@@ -482,6 +486,10 @@ def test_exponential(self):
482
486
[0.68717433461363442 , 1.69175666993575979 ]])
483
487
assert_array_almost_equal (actual , desired , decimal = 15 )
484
488
489
+ def test_exponential_0 (self ):
490
+ assert_equal (mt19937 .exponential (scale = 0 ), 0 )
491
+ assert_raises (ValueError , mt19937 .exponential , scale = - 0. )
492
+
485
493
def test_f (self ):
486
494
mt19937 .seed (self .seed )
487
495
actual = mt19937 .f (12 , 77 , size = (3 , 2 ))
@@ -498,6 +506,10 @@ def test_gamma(self):
498
506
[31.71863275789960568 , 33.30143302795922011 ]])
499
507
assert_array_almost_equal (actual , desired , decimal = 14 )
500
508
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
+
501
513
def test_geometric (self ):
502
514
mt19937 .seed (self .seed )
503
515
actual = mt19937 .geometric (.123456789 , size = (3 , 2 ))
@@ -514,6 +526,10 @@ def test_gumbel(self):
514
526
[1.10651090478803416 , - 0.69535848626236174 ]])
515
527
assert_array_almost_equal (actual , desired , decimal = 15 )
516
528
529
+ def test_gumbel_0 (self ):
530
+ assert_equal (mt19937 .gumbel (scale = 0 ), 0 )
531
+ assert_raises (ValueError , mt19937 .gumbel , scale = - 0. )
532
+
517
533
def test_hypergeometric (self ):
518
534
mt19937 .seed (self .seed )
519
535
actual = mt19937 .hypergeometric (10.1 , 5.5 , 14 , size = (3 , 2 ))
@@ -548,6 +564,10 @@ def test_laplace(self):
548
564
[- 0.05391065675859356 , 1.74901336242837324 ]])
549
565
assert_array_almost_equal (actual , desired , decimal = 15 )
550
566
567
+ def test_laplace_0 (self ):
568
+ assert_equal (mt19937 .laplace (scale = 0 ), 0 )
569
+ assert_raises (ValueError , mt19937 .laplace , scale = - 0. )
570
+
551
571
def test_logistic (self ):
552
572
mt19937 .seed (self .seed )
553
573
actual = mt19937 .logistic (loc = .123456789 , scale = 2.0 , size = (3 , 2 ))
@@ -556,6 +576,10 @@ def test_logistic(self):
556
576
[- 0.21682183359214885 , 2.63373365386060332 ]])
557
577
assert_array_almost_equal (actual , desired , decimal = 15 )
558
578
579
+ def test_laplace_0 (self ):
580
+ assert_ (mt19937 .laplace (scale = 0 ) in [0 , 1 ])
581
+ assert_raises (ValueError , mt19937 .laplace , scale = - 0. )
582
+
559
583
def test_lognormal (self ):
560
584
mt19937 .seed (self .seed )
561
585
actual = mt19937 .lognormal (mean = .123456789 , sigma = 2.0 , size = (3 , 2 ))
@@ -564,6 +588,10 @@ def test_lognormal(self):
564
588
[65.72798501792723869 , 86.84341601437161273 ]])
565
589
assert_array_almost_equal (actual , desired , decimal = 13 )
566
590
591
+ def test_lognormal_0 (self ):
592
+ assert_equal (mt19937 .lognormal (sigma = 0 ), 1 )
593
+ assert_raises (ValueError , mt19937 .lognormal , sigma = - 0. )
594
+
567
595
def test_logseries (self ):
568
596
mt19937 .seed (self .seed )
569
597
actual = mt19937 .logseries (p = .923456789 , size = (3 , 2 ))
@@ -654,6 +682,10 @@ def test_normal(self):
654
682
[4.18552478636557357 , 4.46410668111310471 ]])
655
683
assert_array_almost_equal (actual , desired , decimal = 15 )
656
684
685
+ def test_normal_0 (self ):
686
+ assert_equal (mt19937 .normal (scale = 0 ), 0 )
687
+ assert_raises (ValueError , mt19937 .normal , scale = - 0. )
688
+
657
689
def test_pareto (self ):
658
690
mt19937 .seed (self .seed )
659
691
actual = mt19937 .pareto (a = .123456789 , size = (3 , 2 ))
@@ -701,6 +733,10 @@ def test_rayleigh(self):
701
733
[11.06066537006854311 , 17.35468505778271009 ]])
702
734
assert_array_almost_equal (actual , desired , decimal = 14 )
703
735
736
+ def test_rayleigh_0 (self ):
737
+ assert_equal (mt19937 .rayleigh (scale = 0 ), 0 )
738
+ assert_raises (ValueError , mt19937 .rayleigh , scale = - 0. )
739
+
704
740
def test_standard_cauchy (self ):
705
741
mt19937 .seed (self .seed )
706
742
actual = mt19937 .standard_cauchy (size = (3 , 2 ))
@@ -725,6 +761,10 @@ def test_standard_gamma(self):
725
761
[7.54838614231317084 , 8.012756093271868 ]])
726
762
assert_array_almost_equal (actual , desired , decimal = 14 )
727
763
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
+
728
768
def test_standard_normal (self ):
729
769
mt19937 .seed (self .seed )
730
770
actual = mt19937 .standard_normal (size = (3 , 2 ))
@@ -800,6 +840,10 @@ def test_weibull(self):
800
840
[0.67057783752390987 , 1.39494046635066793 ]])
801
841
assert_array_almost_equal (actual , desired , decimal = 15 )
802
842
843
+ def test_weibull_0 (self ):
844
+ assert_equal (mt19937 .weibull (a = 0 ), 0 )
845
+ assert_raises (ValueError , mt19937 .weibull , a = - 0. )
846
+
803
847
def test_zipf (self ):
804
848
mt19937 .seed (self .seed )
805
849
actual = mt19937 .zipf (a = 1.23 , size = (3 , 2 ))
@@ -1404,7 +1448,7 @@ def gen_random(state, out):
1404
1448
def test_multinomial (self ):
1405
1449
def gen_random (state , out ):
1406
1450
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 ))
1408
1452
1409
1453
# See Issue #4263
1410
1454
class TestSingleEltArrayInput (TestCase ):
0 commit comments