diff options
author | Adrien Chauve <adrien.chauve@logilab.fr> | 2010-07-29 17:53:41 +0200 |
---|---|---|
committer | Adrien Chauve <adrien.chauve@logilab.fr> | 2010-07-29 17:53:41 +0200 |
commit | e770ad09f3ae646b823d6275192f4c8290885d42 (patch) | |
tree | d758f6f02c7c14bdc196912af18a2846084ac9d8 | |
parent | fac3eabf729f6e7a8b93bd0e8cc1b252ea2a3fba (diff) | |
download | logilab-common-e770ad09f3ae646b823d6275192f4c8290885d42.tar.gz |
[testlib] add relative tolerance to assertFloatAlmostEquals
-rw-r--r-- | testlib.py | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1039,18 +1039,20 @@ succeeded test into", osp.join(os.getcwd(), FILE_RESTART) self.assert_( obj is not None, msg ) @deprecated('Non-standard. Please use assertAlmostEqual instead.') - def assertFloatAlmostEquals(self, obj, other, prec=1e-5, msg=None): + def assertFloatAlmostEquals(self, obj, other, prec=1e-5, + relative_prec=1e-5, msg=None): """compares if two floats have a distance smaller than expected precision. :param obj: a Float :param other: another Float to be comparted to <obj> :param prec: a Float describing the precision + :param relative_prec: a Float describing the relative precision :param msg: a String for a custom message """ if msg is None: msg = "%r != %r" % (obj, other) - self.assert_(math.fabs(obj - other) < prec, msg) + self.assert_(math.fabs(obj - other) < prec+relative_prec*math.fabs(obj), msg) #@deprecated('[API] Non-standard. Please consider using a context here') def failUnlessRaises(self, excClass, callableObj, *args, **kwargs): |