def fx(a,b,c): t = b*b - 4*a*c if t >= 0: return (-b + math.sqrt(t))/2/a,(-b - math.sqrt(t))/2/a else: b = Complex(b,0) a = Complex(a,0) k = Complex(0,math.sqrt(-t)) p = 1/(a.conjugate()*a)._re x1 = (Complex(-1,0)*b + k)*Complex(.5,0)*a.conjugate()*Complex(p,0) x2 = (Complex(-1,0)*b - k)*Complex(.5,0)*a.conjugate()*Complex(p,0) return x1,x2
def test_conjugate_complex(): """Tests that the conjugate function in complex.py works Loops through the first list of z values and appends the result of the conjugation to a new list, then compares that list of computed values to a list of correct answers. """ # Hand-calculated values to test against z_real_list = [(-6, -3), (-3, 6), (0, -2), (3, 3), (7, 0)] z_computed_list = [] for i in range(val_len): if isinstance(z1_values[i], (float, int)): z = Complex(z1_values[i]) else: z = Complex(z1_values[i][0], z1_values[i][1]) z_computed = z.conjugate() z_computed_list.append(z_computed()) for i in range(val_len): msg = "\nError in value number %d\n\ z1 = %s \n\ z_real = %s \n\ z_computed = %s" \ % (i, z1_values[i], z_real_list[i], z_computed_list[i]) msg = msg.replace(' ', '') assert z_real_list[i] == z_computed_list[i], msg
def test_conjugate(): """Raises AssertionError if conjugating Complex objects does not return expected values. """ z = Complex(-5, 3) ans = z.conjugate() expected = Complex(-5, -3) assert ans.real == expected.real and ans.imag == expected.imag
def test_conj(): """Test to make sure the conjugate() function works. form: !z = a − bi Where z=complex number, a=real, b=imaginary """ complexNumber = Complex(2, 0) assert complexNumber.conjugate() == Complex(2, 0), error complexNumber = Complex(4, 7) assert complexNumber.conjugate() == Complex(4, -7), error complexNumber = Complex(0, 8) assert complexNumber.conjugate() == Complex(0, -8), error complexNumber = Complex(-1, -3) assert complexNumber.conjugate() == Complex(-1, 3), error
def test_conjugate(): z1 = Complex(1, 2) z3 = Complex(0, 2) z4 = Complex(2, 0) assert z1.conjugate() == Complex(1, -2), ("Conjugate of {} was equal to {}" " and not 1-2i".format( z1, z1.conjugate())) assert z3.conjugate() == Complex(0, -2), ("Conjugate of {} was equal to {} " "and not 0-2i".format( z3, z3.conjugate())) assert z4.conjugate() == Complex( 2, 0), "Conjugate of {} was equal to {}" " and not 2".format( z4, z4.conjugate())
def test_conjugate(): """ Verifies that the conjugate function works as intended """ z = Complex(0, 0) assert z.conjugate() == Complex(0, 0) # "0" z = Complex(4, 0) assert z.conjugate() == Complex(4, 0) # "4" z = Complex(0, 11) assert z.conjugate() == Complex(0, -11) # "-11i" z = Complex(3, 7) assert z.conjugate() == Complex(3, -7) # "3 - 7i" z = Complex(-9, -4) assert z.conjugate() == Complex(-9, 4) # "-9 + 4i" z = Complex(12, -9) assert z.conjugate() == Complex(12, 9) # "12 + 9i" z = Complex(-3, 7) assert z.conjugate() == Complex(-3, -7) # "-3 - 7i"
def test_conjugate2(): z_1 = Complex(0, 1) assert z_1.conjugate() == Complex(0, -1)
def test_conjugate__from_negative_to_positive(self): z = Complex(8, -2) assert z.conjugate().__str__() == "8+2i"
def test_complex_conjugate(): a1 = Complex(1, 2) assert (a1.conjugate() == Complex(1, -2)) == True
def test_conjugate1(): z_1 = Complex(1, 0) assert z_1.conjugate() == Complex(1, 0)
def test_conjugate_two(): x = Complex(4, 3) assert x.conjugate() == '4-3i'
def test_complex(): x, y = Complex(2, 1), Complex(5, 6) su, sub, mul, div, mod_x, mod_y, x_angle, y_angle, x_conjugate, y_conjugate, x_log, y_log = x+y, x-y, x*y, x/y, x.mod(), y.mod(), x.angle(), y.angle(), x.conjugate(), y.conjugate(), x.log(), y.log() assert su.__str__() == '7.00+7.00i' assert sub.__str__() == '-3.00-5.00i' assert mul.__str__() == '4.00+17.00i' assert div.__str__() == '0.26-0.11i' assert mod_x.__str__() == '2.24+0.00i' assert mod_y.__str__() == '7.81+0.00i' assert x_angle.__str__() == '0.4636476090008061' assert y_angle.__str__() == '0.8760580505981934' assert x_conjugate.__str__() == '2.00-1.00i' assert y_conjugate.__str__() == '5.00-6.00i' assert x_log.__str__() == '0.80+0.46i' assert y_log.__str__() == '2.06+0.88i'
def test_conjugate_three(): x = Complex(0, 5) assert x.conjugate() == '0-5i'
def test_conjugate_make_both_numbers_negative(self): z = Complex(-9, 4) assert z.conjugate().__str__() == "-9-4i"
def test_conjugate(): a = Complex(3, 2) assert a.conjugate() == Complex(3, -2)
def test_conjugate_from_positive_to_negative(self): z = Complex(6, 5) assert z.conjugate().__str__() == "6-5i"
def test_conjugate_one(): #first unit test for conjugate of complex number x = Complex(4, 5) assert x.conjugate() == '4-5i'