8000 TST fix unstable test_newrand_set_seed (#25940) · scikit-learn/scikit-learn@9391b0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9391b0d

Browse files
ogriseljeremiedbb
andauthored
TST fix unstable test_newrand_set_seed (#25940)
Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
1 parent 1f934d6 commit 9391b0d

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

sklearn/svm/tests/test_bounds.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,24 @@ def test_ill_posed_min_c():
7272
_MAX_UNSIGNED_INT = 4294967295
7373

7474

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):
7789
"""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
8293

8394

8495
@pytest.mark.parametrize("seed", [-1, _MAX_UNSIGNED_INT + 1])
@@ -91,6 +102,9 @@ def test_newrand_set_seed_overflow(seed):
91102
@pytest.mark.parametrize("range_, n_pts", [(_MAX_UNSIGNED_INT, 10000), (100, 25)])
92103
def test_newrand_bounded_rand_int(range_, n_pts):
93104
"""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)
94108
n_iter = 100
95109
ks_pvals = []
96110
uniform_dist = stats.uniform(loc=0, scale=range_)

0 commit comments

Comments
 (0)
0