Extend unittest's fail*AlmostEqual methods to work on complex numbers.

This commit is contained in:
Jeffrey Yasskin 2007-09-06 18:55:17 +00:00
parent d3f6c9d17b
commit 1cc5544345

View File

@ -339,7 +339,7 @@ class TestCase:
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
"""
if round(second-first, places) != 0:
if round(abs(second-first), places) != 0:
raise self.failureException(msg or '%r != %r within %r places'
% (first, second, places))
@ -351,7 +351,7 @@ class TestCase:
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
"""
if round(second-first, places) == 0:
if round(abs(second-first), places) == 0:
raise self.failureException(msg or '%r == %r within %r places'
% (first, second, places))