Skip to content

Commit 8808c39

Browse files
committed
add test for random
1 parent cb96c63 commit 8808c39

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

test/test_random.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
import pytest
12
import numpy as np
23
import sharpy as sp
34

4-
def test_random_rand(shape, seed):
5-
sp.init(False)
5+
@pytest.fixture(params=[(), (6,), (6, 5), (6, 5, 4)])
6+
def shape(request):
7+
return request.param
8+
9+
@pytest.fixture(params=[0, 42, 66, 890, 1000])
10+
def seed(request):
11+
return request.param
12+
613

14+
def test_random_rand(shape, seed):
715
sp.random.seed(seed)
8-
a = sp.random.rand(*shape)
9-
assert(a.shape == shape)
16+
sp_data = sp.random.rand(*shape)
17+
18+
np.random.seed(seed)
19+
np_data = np.random.rand(*shape)
1020

11-
sp.fini()
21+
if isinstance(np_data, float):
22+
assert isinstance(sp_data, float) and sp_data == np_data
23+
else:
24+
assert np.allclose(sp.to_numpy(sp_data), np_data)

0 commit comments

Comments
 (0)