def test_modulus(): """ Verifies that the modulus function works as intended """ z = Complex(0, 0) assert z.modulus() == 0 z = Complex(3, 7) assert z.modulus() == math.sqrt(58) z = Complex(-6, -4) assert z.modulus() == 2 * math.sqrt(13) z = Complex(-10, 0) assert z.modulus() == 10 z = Complex(-2, -8) assert z.modulus() == 2 * math.sqrt(17)
def test_mod(): """Test to make sure the modulus() function works. form: |z| = sqrt(a^2 + b^2) Where z=complex number, a=real, b=imaginary """ complexNumber = Complex(2, 0) assert complexNumber.modulus() == 2, error complexNumber = Complex(4, 7) assert complexNumber.modulus() == sqrt(65), error complexNumber = Complex(3, 8) assert complexNumber.modulus() == sqrt(73), error complexNumber = Complex(-1, -3) assert complexNumber.modulus() == sqrt(10), error
def test_modulus(): z1 = Complex(1, 2) z3 = Complex(0, 2) z4 = Complex(2, 0) assert (abs(z1.modulus() - sqrt(5)) < 1e-8), " Modulus of {} was equal to {} and not sqrt(5) ".format( z1, z1.modulus()) assert (abs(z3.modulus() - sqrt(4)) < 1e-8), "Modulus of {} was equal to {} and not sqrt(2) ".format( z3, z3.modulus()) assert (abs(z4.modulus() - sqrt(4)) < 1e-8), " Modulus of {} was equal to {} and not sqrt(2) ".format( z4, z4.modulus())
def test_modulus_complex(): """Tests that the modulus function in complex.py works Loops through the first list of z values and appends the result of the modulus 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 = [ sqrt(6**2 + 3**2), sqrt(3**2 + 6**2), sqrt(0**2 + 2**2), sqrt(3**2 + 3**2), sqrt(7**2 + 0**2) ] 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.modulus() z_computed_list.append(z_computed) eps = 10**(-12) 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 abs(z_real_list[i] - z_computed_list[i]) < eps, msg
def test_modulus(): z_1 = Complex(1, 1) assert abs(np.sqrt(2) - z_1.modulus()) < 1e-14
def test_complex_mudulus(): a1 = Complex(4, 3) assert (a1.modulus() == 5) == True
def test_modulus_with_both_negative_numbers(self): z = Complex(-6, -9) number = (int(z.modulus())) assert number == 10
def test_modulus_with_negative_number(self): z = Complex(2, -18) number = (int(z.modulus())) assert number == 18
def test_modulus(self): z = Complex(3, 6) number = (int(z.modulus())) assert number == 6
def test_mod_four(): x = Complex(0, 8) assert x.modulus() == sqrt(64)
def test_mod_three(): x = Complex(6, 0) assert x.modulus() == sqrt(36)
def test_mod_two(): x = Complex(-5, 4) assert x.modulus() == sqrt(41)
def test_mod_one(): #unit tests for modulus of a complex number x = Complex(6, -8) assert x.modulus() == sqrt(100)
def test_modulus(): a = Complex(3, -4) assert a.modulus() == 5