示例#1
0
def test_field_4():
    f = Field(4)
    assert [str(e) for e in f.elements] == ['0', '1', 'x', 'x + 1']
    assert f.elements == [
        RemainderPoly(coef_list=[IntMod(0)]),
        RemainderPoly(coef_list=[IntMod(1)]),
        RemainderPoly(coef_list=[IntMod(0), IntMod(1)]),
        RemainderPoly(coef_list=[IntMod(1), IntMod(1)])
    ]
示例#2
0
def test_plus_different_degrees():
    IntMod.modulus = 2
    rp1 = RemainderPoly(coef_list=[IntMod(0), IntMod(1)])
    rp2 = RemainderPoly(coef_list=[IntMod(1), IntMod(1), IntMod(1)])
    rp = rp1 + rp2

    rp_expected = RemainderPoly(coef_list=[IntMod(1), IntMod(0), IntMod(1)])

    assert rp == rp_expected
示例#3
0
def test_plus_no_quotient():
    IntMod.modulus = 2
    rp1 = RemainderPoly(coef_list=[IntMod(0), IntMod(1)])
    rp2 = RemainderPoly(coef_list=[IntMod(1), IntMod(1)])
    rp = rp1 + rp2

    rp_expected = RemainderPoly(coef_list=[IntMod(1)])

    assert rp == rp_expected
示例#4
0
def test_times_no_residue_needed():
    IntMod.modulus = 3
    qp = PolyMod([IntMod(1), IntMod(1), IntMod(1), IntMod(1)])
    RemainderPoly.quotient = qp

    rp1 = RemainderPoly(coef_list=[IntMod(1), IntMod(1)])
    rp2 = RemainderPoly(coef_list=[IntMod(1), IntMod(1)])
    rp = rp1 * rp2

    rp_expected = RemainderPoly(coef_list=[IntMod(1), IntMod(2), IntMod(1)])

    assert rp == rp_expected
示例#5
0
def test_create_with_quotient():
    IntMod.modulus = 7
    qp = PolyMod([IntMod(1), IntMod(2), IntMod(1)])
    RemainderPoly.quotient = qp
    rp = RemainderPoly([IntMod(1), IntMod(4), IntMod(6), IntMod(4), IntMod(1)])
    rp._residue()  # pylint: disable=protected-access
    x = str(rp)
    assert x == '0'
示例#6
0
def test_create_no_quotient():
    IntMod.modulus = 0
    rp = RemainderPoly(coef_list=[
        IntMod(1), IntMod(4),
        IntMod(6), IntMod(4),
        IntMod(1)
    ])
    x = str(rp)
    assert x == 'x^4 + 4x^3 + 6x^2 + 4x + 1'