Skip to content

Commit 7b27515

Browse files
author
Chaluvadi
committed
added unit tests for range function
1 parent a657583 commit 7b27515

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/test_range.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import random
2+
3+
import pytest
4+
5+
import arrayfire_wrapper.dtypes as dtypes
6+
import arrayfire_wrapper.lib as wrapper
7+
8+
9+
@pytest.mark.parametrize(
10+
"shape",
11+
[
12+
(),
13+
(random.randint(1, 10), 1),
14+
(random.randint(1, 10), random.randint(1, 10)),
15+
(random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
16+
(random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
17+
],
18+
)
19+
def test_range_shape(shape: tuple) -> None:
20+
"""Test if the range function output an AFArray with the correct shape"""
21+
dim = 2
22+
dtype = dtypes.s16
23+
24+
result = wrapper.range(shape, dim, dtype)
25+
26+
assert wrapper.get_dims(result)[0 : len(shape)] == shape # noqa: E203
27+
28+
29+
def test_range_invalid_shape() -> None:
30+
"""Test if range function correctly handles an invalid shape"""
31+
with pytest.raises(TypeError):
32+
shape = (
33+
random.randint(1, 10),
34+
random.randint(1, 10),
35+
random.randint(1, 10),
36+
random.randint(1, 10),
37+
random.randint(1, 10),
38+
)
39+
dim = 2
40+
dtype = dtypes.s16
41+
42+
wrapper.range(shape, dim, dtype)
43+
44+
45+
@pytest.mark.parametrize(
46+
"shape",
47+
[
48+
(),
49+
(random.randint(1, 10), 1),
50+
(random.randint(1, 10), random.randint(1, 10)),
51+
(random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
52+
(random.randint(1, 10), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)),
53+
],
54+
)
55+
def test_range_invalid_dim(shape: tuple) -> None:
56+
"""Test if the range function can properly handle and invalid dimension given"""
57+
with pytest.raises(RuntimeError):
58+
dim = random.randint(4, 10)
59+
dtype = dtypes.s16
60+
61+
wrapper.range(shape, dim, dtype)

0 commit comments

Comments
 (0)