Reduce the default absolute error threshold to 1e-12.

This commit is contained in:
Kale Kundert 2016-03-07 16:43:53 -08:00
parent bf97d5b817
commit b8a8382c2c
1 changed files with 8 additions and 5 deletions

View File

@ -1,4 +1,5 @@
""" Python test discovery, setup and run of test functions. """ """ Python test discovery, setup and run of test functions. """
import fnmatch import fnmatch
import functools import functools
import inspect import inspect
@ -1379,7 +1380,7 @@ class approx(object):
you're expecting and ``a`` is the value you're comparing to. This you're expecting and ``a`` is the value you're comparing to. This
definition breaks down when the numbers being compared get very close to definition breaks down when the numbers being compared get very close to
zero, so ``approx`` will also consider two numbers to be equal if the zero, so ``approx`` will also consider two numbers to be equal if the
absolute difference between them is less than 1e-100. absolute difference between them is less than 1e-12.
Both the relative and absolute error thresholds can be changed by passing Both the relative and absolute error thresholds can be changed by passing
arguments to the ``approx`` constructor:: arguments to the ``approx`` constructor::
@ -1393,13 +1394,15 @@ class approx(object):
Note that if you specify ``abs`` but not ``rel``, the comparison will not Note that if you specify ``abs`` but not ``rel``, the comparison will not
consider the relative error between the two values at all. In other words, consider the relative error between the two values at all. In other words,
two number that are within the default relative error threshold of 1e-6 two numbers that are within the default relative error threshold of 1e-6
will still be considered unequal if they exceed the specified absolute will still be considered unequal if they exceed the specified absolute
error threshold:: error threshold::
>>> 0.1 + 0.2 == approx(0.3, abs=1e-100) >>> 1 + 1e-8 == approx(1)
True
>>> 1 + 1e-8 == approx(1, abs=1e-12)
False False
>>> 0.1 + 0.2 == approx(0.3, rel=1e-6, abs=1e-100) >>> 1 + 1e-8 == approx(1, rel=1e-6, abs=1e-12)
True True
""" """
@ -1429,7 +1432,7 @@ class approx(object):
return almost_eq(actual, expected) return almost_eq(actual, expected)
def _get_margin(self, x): def _get_margin(self, x):
margin = self.max_absolute_error or 1e-100 margin = self.max_absolute_error or 1e-12
if self.max_relative_error is None: if self.max_relative_error is None:
if self.max_absolute_error is not None: if self.max_absolute_error is not None: