Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(14)

## Delta Between Two Patch Sets: Lib/test/test_complex.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years, 5 months ago
Right Patch Set: Created 6 years ago
 Left: Base Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None Right: Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None
« no previous file with change/comment | « Lib/test/test_compile.py ('k') | Lib/test/test_concurrent_futures.py » ('j') | no next file with change/comment »
LEFTRIGHT
1 import unittest 1 import unittest
2 from test import support 2 from test import support
3 3
4 from random import random 4 from random import random
5 from math import atan2, isnan, copysign 5 from math import atan2, isnan, copysign
6 import operator 6 import operator
7 7
8 INF = float("inf") 8 INF = float("inf")
9 NAN = float("nan") 9 NAN = float("nan")
10 # These tests ensure that complex math does the right thing 10 # These tests ensure that complex math does the right thing
(...skipping 83 matching lines...)
94 94
95 # Just for fun. 95 # Just for fun.
96 for i in range(100): 96 for i in range(100):
97 self.check_div(complex(random(), random()), 97 self.check_div(complex(random(), random()),
98 complex(random(), random())) 98 complex(random(), random()))
99 99
100 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j) 100 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
101 # FIXME: The following currently crashes on Alpha 101 # FIXME: The following currently crashes on Alpha
102 # self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j) 102 # self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j)
103 103
104 def test_truediv(self):
105 self.assertAlmostEqual(complex.__truediv__(2+0j, 1+1j), 1-1j) 104 self.assertAlmostEqual(complex.__truediv__(2+0j, 1+1j), 1-1j)
106 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j) 105 self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j)
107 106
108 def test_floordiv(self): 107 def test_floordiv(self):
109 self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 1.5+0j) 108 self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 1.5+0j)
110 self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 0+0j) 109 self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 0+0j)
111 110
112 def test_richcompare(self): 111 def test_richcompare(self):
113 self.assertIs(complex.__eq__(1+1j, 1<<10000), False) 112 self.assertIs(complex.__eq__(1+1j, 1<<10000), False)
114 self.assertIs(complex.__lt__(1+1j, None), NotImplemented) 113 self.assertIs(complex.__lt__(1+1j, None), NotImplemented)
(...skipping 182 matching lines...)
297 296
298 # SF bug 543840: complex(string) accepts strings with \0 297 # SF bug 543840: complex(string) accepts strings with \0
299 # Fixed in 2.3. 298 # Fixed in 2.3.
300 self.assertRaises(ValueError, complex, '1+1j\0j') 299 self.assertRaises(ValueError, complex, '1+1j\0j')
301 300
302 self.assertRaises(TypeError, int, 5+3j) 301 self.assertRaises(TypeError, int, 5+3j)
303 self.assertRaises(TypeError, int, 5+3j) 302 self.assertRaises(TypeError, int, 5+3j)
304 self.assertRaises(TypeError, float, 5+3j) 303 self.assertRaises(TypeError, float, 5+3j)
305 self.assertRaises(ValueError, complex, "") 304 self.assertRaises(ValueError, complex, "")
306 self.assertRaises(TypeError, complex, None) 305 self.assertRaises(TypeError, complex, None)
306 self.assertRaisesRegex(TypeError, "not 'NoneType'", complex, None)
307 self.assertRaises(ValueError, complex, "\0") 307 self.assertRaises(ValueError, complex, "\0")
308 self.assertRaises(ValueError, complex, "3\09") 308 self.assertRaises(ValueError, complex, "3\09")
309 self.assertRaises(TypeError, complex, "1", "2") 309 self.assertRaises(TypeError, complex, "1", "2")
310 self.assertRaises(TypeError, complex, "1", 42) 310 self.assertRaises(TypeError, complex, "1", 42)
311 self.assertRaises(TypeError, complex, 1, "2") 311 self.assertRaises(TypeError, complex, 1, "2")
312 self.assertRaises(ValueError, complex, "1+") 312 self.assertRaises(ValueError, complex, "1+")
313 self.assertRaises(ValueError, complex, "1+1j+1j") 313 self.assertRaises(ValueError, complex, "1+1j+1j")
314 self.assertRaises(ValueError, complex, "--") 314 self.assertRaises(ValueError, complex, "--")
315 self.assertRaises(ValueError, complex, "(1+2j") 315 self.assertRaises(ValueError, complex, "(1+2j")
316 self.assertRaises(ValueError, complex, "1+2j)") 316 self.assertRaises(ValueError, complex, "1+2j)")
(...skipping 312 matching lines...)
629 self.assertEqual(format(complex(INF, INF), 'F'), 'INF+INFj') 629 self.assertEqual(format(complex(INF, INF), 'F'), 'INF+INFj')
630 self.assertEqual(format(complex(1, INF), 'F'), '1.000000+INFj') 630 self.assertEqual(format(complex(1, INF), 'F'), '1.000000+INFj')
631 self.assertEqual(format(complex(INF, 1), 'F'), 'INF+1.000000j') 631 self.assertEqual(format(complex(INF, 1), 'F'), 'INF+1.000000j')
632 self.assertEqual(format(complex(INF, -1), 'F'), 'INF-1.000000j') 632 self.assertEqual(format(complex(INF, -1), 'F'), 'INF-1.000000j')
633 633
634 def test_main(): 634 def test_main():
635 support.run_unittest(ComplexTest) 635 support.run_unittest(ComplexTest)
636 636
637 if __name__ == "__main__": 637 if __name__ == "__main__":
638 test_main() 638 test_main()
LEFTRIGHT

This is Rietveld 894c83f36cb7+