MCPcopy
hub / github.com/networkx/networkx / test_PythonRandomInterface_Generator

Function test_PythonRandomInterface_Generator

networkx/utils/tests/test_misc.py:238–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

236
237
238def test_PythonRandomInterface_Generator():
239 np = pytest.importorskip("numpy")
240
241 seed = 42
242 rng = np.random.default_rng(seed)
243 pri = PythonRandomInterface(np.random.default_rng(seed))
244
245 # make sure these functions are same as expected outcome
246 assert pri.randrange(3, 5) == rng.integers(3, 5)
247 assert pri.randrange(2) == rng.integers(0, 2)
248 assert pri.uniform(1, 10) == rng.uniform(1, 10)
249 assert pri.choice([1, 2, 3]) == rng.choice([1, 2, 3])
250 assert pri.gauss(0, 1) == rng.normal(0, 1)
251 assert pri.expovariate(1.5) == rng.exponential(1 / 1.5)
252 assert pri.paretovariate(2) == rng.pareto(2)
253 assert np.all(pri.shuffle([1, 2, 3]) == rng.shuffle([1, 2, 3]))
254 assert np.all(
255 pri.sample([1, 2, 3], 2) == rng.choice([1, 2, 3], (2,), replace=False)
256 )
257 assert np.all(
258 [pri.randint(3, 5) for _ in range(100)]
259 == [rng.integers(3, 6) for _ in range(100)]
260 )
261 assert pri.random() == rng.random()
262
263
264@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 11

randrangeMethod · 0.95
uniformMethod · 0.95
choiceMethod · 0.95
gaussMethod · 0.95
expovariateMethod · 0.95
paretovariateMethod · 0.95
shuffleMethod · 0.95
sampleMethod · 0.95
randintMethod · 0.95
randomMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…