コード例 #1
0
def test_sub(init):
    cf = CalculatorComplex(init[0])
    assert (cf - init[1]) == CalculatorComplex(init[2])
    cf -= init[1]
    assert cf == CalculatorComplex(init[2])
    cf = CalculatorComplex(init[1])
    assert (init[0] - cf) == CalculatorComplex(init[2])
コード例 #2
0
def test_mult(init):
    cf = CalculatorComplex(init[0])
    assert (cf * init[1]) == CalculatorComplex(init[2])
    cf *= init[1]
    assert cf == CalculatorComplex(init[2])
    cf = CalculatorComplex(init[1])
    assert (init[0] * cf) == CalculatorComplex(init[2])
コード例 #3
0
def test_str_init():
    cf = CalculatorComplex("start_value")
    assert cf.real.value == "start_value"
    assert cf.imag.value == 0
    cf2 = CalculatorComplex(cf)
    assert cf.real.value == "start_value"
    assert cf.imag.value == 0
コード例 #4
0
def test_add(init):
    cf = CalculatorComplex(init[0])
    assert (cf + init[1]) == CalculatorComplex(init[2])
    cf += init[1]
    assert cf == CalculatorComplex(init[2])
    cf = CalculatorComplex(init[1])
    assert (init[0] + cf) == CalculatorComplex(init[2])
コード例 #5
0
def test_init(start_value):
    cf = CalculatorComplex(start_value)
    assert cf.real.value == np.real(start_value)
    assert cf.imag.value == np.imag(start_value)
    cf2 = CalculatorComplex(cf)
    assert cf2.real.value == np.real(start_value)
    assert cf2.imag.value == np.imag(start_value)
コード例 #6
0
def test_div(init):
    cf = CalculatorComplex(init[0])
    assert (cf / init[1]) == CalculatorComplex(init[2])
    cf /= init[1]
    assert cf == CalculatorComplex(init[2])
    cf = CalculatorComplex(init[1])
    assert (init[0] / cf) == CalculatorComplex(init[2])
コード例 #7
0
def test_div_fail(init):
    cf = CalculatorComplex(init[0])
    with pytest.raises(ZeroDivisionError):
        (cf / init[1])
    with pytest.raises(ZeroDivisionError):
        cf /= init[1]
    with pytest.raises(ZeroDivisionError):
        cf = CalculatorComplex(init[1])
        (init[0] / cf)
コード例 #8
0
def test_failed_init():
    with pytest.raises(TypeError):
        cf = CalculatorComplex(dict())
コード例 #9
0
def test_from_pair(start_value):
    cf = CalculatorComplex.from_pair(*start_value)
    assert cf.real == CalculatorFloat(start_value[0])
    assert cf.imag == CalculatorFloat(start_value[1])
コード例 #10
0
def test_complex_cast_fail():
    cc = CalculatorComplex.from_pair("a", "b")
    with pytest.raises(ValueError):
        assert complex(cc)
コード例 #11
0
def test_complex_cast(initial):
    cc = CalculatorComplex(initial[0])
    assert complex(cc) == initial[1]
コード例 #12
0
def test_complex_abs(initial):
    aabs = abs(CalculatorComplex.from_pair(*initial[0]))
    assert aabs.isclose(initial[1])
コード例 #13
0
def test_complex_arg(initial):
    arg = CalculatorComplex.from_pair(*initial[0]).arg()
    assert arg.isclose(initial[1])
コード例 #14
0
def test_complex_conj(initial):
    t = CalculatorComplex.from_pair(*initial[0]).conj()
    assert t == CalculatorComplex.from_pair(*initial[1])
コード例 #15
0
def test_complex_isclose(initial):
    t = CalculatorComplex.from_pair(initial[0][0], initial[0][1]).isclose(
        CalculatorComplex.from_pair(initial[1][0], initial[1][1]))
    assert t == initial[2]