def test_uniform(low, high, rng): n = 100 dist = Uniform(low, high) samples = dist.sample(n, rng=rng) if low < high: assert np.all(samples >= low) assert np.all(samples < high) else: assert np.all(samples <= low) assert np.all(samples > high) hist, _ = np.histogram(samples, bins=5) assert np.allclose(hist - np.mean(hist), 0, atol=0.1 * n)
def test_uniform(low, high, rng, allclose): n = 200 dist = Uniform(low, high) samples = dist.sample(n, rng=rng) if low < high: assert np.all(samples >= low) assert np.all(samples < high) else: assert np.all(samples <= low) assert np.all(samples > high) histogram, _ = np.histogram(samples, bins=5) assert allclose(histogram, np.mean(histogram), atol=0.1 * n) # test `integer=true` dist = Uniform(low, high, integer=True) if low < high: samples = dist.sample(n, rng=rng) assert np.all(samples >= low) assert np.all(samples < high) assert np.all(samples % 1 == 0) else: with pytest.raises(ValueError): samples = dist.sample(n, rng=rng)