MCPcopy Create free account
hub / github.com/bayesian-optimization/BayesianOptimization / test_ensure_rng

Function test_ensure_rng

tests/test_util.py:8–27  ·  view source on GitHub ↗

Test that ensure_rng properly handles different inputs.

()

Source from the content-addressed store, hash-verified

6
7
8def test_ensure_rng():
9 """Test that ensure_rng properly handles different inputs."""
10
11 # Test with None (should return a new RandomState)
12 rng1 = ensure_rng(None)
13 assert isinstance(rng1, np.random.RandomState)
14
15 # Test with int (should return a new RandomState seeded with that int)
16 rng2 = ensure_rng(123)
17 assert isinstance(rng2, np.random.RandomState)
18
19 # Test with RandomState (should return the same RandomState)
20 rng3 = np.random.RandomState(456)
21 rng4 = ensure_rng(rng3)
22 assert rng3 is rng4
23
24 # Test that different seeds produce different random numbers
25 rng5 = ensure_rng(1)
26 rng6 = ensure_rng(2)
27 assert rng5.random() != rng6.random()

Callers

nothing calls this directly

Calls 1

ensure_rngFunction · 0.90

Tested by

no test coverage detected