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