diff options
| author | Mark Dickinson <dickinsm@gmail.com> | 2010-11-07 15:31:41 (GMT) | 
|---|---|---|
| committer | Mark Dickinson <dickinsm@gmail.com> | 2010-11-07 15:31:41 (GMT) | 
| commit | a837aa62134468cc63d7acf1135b5f66fc08f12b (patch) | |
| tree | 8d721eb60119dd02af135b1f9490296bcf5d8be2 /Lib/test/test_cmath.py | |
| parent | 4ae5f138da539d071f75764094bec8c8ce73b0fa (diff) | |
| download | cpython-a837aa62134468cc63d7acf1135b5f66fc08f12b.zip cpython-a837aa62134468cc63d7acf1135b5f66fc08f12b.tar.gz cpython-a837aa62134468cc63d7acf1135b5f66fc08f12b.tar.bz2  | |
Update assertComplexIdentical to handle nans correctly.
Diffstat (limited to 'Lib/test/test_cmath.py')
| -rw-r--r-- | Lib/test/test_cmath.py | 37 | 
1 files changed, 32 insertions, 5 deletions
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index e3cf03e..15f635f 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -62,11 +62,38 @@ class CMathTests(unittest.TestCase):      def tearDown(self):          self.test_values.close() -    def assertComplexIdentical(self, a, b): -        """Fail if two complex numbers value or sign is different.""" -        self.assertEqual(a, b) -        self.assertEqual(math.copysign(1., a.real), math.copysign(1., b.real)) -        self.assertEqual(math.copysign(1., a.imag), math.copysign(1., b.imag)) +    def assertFloatIdentical(self, x, y): +        """Fail unless floats x and y are identical, in the sense that: +        (1) both x and y are nans, or +        (2) both x and y are infinities, with the same sign, or +        (3) both x and y are zeros, with the same sign, or +        (4) x and y are both finite and nonzero, and x == y + +        """ +        msg = 'floats {!r} and {!r} are not identical' + +        if math.isnan(x) or math.isnan(y): +            if math.isnan(x) and math.isnan(y): +                return +        elif x == y: +            if x != 0.0: +                return +            # both zero; check that signs match +            elif math.copysign(1.0, x) == math.copysign(1.0, y): +                return +            else: +                msg += ': zeros have different signs' +        self.fail(msg.format(x, y)) + +    def assertComplexIdentical(self, x, y): +        """Fail unless complex numbers x and y have equal values and signs. + +        In particular, if x and y both have real (or imaginary) part +        zero, but the zeros have different signs, this test will fail. + +        """ +        self.assertFloatIdentical(x.real, y.real) +        self.assertFloatIdentical(x.imag, y.imag)      def rAssertAlmostEqual(self, a, b, rel_err = 2e-15, abs_err = 5e-323,                             msg=None):  | 
