def test_complex_division(set_up_complex_nums):
    number_1, number_2, number_3 = set_up_complex_nums
    assert number_1 / number_2 == specs.ComplexNumber(.3, .1)
    assert number_1 / number_3 == specs.ComplexNumber(20. / 85, -5. / 85)
    assert number_2 / number_3 == specs.ComplexNumber(55. / 85, -35. / 85)
    assert number_3 / number_3 == specs.ComplexNumber(1, 0)

    with pytest.raises(Exception) as excinfo:
        number_1 / specs.ComplexNumber()
    assert excinfo.typename == 'ValueError'
    assert excinfo.value.args[0] == "Cannot divide by zero"
Esempio n. 2
0
def test_complex_division(set_up_complex_nums):
    number_1, number_2, number_3 = set_up_complex_nums
    assert number_1 / number_2 == specs.ComplexNumber(.3, .1)
    assert number_1 / number_3 == specs.ComplexNumber(4. / 17, -1. / 17)
    assert number_2 / number_3 == specs.ComplexNumber(11. / 17, -7. / 17)
    assert number_3 / number_3 == specs.ComplexNumber(1, 0)

    with pytest.raises(Exception) as error:
        specs.ComplexNumber(1, 2) / specs.ComplexNumber(0, 0)
    assert error.typename == "ValueError"
    assert error.value.args[0] == "Cannot divide by zero"
Esempio n. 3
0
def test_complex_multiplication(set_up_complex_nums):
    number_1, number_2, number_3 = set_up_complex_nums
    assert number_1 * number_2 == specs.ComplexNumber(-5, 15)
    assert number_1 * number_3 == specs.ComplexNumber(-16, 13)
    assert number_2 * number_3 == specs.ComplexNumber(-35, 55)
    assert number_3 * number_3 == specs.ComplexNumber(-77, 36)
Esempio n. 4
0
def test_complex_subtraction(set_up_complex_nums):
    number_1, number_2, number_3 = set_up_complex_nums
    assert number_1 - number_2 == specs.ComplexNumber(-4, -3)
    assert number_1 - number_3 == specs.ComplexNumber(-1, -7)
    assert number_2 - number_3 == specs.ComplexNumber(3, -4)
    assert number_3 - number_3 == specs.ComplexNumber(0, 0)
Esempio n. 5
0
def test_complex_addition(set_up_complex_nums):
    number_1, number_2, number_3 = set_up_complex_nums
    assert number_1 + number_2 == specs.ComplexNumber(6, 7)
    assert number_1 + number_3 == specs.ComplexNumber(3, 11)
    assert number_2 + number_3 == specs.ComplexNumber(7, 14)
    assert number_3 + number_3 == specs.ComplexNumber(4, 18)
Esempio n. 6
0
def set_up_complex_nums():
    number_1 = specs.ComplexNumber(1, 2)
    number_2 = specs.ComplexNumber(5, 5)
    number_3 = specs.ComplexNumber(2, 9)
    return number_1, number_2, number_3
Esempio n. 7
0
def test_complex_string(set_up_complex_nums):
    number_1, number_2, number_3 = set_up_complex_nums
    assert str(number_1) == "1+2i"
    assert str(number_2) == "5+5i"
    assert str(number_3) == "2+9i"
    assert str(specs.ComplexNumber(1, -5)) == "1-5i"
Esempio n. 8
0
def test_complex_conjugate(set_up_complex_nums):
    number_1, number_2, number_3 = set_up_complex_nums
    assert number_1.conjugate() == specs.ComplexNumber(1, -2)
    assert number_2.conjugate() == specs.ComplexNumber(5, -5)
    assert number_3.conjugate() == specs.ComplexNumber(2, -9)
Esempio n. 9
0
def test_complex_equals(set_up_complex_nums):
    number_1, number_2, number_3 = set_up_complex_nums
    assert number_1 == specs.ComplexNumber(1, 2)
    assert number_2 == specs.ComplexNumber(5, 5)
    assert number_3 == specs.ComplexNumber(2, 9)