@@ -72,13 +72,24 @@ def test_ill_posed_min_c():
72
72
_MAX_UNSIGNED_INT = 4294967295
73
73
74
74
75
- @pytest .mark .parametrize ("seed, val" , [(None , 81 ), (0 , 54 ), (_MAX_UNSIGNED_INT , 9 )])
76
- def test_newrand_set_seed (seed , val ):
75
+ def test_newrand_default ():
76
+ """Test that bounded_rand_int_wrap without seeding respects the range
77
+
78
+ Note this test should pass either if executed alone, or in conjunctions
79
+ with other tests that call set_seed explicit in any order: it checks
80
+ invariants on the RNG instead of specific values.
81
+ """
82
+ generated = [bounded_rand_int_wrap (100 ) for _ in range (10 )]
83
+ assert all (0 <= x < 100 for x in generated )
84
+ assert not all (x == generated [0 ] for x in generated )
85
+
86
+
87
+ @pytest .mark .parametrize ("seed, expected" , [(0 , 54 ), (_MAX_UNSIGNED_INT , 9 )])
88
+ def test_newrand_set_seed (seed , expected ):
77
89
"""Test that `set_seed` produces deterministic results"""
78
- if seed is not None :
79
- set_seed_wrap (seed )
80
- x = bounded_rand_int_wrap (100 )
81
- assert x == val , f"Expected { val } but got { x } instead"
90
+ set_seed_wrap (seed )
91
+ generated = bounded_rand_int_wrap (100 )
92
+ assert generated == expected
82
93
83
94
84
95
@pytest .mark .parametrize ("seed" , [- 1 , _MAX_UNSIGNED_INT + 1 ])
@@ -91,6 +102,9 @@ def test_newrand_set_seed_overflow(seed):
91
102
@pytest .mark .parametrize ("range_, n_pts" , [(_MAX_UNSIGNED_INT , 10000 ), (100 , 25 )])
92
103
def test_newrand_bounded_rand_int (range_ , n_pts ):
93
104
"""Test that `bounded_rand_int` follows a uniform distribution"""
105
+ # XXX: this test is very seed sensitive: either it is wrong (too strict?)
106
+ # or the wrapped RNG is not uniform enough, at least on some platforms.
107
+ set_seed_wrap (42 )
94
108
n_iter = 100
95
109
ks_pvals = []
96
110
uniform_dist = stats .uniform (loc = 0 , scale = range_ )
0 commit comments