MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_pow

Method test_pow

Lib/test/test_complex.py:352–423  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

350 self.assertRaises(TypeError, divmod, a, b)
351
352 def test_pow(self):
353 self.assertAlmostEqual(pow(1+1j, 0+0j), 1.0)
354 self.assertAlmostEqual(pow(0+0j, 2+0j), 0.0)
355 self.assertEqual(pow(0+0j, 2000+0j), 0.0)
356 self.assertEqual(pow(0, 0+0j), 1.0)
357 self.assertEqual(pow(-1, 0+0j), 1.0)
358 self.assertRaises(ZeroDivisionError, pow, 0+0j, 1j)
359 self.assertRaises(ZeroDivisionError, pow, 0+0j, -1000)
360 self.assertAlmostEqual(pow(1j, -1), 1/1j)
361 self.assertAlmostEqual(pow(1j, 200), 1)
362 self.assertRaises(ValueError, pow, 1+1j, 1+1j, 1+1j)
363 self.assertRaises(OverflowError, pow, 1e200+1j, 1e200+1j)
364 self.assertRaises(OverflowError, pow, 1e200+1j, 5)
365 self.assertRaises(TypeError, pow, 1j, None)
366 self.assertRaises(TypeError, pow, None, 1j)
367 self.assertAlmostEqual(pow(1j, 0.5), 0.7071067811865476+0.7071067811865475j)
368
369 a = 3.33+4.43j
370 self.assertEqual(a ** 0j, 1)
371 self.assertEqual(a ** 0.+0.j, 1)
372
373 self.assertEqual(3j ** 0j, 1)
374 self.assertEqual(3j ** 0, 1)
375
376 try:
377 0j ** a
378 except ZeroDivisionError:
379 pass
380 else:
381 self.fail("should fail 0.0 to negative or complex power")
382
383 try:
384 0j ** (3-2j)
385 except ZeroDivisionError:
386 pass
387 else:
388 self.fail("should fail 0.0 to negative or complex power")
389
390 # The following is used to exercise certain code paths
391 self.assertEqual(a ** 105, a ** 105)
392 self.assertEqual(a ** -105, a ** -105)
393 self.assertEqual(a ** -30, a ** -30)
394
395 self.assertEqual(0.0j ** 0, 1)
396
397 b = 5.1+2.3j
398 self.assertRaises(ValueError, pow, a, b, 0)
399
400 # Check some boundary conditions; some of these used to invoke
401 # undefined behaviour (https://bugs.python.org/issue44698). We're
402 # not actually checking the results of these operations, just making
403 # sure they don't crash (for example when using clang's
404 # UndefinedBehaviourSanitizer).
405 values = (sys.maxsize, sys.maxsize+1, sys.maxsize-1,
406 -sys.maxsize, -sys.maxsize+1, -sys.maxsize+1)
407 for real in values:
408 for imag in values:
409 with self.subTest(real=real, imag=imag):

Callers

nothing calls this directly

Calls 6

assertAlmostEqualMethod · 0.95
subTestMethod · 0.80
powFunction · 0.50
assertEqualMethod · 0.45
assertRaisesMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected