Skip to content

Commit 729592c

Browse files
tests: more tests for random funcs (#135)
* tests: more tests for random funcs
1 parent 1aca076 commit 729592c

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

tests/skipped_tests.tbl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ tests/test_random.py::test_random_check_otput[random_sample]
3030
tests/test_random.py::test_random_check_otput[randf]
3131
tests/test_random.py::test_random_check_otput[sample]
3232
tests/test_random.py::test_random_check_otput[rand]
33+
tests/test_random.py::test_randn_normal_distribution
34+
tests/test_random.py::test_radnom_seed[random]
35+
tests/test_random.py::test_radnom_seed[random_sample]
36+
tests/test_random.py::test_radnom_seed[randf]
37+
tests/test_random.py::test_radnom_seed[sample]
38+
tests/test_random.py::test_radnom_seed[rand]
3339
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_and
3440
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_or
3541
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_xor

tests/test_random.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import dpnp.random
44
import numpy
5-
5+
# from scipy import stats
6+
from numpy.testing import assert_allclose
67

78
@pytest.mark.parametrize("func",
89
[dpnp.random.rand,
@@ -49,3 +50,48 @@ def test_random_check_otput(func):
4950
for i in range(res.size):
5051
assert res[i] >= 0.0
5152
assert res[i] < 1.0
53+
54+
55+
def test_randn_normal_distribution():
56+
""" Check if the sample obtained from the dpnp.random.randn differs from
57+
the normal distribution.
58+
Using ``scipy.stats.normaltest``.
59+
60+
It is based on D’Agostino and Pearson’s test that combines skew
61+
and kurtosis to produce an omnibus test of normality,
62+
see: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.normaltest.html
63+
"""
64+
pts = 1000
65+
alpha = 0.05
66+
dpnp.random.seed(28041990)
67+
x = dpnp.random.randn(pts)
68+
_, p = stats.normaltest(x)
69+
# null hypothesis: x comes from a normal distribution.
70+
# The p-value is interpreted against an alpha of 5% and finds that the test
71+
# dataset does not significantly deviate from normal.
72+
# If p > alpha, the null hypothesis cannot be rejected.
73+
assert p > alpha
74+
75+
76+
@pytest.mark.parametrize("func",
77+
[dpnp.random.random,
78+
dpnp.random.random_sample,
79+
dpnp.random.randf,
80+
dpnp.random.sample,
81+
dpnp.random.rand],
82+
ids=['random', 'random_sample',
83+
'randf', 'sample',
84+
'rand'])
85+
def test_radnom_seed(func):
86+
seed = 28041990
87+
size = 100
88+
shape = (100, 1)
89+
if func in [dpnp.random.rand, dpnp.random.randn]:
90+
args = size
91+
else:
92+
args = shape
93+
dpnp.random.seed(seed)
94+
a1 = func(args)
95+
dpnp.random.seed(seed)
96+
a2 = func(args)
97+
assert_allclose(a1, a2, rtol=1e-07, atol=0)

0 commit comments

Comments
 (0)