|
37 | 37 | ndindex, promote_dtypes, is_integer_dtype,
|
38 | 38 | is_float_dtype, not_equal, float64, asarray,
|
39 | 39 | dtype_ranges, full, true, false, assert_same_sign,
|
40 |
| - isnan) |
| 40 | + isnan, equal, less) |
41 | 41 | # We might as well use this implementation rather than requiring
|
42 | 42 | # mod.broadcast_shapes(). See test_equal() and others.
|
43 | 43 | from .test_broadcasting import broadcast_shapes
|
@@ -827,8 +827,26 @@ def test_remainder(args):
|
827 | 827 |
|
828 | 828 | @given(numeric_scalars)
|
829 | 829 | 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]) |
832 | 850 |
|
833 | 851 | @given(numeric_scalars)
|
834 | 852 | def test_sign(x):
|
|
0 commit comments