(self)
| 456 | self.assertEqual(complex(5.3, 9.8).conjugate(), 5.3-9.8j) |
| 457 | |
| 458 | def test_constructor(self): |
| 459 | def check(z, x, y): |
| 460 | self.assertIs(type(z), complex) |
| 461 | self.assertFloatsAreIdentical(z.real, x) |
| 462 | self.assertFloatsAreIdentical(z.imag, y) |
| 463 | |
| 464 | check(complex(), 0.0, 0.0) |
| 465 | check(complex(10), 10.0, 0.0) |
| 466 | check(complex(4.25), 4.25, 0.0) |
| 467 | check(complex(4.25+0j), 4.25, 0.0) |
| 468 | check(complex(4.25+0.5j), 4.25, 0.5) |
| 469 | check(complex(ComplexSubclass(4.25+0.5j)), 4.25, 0.5) |
| 470 | check(complex(WithComplex(4.25+0.5j)), 4.25, 0.5) |
| 471 | |
| 472 | check(complex(1, 10), 1.0, 10.0) |
| 473 | check(complex(1, 10.0), 1.0, 10.0) |
| 474 | check(complex(1, 4.25), 1.0, 4.25) |
| 475 | check(complex(1.0, 10), 1.0, 10.0) |
| 476 | check(complex(4.25, 10), 4.25, 10.0) |
| 477 | check(complex(1.0, 10.0), 1.0, 10.0) |
| 478 | check(complex(4.25, 0.5), 4.25, 0.5) |
| 479 | |
| 480 | with self.assertWarnsRegex(DeprecationWarning, |
| 481 | "argument 'real' must be a real number, not complex"): |
| 482 | check(complex(4.25+0j, 0), 4.25, 0.0) |
| 483 | with self.assertWarnsRegex(DeprecationWarning, |
| 484 | "argument 'real' must be a real number, not .*ComplexSubclass"): |
| 485 | check(complex(ComplexSubclass(4.25+0j), 0), 4.25, 0.0) |
| 486 | with self.assertWarnsRegex(DeprecationWarning, |
| 487 | "argument 'real' must be a real number, not .*WithComplex"): |
| 488 | check(complex(WithComplex(4.25+0j), 0), 4.25, 0.0) |
| 489 | with self.assertWarnsRegex(DeprecationWarning, |
| 490 | "argument 'real' must be a real number, not complex"): |
| 491 | check(complex(4.25j, 0), 0.0, 4.25) |
| 492 | with self.assertWarnsRegex(DeprecationWarning, |
| 493 | "argument 'real' must be a real number, not complex"): |
| 494 | check(complex(0j, 4.25), 0.0, 4.25) |
| 495 | with self.assertWarnsRegex(DeprecationWarning, |
| 496 | "argument 'imag' must be a real number, not complex"): |
| 497 | check(complex(0, 4.25+0j), 0.0, 4.25) |
| 498 | with self.assertWarnsRegex(DeprecationWarning, |
| 499 | "argument 'imag' must be a real number, not .*ComplexSubclass"): |
| 500 | check(complex(0, ComplexSubclass(4.25+0j)), 0.0, 4.25) |
| 501 | with self.assertRaisesRegex(TypeError, |
| 502 | "argument 'imag' must be a real number, not .*WithComplex"): |
| 503 | complex(0, WithComplex(4.25+0j)) |
| 504 | with self.assertWarnsRegex(DeprecationWarning, |
| 505 | "argument 'imag' must be a real number, not complex"): |
| 506 | check(complex(0.0, 4.25j), -4.25, 0.0) |
| 507 | with self.assertWarnsRegex(DeprecationWarning, |
| 508 | "argument 'real' must be a real number, not complex"): |
| 509 | check(complex(4.25+0j, 0j), 4.25, 0.0) |
| 510 | with self.assertWarnsRegex(DeprecationWarning, |
| 511 | "argument 'real' must be a real number, not complex"): |
| 512 | check(complex(4.25j, 0j), 0.0, 4.25) |
| 513 | with self.assertWarnsRegex(DeprecationWarning, |
| 514 | "argument 'real' must be a real number, not complex"): |
| 515 | check(complex(0j, 4.25+0j), 0.0, 4.25) |
nothing calls this directly
no test coverage detected