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

Side by Side Diff: Lib/test/test_complex.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_compile.py ('k') | Lib/test/test_concurrent_futures.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 self.assertEqual(a ** -30, a ** -30) 197 self.assertEqual(a ** -30, a ** -30)
198 198
199 self.assertEqual(0.0j ** 0, 1) 199 self.assertEqual(0.0j ** 0, 1)
200 200
201 b = 5.1+2.3j 201 b = 5.1+2.3j
202 self.assertRaises(ValueError, pow, a, b, 0) 202 self.assertRaises(ValueError, pow, a, b, 0)
203 203
204 def test_boolcontext(self): 204 def test_boolcontext(self):
205 for i in range(100): 205 for i in range(100):
206 self.assertTrue(complex(random() + 1e-6, random() + 1e-6)) 206 self.assertTrue(complex(random() + 1e-6, random() + 1e-6))
207 self.assertTrue(not complex(0.0, 0.0)) 207 self.assertFalse(complex(0.0, 0.0))
208 208
209 def test_conjugate(self): 209 def test_conjugate(self):
210 self.assertClose(complex(5.3, 9.8).conjugate(), 5.3-9.8j) 210 self.assertClose(complex(5.3, 9.8).conjugate(), 5.3-9.8j)
211 211
212 def test_constructor(self): 212 def test_constructor(self):
213 class OS: 213 class OS:
214 def __init__(self, value): self.value = value 214 def __init__(self, value): self.value = value
215 def __complex__(self): return self.value 215 def __complex__(self): return self.value
216 class NS(object): 216 class NS(object):
217 def __init__(self, value): self.value = value 217 def __init__(self, value): self.value = value
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 def split_zeros(x): 282 def split_zeros(x):
283 """Function that produces different results for 0. and -0.""" 283 """Function that produces different results for 0. and -0."""
284 return atan2(x, -1.) 284 return atan2(x, -1.)
285 285
286 self.assertEqual(split_zeros(complex(1., 0.).imag), split_zeros(0.)) 286 self.assertEqual(split_zeros(complex(1., 0.).imag), split_zeros(0.))
287 self.assertEqual(split_zeros(complex(1., -0.).imag), split_zeros(-0.)) 287 self.assertEqual(split_zeros(complex(1., -0.).imag), split_zeros(-0.))
288 self.assertEqual(split_zeros(complex(0., 1.).real), split_zeros(0.)) 288 self.assertEqual(split_zeros(complex(0., 1.).real), split_zeros(0.))
289 self.assertEqual(split_zeros(complex(-0., 1.).real), split_zeros(-0.)) 289 self.assertEqual(split_zeros(complex(-0., 1.).real), split_zeros(-0.))
290 290
291 c = 3.14 + 1j 291 c = 3.14 + 1j
292 self.assertTrue(complex(c) is c) 292 self.assertIs(complex(c), c)
293 del c 293 del c
294 294
295 self.assertRaises(TypeError, complex, "1", "1") 295 self.assertRaises(TypeError, complex, "1", "1")
296 self.assertRaises(TypeError, complex, 1, "1") 296 self.assertRaises(TypeError, complex, 1, "1")
297 297
298 # SF bug 543840: complex(string) accepts strings with \0 298 # SF bug 543840: complex(string) accepts strings with \0
299 # Fixed in 2.3. 299 # Fixed in 2.3.
300 self.assertRaises(ValueError, complex, '1+1j\0j') 300 self.assertRaises(ValueError, complex, '1+1j\0j')
301 301
302 self.assertRaises(TypeError, int, 5+3j) 302 self.assertRaises(TypeError, int, 5+3j)
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()
OLDNEW
« no previous file with comments | « Lib/test/test_compile.py ('k') | Lib/test/test_concurrent_futures.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+