Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
- Add LUTs for high degree primitive polynomials from Wolfram's database
- Add test_minimum_terms_from_database with a timeout=1s
  • Loading branch information
iyanmv committed Jan 22, 2023
1 parent 6d2a2bd commit 41486bf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dev = [
"pytest-cov[toml]",
"pytest-xdist",
"pytest-benchmark >= 4.0.0",
"pytest-timeout"
]

[project.urls]
Expand Down
28 changes: 28 additions & 0 deletions tests/polys/luts/primitive_polys_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
A module containing LUTs for primitive polynomials with min terms from primitive_polys.db
"""

# LUT items are poly nonzero degrees and coefficients in degree-descending order

# Wolfram's database
# LUT items picked from `ResourceData["Primitive Polynomials"]` using Mathematica 13.2

PRIMITIVE_POLY_MIN_TERMS_2_723 = [[723, 16, 13, 6, 0], [1, 1, 1, 1, 1]]
PRIMITIVE_POLY_MIN_TERMS_2_936 = [[936, 16, 13, 7, 0], [1, 1, 1, 1, 1]]
PRIMITIVE_POLY_MIN_TERMS_2_1056 = [[1056, 14, 9, 6, 0], [1, 1, 1, 1, 1]]
PRIMITIVE_POLY_MIN_TERMS_2_1200 = [[1200, 23, 8, 5, 0], [1, 1, 1, 1, 1]]

PRIMITIVE_POLY_MIN_TERMS_3_399 = [[399, 181, 0], [1, 2, 1]]
PRIMITIVE_POLY_MIN_TERMS_3_422 = [[422, 287, 3, 0], [1, 1, 1, 2]]
PRIMITIVE_POLY_MIN_TERMS_3_549 = [[549, 77, 0], [1, 2, 1]]
PRIMITIVE_POLY_MIN_TERMS_3_660 = [[660, 329, 37, 0], [1, 1, 1, 2]]

PRIMITIVE_POLY_MIN_TERMS_5_296 = [[296, 10, 1, 0], [1, 4, 1, 2]]
PRIMITIVE_POLY_MIN_TERMS_5_357 = [[357, 176, 0], [1, 3, 2]]
PRIMITIVE_POLY_MIN_TERMS_5_404 = [[404, 43, 1, 0], [1, 4, 1, 2]]
PRIMITIVE_POLY_MIN_TERMS_5_430 = [[430, 7, 1, 0], [1, 3, 2, 2]]

PRIMITIVE_POLY_MIN_TERMS_7_129 = [[129, 3, 1, 0], [1, 5, 1, 2]]
PRIMITIVE_POLY_MIN_TERMS_7_195 = [[195, 20, 1, 0], [1, 6, 1, 2]]
PRIMITIVE_POLY_MIN_TERMS_7_284 = [[284, 5, 1, 0], [1, 3, 3, 3]]
PRIMITIVE_POLY_MIN_TERMS_7_357 = [[357, 25, 1, 0], [1, 4, 3, 4]]
48 changes: 48 additions & 0 deletions tests/polys/test_primitive_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@
)
from .luts.primitive_polys_25 import PRIMITIVE_POLYS_25_1, PRIMITIVE_POLYS_25_2

from .luts.primitive_polys_database import (
PRIMITIVE_POLY_MIN_TERMS_2_723,
PRIMITIVE_POLY_MIN_TERMS_2_936,
PRIMITIVE_POLY_MIN_TERMS_2_1056,
PRIMITIVE_POLY_MIN_TERMS_2_1200,
PRIMITIVE_POLY_MIN_TERMS_3_399,
PRIMITIVE_POLY_MIN_TERMS_3_422,
PRIMITIVE_POLY_MIN_TERMS_3_549,
PRIMITIVE_POLY_MIN_TERMS_3_660,
PRIMITIVE_POLY_MIN_TERMS_5_296,
PRIMITIVE_POLY_MIN_TERMS_5_357,
PRIMITIVE_POLY_MIN_TERMS_5_404,
PRIMITIVE_POLY_MIN_TERMS_5_430,
PRIMITIVE_POLY_MIN_TERMS_7_129,
PRIMITIVE_POLY_MIN_TERMS_7_195,
PRIMITIVE_POLY_MIN_TERMS_7_284,
PRIMITIVE_POLY_MIN_TERMS_7_357,
)

PARAMS = [
(2, 1, PRIMITIVE_POLYS_2_1),
(2, 2, PRIMITIVE_POLYS_2_2),
Expand Down Expand Up @@ -75,6 +94,25 @@
(5**2, 2, PRIMITIVE_POLYS_25_2),
]

PARAMS_DB = [
(2, 723, PRIMITIVE_POLY_MIN_TERMS_2_723),
(2, 936, PRIMITIVE_POLY_MIN_TERMS_2_936),
(2, 1056, PRIMITIVE_POLY_MIN_TERMS_2_1056),
(2, 1200, PRIMITIVE_POLY_MIN_TERMS_2_1200),
(3, 399, PRIMITIVE_POLY_MIN_TERMS_3_399),
(3, 422, PRIMITIVE_POLY_MIN_TERMS_3_422),
(3, 549, PRIMITIVE_POLY_MIN_TERMS_3_549),
(3, 660, PRIMITIVE_POLY_MIN_TERMS_3_660),
(5, 296, PRIMITIVE_POLY_MIN_TERMS_5_296),
(5, 357, PRIMITIVE_POLY_MIN_TERMS_5_357),
(5, 404, PRIMITIVE_POLY_MIN_TERMS_5_404),
(5, 430, PRIMITIVE_POLY_MIN_TERMS_5_430),
(7, 129, PRIMITIVE_POLY_MIN_TERMS_7_129),
(7, 195, PRIMITIVE_POLY_MIN_TERMS_7_195),
(7, 284, PRIMITIVE_POLY_MIN_TERMS_7_284),
(7, 357, PRIMITIVE_POLY_MIN_TERMS_7_357),
]


def test_primitive_poly_exceptions():
with pytest.raises(TypeError):
Expand Down Expand Up @@ -164,6 +202,16 @@ def test_minimum_terms(order, degree, polys):
assert f.coeffs.tolist() in min_term_polys


@pytest.mark.timeout(1, method="signal")
@pytest.mark.parametrize("order,degree,polys", PARAMS_DB)
def test_minimum_terms_from_database(order, degree, polys):
p = galois.primitive_poly(order, degree, terms="min")
db_degrees = p.nonzero_degrees.tolist()
db_coeffs = p.nonzero_coeffs.tolist()
exp_degrees, exp_coeffs = polys
assert db_degrees == exp_degrees and db_coeffs == exp_coeffs


def test_conway_poly_exceptions():
with pytest.raises(TypeError):
galois.conway_poly(2.0, 3)
Expand Down

0 comments on commit 41486bf

Please sign in to comment.