-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_poly_mod5.py
47 lines (40 loc) · 1.17 KB
/
test_poly_mod5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from commutative_ring import verify_ring_properties
from lib.test_helpers import assert_equal, assert_str, run_test
from math_helper import MathHelper
from mod5 import Mod5
from math_mod5 import Mod5Math
from poly import SingleVarPoly
from poly_mod5 import Mod5Poly
zero = Mod5Math.zero
one = Mod5Math.one
two = Mod5(2)
three = Mod5(3)
four = Mod5(4)
p_zero = Mod5Poly.zero
p_one = Mod5Poly.one
p_two = Mod5Poly.two
p_three = Mod5Poly.three
p_four = Mod5Poly.four
p_m = Mod5Poly.m
@run_test
def polynomial_math_works_over_mod5():
q = (p_m + p_four) * (p_m + p_three)
assert_str(q, "m**2+(2)*m+2")
assert q.eval(four) == one
assert_equal(q.type_string, "SingleVarPoly.Mod5")
@run_test
def mod5_polys_conform_to_axioms():
poly_samples = [
Mod5Poly.from_list([one, zero, three]),
Mod5Poly.from_list([three, one, four, two]),
Mod5Poly.from_list([one, four, two, three, three]),
Mod5Poly.from_list([two]),
(p_m * p_two) + p_one,
(p_m + p_three).raised_to_exponent(15),
]
math = MathHelper(
value_type=SingleVarPoly,
zero=p_zero,
one=p_one,
)
verify_ring_properties(math, poly_samples)