Exemple #1
0
def test_string():
    pos = 2
    positive = z.Z(pos)
    assert (str(positive) == str(pos))

    neg = -3
    negative = z.Z(neg)
    assert (str(negative) == str(neg))
Exemple #2
0
def test_eq_neq():
    original = z.Z(2)
    same = z.Z(2)
    different = z.Z(3)

    assert (original == same)
    assert (not (original == different))
    assert (original != different)
    assert (not (original != same))
Exemple #3
0
def test_multiplication():
    a = 3
    b = -4
    c = a * b

    zObjectA = z.Z(a)
    zObjectB = z.Z(b)
    zObjectC = zObjectA * zObjectB

    assert (zObjectC.a == c)
Exemple #4
0
def test_floordiv():
    a = 5
    b = -3
    c = -2  # defining c here to be extra clear about the intended behaviour

    aObject = z.Z(a)
    bObject = z.Z(b)
    cObject = z.Z(c)

    assert (aObject // bObject == cObject)
Exemple #5
0
def test_subtraction():
    a = 5
    b = 7
    c = a - b

    aObject = z.Z(a)
    bObject = z.Z(b)
    cObject = aObject - bObject

    assert (cObject.a == c)
Exemple #6
0
def test_addition():
    a = 1
    b = -5
    c = a + b

    zObjectA = z.Z(a)
    zObjectB = z.Z(b)
    zObjectC = zObjectA + zObjectB

    assert (zObjectC.a == c)
Exemple #7
0
def test_mod():
    a = 5
    b = -3
    c = -1  # defining c here to be extra clear about the intended behaviour

    aObject = z.Z(a)
    bObject = z.Z(b)
    cObject = z.Z(c)

    assert (aObject % bObject == cObject)
Exemple #8
0
def test_negation():
    a = 12
    negA = -a

    zObject = z.Z(a)
    zNegObject = -zObject

    assert (zNegObject.a == negA)
Exemple #9
0
def test_lt_gt_simple():
    negative = z.Z(-1)
    positive = z.Z(2)
    positive_again = z.Z(2)

    assert (negative < positive)
    assert (positive > negative)
    assert (not positive < negative)
    assert (not negative > positive)

    assert (not positive > positive_again)
    assert (not positive < positive_again)
    assert (not positive_again > positive)
    assert (not positive_again < positive)

    assert (not positive < positive)
    assert (not positive > positive)
Exemple #10
0
def test_create_matrix():
    matrix.Matrix(2, 1, [z.Z(3), z.Z(4)])
Exemple #11
0
def test_int_creation():
    a = 10
    zObject = z.Z(a)
    assert (zObject.a == a)
Exemple #12
0
def test_bad_type_creation():
    a = 2.0
    with pytest.raises(pid.InvalidInitialContent):
        z.Z(a)
Exemple #13
0
def test_bad_list_creation():
    a = [10, 12]
    with pytest.raises(pid.InvalidInitialContent):
        z.Z(a)
Exemple #14
0
def test_bad_string_creation():
    a = "hello"
    with pytest.raises(pid.InvalidInitialContent):
        z.Z(a)
Exemple #15
0
def test_determinant_raise_exception():
    m = matrix.Matrix(2, 3, [z.Z(1), z.Z(2), z.Z(3), z.Z(4), z.Z(3), z.Z(4)])
    with pytest.raises(matrix.MatrixNotSquareException):
        m.determinant()
Exemple #16
0
def test_add_z():
    m1 = matrix.Matrix(2, 2, [z.Z(1), z.Z(2), z.Z(3), z.Z(4)])
    m2 = matrix.Matrix(2, 2, [z.Z(3), z.Z(-4), z.Z(-1), z.Z(2)])
    m3 = matrix.Matrix(2, 2, [z.Z(4), z.Z(-2), z.Z(2), z.Z(6)])

    assert (m1 + m2 == m3)
Exemple #17
0
def test_mult():
    a = matrix.Matrix(2, 2, [z.Z(1), z.Z(2), z.Z(3), z.Z(4)])
    b = matrix.Matrix(2, 3, [z.Z(3), z.Z(-4), z.Z(-1), z.Z(2), z.Z(4), z.Z(5)])
    c = matrix.Matrix(2, 3, [z.Z(7), z.Z(4), z.Z(9), z.Z(17), z.Z(4), z.Z(17)])
    assert (a * b == c)
Exemple #18
0
def test_eq_neq_contents():
    m1 = matrix.Matrix(2, 1, [z.Z(3), z.Z(3)])
    m2 = matrix.Matrix(1, 2, [z.Z(3), z.Z(4)])

    assert (m1 != m2)
    assert (not m1 == m2)
Exemple #19
0
def test_mul_raise_exception():
    a = matrix.Matrix(2, 2, [z.Z(1), z.Z(2), z.Z(3), z.Z(4)])
    b = matrix.Matrix(3, 2, [z.Z(3), z.Z(-4), z.Z(-1), z.Z(2), z.Z(4), z.Z(5)])

    with pytest.raises(matrix.IncompatibleMatrixSizesException):
        a * b
Exemple #20
0
def test_determinant_2x2():
    m = matrix.Matrix(2, 2, [z.Z(1), z.Z(2), z.Z(3), z.Z(4)])
    assert (m.determinant() == z.Z(-2))
Exemple #21
0
def test_str_creation():
    a = "10"
    zObject = z.Z(a)
    assert (zObject.a == int(a))
Exemple #22
0
def test_str():
    m = matrix.Matrix(2, 2, [z.Z(1), z.Z(2), z.Z(3), z.Z(4)])
    mString = "[1 2]\n[3 4]\n"
    assert (str(m) == mString)
Exemple #23
0
def test_invalid_create():
    with pytest.raises(matrix.InvalidNumberOfElements):
        matrix.Matrix(2, 2, [z.Z(3), z.Z(4)])
Exemple #24
0
def test_is_unit():
    assert (z.Z(1).isUnit())
    assert (z.Z(-1).isUnit())
    assert (not z.Z(2).isUnit())
    assert (not z.Z(-5).isUnit())
    assert (not (-z.Z(3)).isUnit())
Exemple #25
0
def test_lt_gt_is_using_norm():
    negative = z.Z(-10)
    positive = z.Z(2)

    assert (negative > positive)
    assert (positive < negative)
Exemple #26
0
def test_list_creation():
    a = [10]
    zObject = z.Z(a)
    assert (zObject.a == a[0])
Exemple #27
0
def test_add_raise_exception():
    m1 = matrix.Matrix(2, 1, [z.Z(3), z.Z(4)])
    m2 = matrix.Matrix(1, 2, [z.Z(3), z.Z(4)])
    with pytest.raises(matrix.IncompatibleMatrixSizesException):
        m1 + m2
Exemple #28
0
def test_determinant_3x3():
    contents = list(map(z.Z, [1, 2, 3, 4, 5, 6, 7, 8, 20]))
    m = matrix.Matrix(3, 3, contents)

    assert (m.determinant() == z.Z(-33))
Exemple #29
0
from smithnormalform import matrix, snfproblem, z
import random as rand

rand.seed(1001)

snfContents = [rand.randrange(-10000, 10000) for _ in range(100)]
snfMatrix = matrix.Matrix(10, 10, [z.Z(x) for x in snfContents])
snfProb = snfproblem.SNFProblem(snfMatrix)
snfProb.computeSNF()

print(f"A:\n{snfProb.A}")
print()
print(f"J:\n{snfProb.J}")
print()
print(f"S:\n{snfProb.S}")
print()
print(f"T:\n{snfProb.T}")
print()

print(f"S.det: {snfProb.S.determinant()}")
print()
print(f"T.det: {snfProb.T.determinant()}")
print()

print(f"S*A*T == J ?: {snfProb.S * snfProb.A * snfProb.T == snfProb.J}")
Exemple #30
0
def test_eq_neq():
    m1 = matrix.Matrix(2, 2, [z.Z(1), z.Z(2), z.Z(3), z.Z(4)])
    m2 = matrix.Matrix(2, 2, [z.Z(1), z.Z(2), z.Z(3), z.Z(4)])

    assert (m1 == m2)
    assert (not m1 != m2)