Debian Codegraph @

hypothesis-python/tests/numpy/test_floor_ceil.py

raw
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Copyright the Hypothesis Authors.
5 # Individual contributors are listed in AUTHORS.rst and the git log.
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public License,
8 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 # obtain one at https://mozilla.org/MPL/2.0/.
10
11 import math
12
13 import numpy as np
14 import pytest
15
16 from hypothesis.internal.compat import ceil, floor
17
18
19 @pytest.mark.parametrize(
20 "value",
21 [
22 # These are strings so that the test names are easier to read.
23 "2**64+1",
24 "2**64-1",
25 "2**63+1",
26 "2**53+1",
27 "-2**53-1",
28 "-2**63+1",
29 "-2**63-1",
30 "-2**64+1",
31 "-2**64-1",
32 ],
33 )
34 def test_our_floor_and_ceil_avoid_numpy_rounding(value):
35 a = np.array(eval(value))
36 f = floor(a)
37 c = ceil(a)
38
39 # Check *exact* type - we don't want to allow a subclass of int here
40 assert type(f) == int
41 assert type(c) == int
42
43 # Using math.floor or math.ceil for these values would give an incorrect result.
44 assert (math.floor(a) > a) or (math.ceil(a) < a)
45
46 assert f <= a <= c
47 assert f + 1 > a > c - 1