Skip to content

Commit 2c31c2b

Browse files
committed
tests: more tests for random funcs
* added test_randn_normal_distribution * added test_radnom_seed * skipped tests * scipy import under the coment currently : TODO
1 parent 68815e3 commit 2c31c2b

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-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: 35 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_array_equal
67

78
@pytest.mark.parametrize("func",
89
[dpnp.random.rand,
@@ -49,3 +50,36 @@ 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+
pts = 1000
57+
alpha = 0.05
58+
dpnp.random.seed(28041990)
59+
x = dpnp.random.randn(pts)
60+
_, p = stats.normaltest(x)
61+
assert p > alpha
62+
63+
64+
@pytest.mark.parametrize("func",
65+
[dpnp.random.random,
66+
dpnp.random.random_sample,
67+
dpnp.random.randf,
68+
dpnp.random.sample,
69+
dpnp.random.rand],
70+
ids=['random', 'random_sample',
71+
'randf', 'sample',
72+
'rand'])
73+
def test_radnom_seed(func):
74+
seed = 28041990
75+
size = 100
76+
shape = (100, 1)
77+
if func in [dpnp.random.rand, dpnp.random.randn]:
78+
args = size
79+
else:
80+
args = shape
81+
dpnp.random.seed(seed)
82+
a1 = func(args)
83+
dpnp.random.seed(seed)
84+
a2 = func(args)
85+
assert_array_equal(a1, a2)

0 commit comments

Comments
 (0)