Skip to content

Commit c1dba80

Browse files
committed
Add an elementwise test for round
1 parent 8b4b4f6 commit c1dba80

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

array_api_tests/test_elementwise_functions.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
ndindex, promote_dtypes, is_integer_dtype,
3838
is_float_dtype, not_equal, float64, asarray,
3939
dtype_ranges, full, true, false, assert_same_sign,
40-
isnan)
40+
isnan, equal, less)
4141
# We might as well use this implementation rather than requiring
4242
# mod.broadcast_shapes(). See test_equal() and others.
4343
from .test_broadcasting import broadcast_shapes
@@ -827,8 +827,26 @@ def test_remainder(args):
827827

828828
@given(numeric_scalars)
829829
def test_round(x):
830-
# a = _array_module.round(x)
831-
pass
830+
a = _array_module.round(x)
831+
832+
# Test that the result is integral
833+
finite = isfinite(x)
834+
assert_integral(a[finite])
835+
836+
# round(x) should be the nearest integer to x. The case where there is a
837+
# tie (round to even) is already handled by the special cases tests.
838+
839+
# This is the same strategy used in the mask in the
840+
# test_round_special_cases_one_arg_two_integers_equally_close special
841+
# cases test.
842+
floor = _array_module.floor(x)
843+
ceil = _array_module.ceil(x)
844+
over = _array_module.subtract(x, floor)
845+
under = _array_module.subtract(ceil, x)
846+
round_down = less(over, under)
847+
round_up = less(under, over)
848+
assert_exactly_equal(a[round_down], floor[round_down])
849+
assert_exactly_equal(a[round_up], ceil[round_up])
832850

833851
@given(numeric_scalars)
834852
def test_sign(x):

0 commit comments

Comments
 (0)