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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 self.assertEqual(a ** -30, a ** -30) 196 self.assertEqual(a ** -30, a ** -30)
197 197
198 self.assertEqual(0.0j ** 0, 1) 198 self.assertEqual(0.0j ** 0, 1)
199 199
200 b = 5.1+2.3j 200 b = 5.1+2.3j
201 self.assertRaises(ValueError, pow, a, b, 0) 201 self.assertRaises(ValueError, pow, a, b, 0)
202 202
203 def test_boolcontext(self): 203 def test_boolcontext(self):
204 for i in range(100): 204 for i in range(100):
205 self.assertTrue(complex(random() + 1e-6, random() + 1e-6)) 205 self.assertTrue(complex(random() + 1e-6, random() + 1e-6))
206 self.assertTrue(not complex(0.0, 0.0)) 206 self.assertFalse(complex(0.0, 0.0))
207 207
208 def test_conjugate(self): 208 def test_conjugate(self):
209 self.assertClose(complex(5.3, 9.8).conjugate(), 5.3-9.8j) 209 self.assertClose(complex(5.3, 9.8).conjugate(), 5.3-9.8j)
210 210
211 def test_constructor(self): 211 def test_constructor(self):
212 class OS: 212 class OS:
213 def __init__(self, value): self.value = value 213 def __init__(self, value): self.value = value
214 def __complex__(self): return self.value 214 def __complex__(self): return self.value
215 class NS(object): 215 class NS(object):
216 def __init__(self, value): self.value = value 216 def __init__(self, value): self.value = value
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 def split_zeros(x): 281 def split_zeros(x):
282 """Function that produces different results for 0. and -0.""" 282 """Function that produces different results for 0. and -0."""
283 return atan2(x, -1.) 283 return atan2(x, -1.)
284 284
285 self.assertEqual(split_zeros(complex(1., 0.).imag), split_zeros(0.)) 285 self.assertEqual(split_zeros(complex(1., 0.).imag), split_zeros(0.))
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(0., 1.).real), split_zeros(0.)) 287 self.assertEqual(split_zeros(complex(0., 1.).real), 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 289
290 c = 3.14 + 1j 290 c = 3.14 + 1j
291 self.assertTrue(complex(c) is c) 291 self.assertIs(complex(c), c)
292 del c 292 del c
293 293
294 self.assertRaises(TypeError, complex, "1", "1") 294 self.assertRaises(TypeError, complex, "1", "1")
295 self.assertRaises(TypeError, complex, 1, "1") 295 self.assertRaises(TypeError, complex, 1, "1")
296 296
297 # SF bug 543840: complex(string) accepts strings with \0 297 # SF bug 543840: complex(string) accepts strings with \0
298 # Fixed in 2.3. 298 # Fixed in 2.3.
299 self.assertRaises(ValueError, complex, '1+1j\0j') 299 self.assertRaises(ValueError, complex, '1+1j\0j')
300 300
301 self.assertRaises(TypeError, int, 5+3j) 301 self.assertRaises(TypeError, int, 5+3j)
(...skipping 327 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+