joythief.numbers module¶
Matchers for numeric types (e.g. float).
- class joythief.numbers.CloseTo(expected, *, rel_tol=None, abs_tol=None)[source]¶
-
Matches any numeric value approximately equal to an expected value.
Comparison is delegated to
math.isclose(), so the same tolerance semantics apply: the relative tolerance is the maximum allowed difference relative to the larger absolute value of the inputs, and the absolute tolerance is the minimum allowed difference - useful when comparing values near zero.- Parameters:
- Raises:
ValueError – if either tolerance is negative, or
rel_tolis not less than1.0.
- class joythief.numbers.NaN(*args, **kwargs)[source]¶
-
Matches any
floatinstance representing NaN.IEEE 754 NaN (“not a number”) instances are, by definition, not equal to each other. This matcher compares equal to e.g.
math.nanorfloat("nan")usingmath.isnan().Originally formulated for this answer.
- Parameters:
args (tp.Any)
kwargs (tp.Any)