-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtest_abs.py
53 lines (37 loc) · 1.41 KB
/
test_abs.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
"""
Special cases tests for abs.
These tests are generated from the special cases listed in the spec.
NOTE: This file is generated automatically by the generate_stubs.py script. Do
not modify it directly.
"""
from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, zero
from ..hypothesis_helpers import numeric_arrays
from .._array_module import abs
from hypothesis import given
@given(numeric_arrays)
def test_abs_special_cases_one_arg_equal_1(arg1):
"""
Special case test for `abs(x, /)`:
- If `x_i` is `NaN`, the result is `NaN`.
"""
res = abs(arg1)
mask = exactly_equal(arg1, NaN(arg1.shape, arg1.dtype))
assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask])
@given(numeric_arrays)
def test_abs_special_cases_one_arg_equal_2(arg1):
"""
Special case test for `abs(x, /)`:
- If `x_i` is `-0`, the result is `+0`.
"""
res = abs(arg1)
mask = exactly_equal(arg1, -zero(arg1.shape, arg1.dtype))
assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask])
@given(numeric_arrays)
def test_abs_special_cases_one_arg_equal_3(arg1):
"""
Special case test for `abs(x, /)`:
- If `x_i` is `-infinity`, the result is `+infinity`.
"""
res = abs(arg1)
mask = exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype))
assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask])