MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / test_rand

Function test_rand

tests/test_RandomNumberGenerator.py:45–57  ·  view source on GitHub ↗

Tests that repeatedly calling ``rand()`` should result in a sample that is approximately uniformly distributed.

(seed: int)

Source from the content-addressed store, hash-verified

43
44@mark.parametrize("seed", [2, 10, 42])
45def test_rand(seed: int):
46 """
47 Tests that repeatedly calling ``rand()`` should result in a sample that is
48 approximately uniformly distributed.
49 """
50 rng = RandomNumberGenerator(seed)
51 sample = np.array([rng.rand() for _ in range(10_000)])
52
53 # The sample should be almost uniform, so mean 1/ 2 and variance 1 / 12,
54 # and every realisation needs to be in [0, 1].
55 assert_allclose(sample.mean(), 1 / 2, atol=1e-3)
56 assert_allclose(sample.var(), 1 / 12, atol=1e-3)
57 assert_(0 <= sample.min() < sample.max() <= 1)
58
59
60@mark.parametrize("state", [[1, 2, 3, 4], [10, 14, 274, 83]])

Callers

nothing calls this directly

Calls 4

randMethod · 0.95
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected