Skip to content

Commit 0499550

Browse files
Tommy Odlandtommyod
authored andcommitted
Seed all rng in testing
1 parent a07d65b commit 0499550

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

tests/fmudesign/test_design_distributions.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ def test_draw_values_pert(seed):
7979
assert np.isclose(values.mean(), 5, atol=0.55)
8080

8181

82-
def test_sample_discrete():
83-
rng = np.random.default_rng()
82+
@pytest.mark.parametrize("seed", range(100))
83+
def test_sample_discrete(seed):
84+
rng = np.random.default_rng(seed)
8485

8586
outcomes = ["foo", "bar.com"]
8687
# Test basic functionality
@@ -97,16 +98,17 @@ def test_sample_discrete():
9798

9899
# Test weights that don't sum to 1
99100
weighted_values = dists.sample_discrete(
100-
[",".join(outcomes), "2,6"], rng.uniform(size=100)
101+
[",".join(outcomes), "2,6"], rng.uniform(size=1000)
101102
)
102103
# Should see roughly 25% foo and 75% bar.com
103104
foo_count = np.sum(weighted_values == "foo")
104-
assert 15 <= foo_count <= 35 # Allow some variance due to randomness
105+
assert 200 <= foo_count <= 300 # Allow some variance due to randomness
105106

106107

107-
def test_draw_values():
108+
@pytest.mark.parametrize("seed", range(100))
109+
def test_draw_values(seed):
108110
"""Test the wrapper function for drawing values"""
109-
rng = np.random.default_rng()
111+
rng = np.random.default_rng(seed)
110112

111113
quantiles = rng.uniform(size=10)
112114

tests/forward_models/pyscal/test_pyscal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
)
4545
def test_fm_pyscal(dframe, runargs, tmpdir):
4646
"""Parametrized test function for fm_pyscal"""
47+
random.seed(42)
48+
4749
tmpdir.chdir()
4850
dframe.to_csv("relperm-input.csv", index=False)
4951

0 commit comments

Comments
 (0)