Skip to content

Commit

Permalink
Copy floating point nastiness tricks from complex_numers() tests to f…
Browse files Browse the repository at this point in the history
…rom_dtype tests
  • Loading branch information
felixdivo committed Feb 4, 2023
1 parent 487f809 commit 133944a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions hypothesis-python/tests/numpy/test_from_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.

import sys

import numpy as np
import pytest

Expand Down Expand Up @@ -197,15 +199,28 @@ def test_arrays_gives_useful_error_on_inconsistent_time_unit():
(float, {"allow_nan": False}, lambda x: not np.isnan(x)),
(float, {"allow_infinity": False}, lambda x: not np.isinf(x)),
(float, {"allow_nan": False, "allow_infinity": False}, np.isfinite),
# Complex numbers: bounds and excluding nonfinites
(complex, {"allow_nan": False}, lambda x: not np.isnan(x)),
(complex, {"allow_infinity": False}, lambda x: not np.isinf(x)),
(complex, {"allow_nan": False, "allow_infinity": False}, np.isfinite),
(complex, {"min_magnitude": 1e3}, lambda x: np.abs(x) >= 1e3),
(complex, {"max_magnitude": 1e2}, lambda x: np.abs(x) <= 1e2),
(
complex,
{"min_magnitude": 1e3},
lambda x: abs(x) >= 1e3 * (1 + sys.float_info.epsilon),
),
(
complex,
{"max_magnitude": 1e2},
lambda x: abs(x) <= 1e2 * (1 + sys.float_info.epsilon),
),
(
complex,
{"min_magnitude": 1, "max_magnitude": 1e6},
lambda x: 1 <= np.abs(x) <= 1e6,
lambda x: (
(1 - sys.float_info.epsilon)
<= abs(x)
<= 1e6 * (1 + sys.float_info.epsilon)
),
),
# Integer bounds, limited to the representable range
("int8", {"min_value": -1, "max_value": 1}, lambda x: -1 <= x <= 1),
Expand Down

0 comments on commit 133944a

Please sign in to comment.