def test_gets_sets_str(self): complex = ComplexNumber(1, 2) complex1 = ComplexNumber(1, -1) self.assertEqual(complex.getRealPart(), 1) self.assertEqual(complex.getImagPart(), 2) self.assertEqual(complex1.getRealPart(), 1) self.assertEqual(complex1.getImagPart(), -1) self.assertEqual(str(complex), '1 +2i') complex.setRealPart(4) complex.setImagPart(-100) self.assertEqual(complex.getRealPart(), 4) self.assertEqual(complex.getImagPart(), -100) self.assertEqual(str(complex), '4 -100i')
def test_exponentialComplex(self): c1 = ComplexNumber(3, 4) c2 = c1.exponentialComplex() self.assertAlmostEqual(c2.getRealPart(), -13, 0) self.assertAlmostEqual(c2.getImagPart(), -15, 0) c2 = ComplexNumber(1, 0) c2 = c2.exponentialComplex() self.assertAlmostEqual(c2.getRealPart(), 2.7, 0) self.assertAlmostEqual(c2.getImagPart(), 0, 0)
def test_squarerootComplex(self): c1 = ComplexNumber(3, 4) c2 = c1.squarerootComplex() self.assertEqual(c2.getRealPart(), 2) self.assertEqual(c2.getImagPart(), 1) c2 = ComplexNumber(1, 0) c2 = c2.squarerootComplex() self.assertEqual(c2.getRealPart(), 1) self.assertEqual(c2.getImagPart(), 0)