Пример #1
0
def test_mul_a():
    assert str(a * a) == "a * a"

    assert str(a * Zero()) == "0"
    assert str(Zero() * a) == "0"

    assert str(a * One()) == "a"
    assert str(One() * a) == "a"
Пример #2
0
def test_add_a():
    assert str(a + a) == "2 * a"

    assert str(a + Zero()) == "a"
    assert str(Zero() + a) == "a"

    assert str(a + One()) == "a + 1"
    assert str(One() + a) == "1 + a"
Пример #3
0
def test_mul_zero():
    assert str(0 * a) == "0"
    assert str(a * 0) == "0"

    assert str(0 * Zero()) == "0"
    assert str(Zero() * 0) == "0"

    assert str(0 * One()) == "0"
    assert str(One() * 0) == "0"
Пример #4
0
def test_add_b():
    assert str(b + a) == "b + a"
    assert str(a + b) == "a + b"

    assert str(b + Zero()) == "b"
    assert str(Zero() + b) == "b"

    assert str(b + One()) == "b + 1"
    assert str(One() + b) == "1 + b"
Пример #5
0
def test_add_two():
    assert str(2 + a) == "2 * 1 + a"
    assert str(a + 2) == "a + 2 * 1"

    assert str(2 + Zero()) == "2 * 1"
    assert str(Zero() + 2) == "2 * 1"

    assert str(2 + One()) == "3 * 1"
    assert str(One() + 2) == "3 * 1"
Пример #6
0
def test_add_zero():
    assert str(0 + a) == "a"
    assert str(a + 0) == "a"

    assert str(0 + Zero()) == "0"
    assert str(Zero() + 0) == "0"

    assert str(0 + One()) == "1"
    assert str(One() + 0) == "1"
Пример #7
0
def test_add_one():
    assert str(1 + a) == "1 + a"
    assert str(a + 1) == "a + 1"

    assert str(1 + Zero()) == "1"
    assert str(Zero() + 1) == "1"

    assert str(1 + One()) == "2 * 1"
    assert str(One() + 1) == "2 * 1"
Пример #8
0
def test_add_one_object():
    assert str(One() + a) == "1 + a"
    assert str(a + One()) == "a + 1"

    assert str(One() + Zero()) == "1"
    assert str(Zero() + One()) == "1"

    assert str(One() + One()) == "2 * 1"
    assert str(One() + One()) == "2 * 1"
Пример #9
0
def test_mul_b():
    assert str(b * a) == "b * a"
    assert str(a * b) == "a * b"

    assert str(b * Zero()) == "0"
    assert str(Zero() * b) == "0"

    assert str(b * One()) == "b"
    assert str(One() * b) == "b"
Пример #10
0
def test_mul_two():
    assert str(2 * a) == "2 * a"
    assert str(a * 2) == "2 * a"

    assert str(2 * Zero()) == "0"
    assert str(Zero() * 2) == "0"

    assert str(2 * One()) == "2 * 1"
    assert str(One() * 2) == "2 * 1"
Пример #11
0
def test_mul_one_object():
    assert str(One() * a) == "a"
    assert str(a * One()) == "a"

    assert str(One() * Zero()) == "0"
    assert str(Zero() * One()) == "0"

    assert str(One() * One()) == "1"
    assert str(One() * One()) == "1"
Пример #12
0
def test_mul_one():
    assert str(1 * a) == "a"
    assert str(a * 1) == "a"

    assert str(1 * Zero()) == "0"
    assert str(Zero() * 1) == "0"

    assert str(1 * One()) == "1"
    assert str(One() * 1) == "1"
Пример #13
0
def test_mul_zero_object():
    assert str(Zero() * a) == "0"
    assert str(a * Zero()) == "0"

    assert str(Zero() * Zero()) == "0"
    assert str(Zero() * Zero()) == "0"

    assert str(Zero() * One()) == "0"
    assert str(One() * Zero()) == "0"
Пример #14
0
def test_add_zero_object():
    assert str(Zero() + a) == "a"
    assert str(a + Zero()) == "a"

    assert str(Zero() + Zero()) == "0"

    assert str(Zero() + One()) == "1"
    assert str(One() + Zero()) == "1"
Пример #15
0
def test_equality_one_zero():
    assert One() == One()
    assert One() != Zero()
    assert Zero() == Zero()
Пример #16
0
def test_equality_scaled():
    assert Scaled(One(), 1) == Scaled(One(), 1)
    assert Scaled(One(), 2) != Scaled(One(), 1)
    assert Scaled(Zero(), 1) != Scaled(One(), 1)
Пример #17
0
def test_equality_product():
    assert Product(One(), Zero()) == Product(One(), Zero())
    assert Product(One(), Zero()) == Product(Zero(), One())
    assert Product(One(), Zero()) != Product(One(), One())
Пример #18
0
def test_get_algebra():
    for x in [Element(), One(), Zero()]:
        assert get_algebra(x) == Element

    with pytest.raises(RuntimeError):
        get_algebra(1)
Пример #19
0
def test_equality_sum():
    assert Sum(One(), Zero()) == Sum(One(), Zero())
    assert Sum(One(), Zero()) == Sum(Zero(), One())
    assert Sum(One(), Zero()) != Sum(One(), One())