Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
- Add LUTs for a sample of irreducible polynomials from Gadiel Seroussi's table
- Add test_minimum_terms_from_database
  • Loading branch information
iyanmv committed Jan 22, 2023
1 parent ed2e186 commit 1402a77
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/polys/luts/irreducible_polys_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
A module containing LUTs for irreducible polynomials with min terms from irreducible_polys.db
"""

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

# Gadiel Seroussi's table (1998)
# LUT items obtained by randomly picking degrees and checking the PDF
# sorted(numpy.random.default_rng(1337).integers(size=5, low=500, high=10_000, endpoint=True))

IRREDUCIBLE_POLY_MIN_TERMS_2_2262 = [[2262, 57, 0], [1, 1, 1]]
IRREDUCIBLE_POLY_MIN_TERMS_2_5632 = [[5632, 17, 15, 5, 0], [1, 1, 1, 1, 1]]
IRREDUCIBLE_POLY_MIN_TERMS_2_5690 = [[5690, 1623, 0], [1, 1, 1]]
IRREDUCIBLE_POLY_MIN_TERMS_2_7407 = [[7407, 27, 21, 17, 0], [1, 1, 1, 1, 1]]
IRREDUCIBLE_POLY_MIN_TERMS_2_8842 = [[8842, 4143, 0], [1, 1, 1]]
29 changes: 29 additions & 0 deletions tests/polys/test_irreducible_polys.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
A pytest module to test generating irreducible polynomials over finite fields.
"""
import time
import numpy as np
import pytest

Expand Down Expand Up @@ -42,6 +43,14 @@
)
from .luts.irreducible_polys_25 import IRREDUCIBLE_POLYS_25_1, IRREDUCIBLE_POLYS_25_2

from .luts.irreducible_polys_database import (
IRREDUCIBLE_POLY_MIN_TERMS_2_2262,
IRREDUCIBLE_POLY_MIN_TERMS_2_5632,
IRREDUCIBLE_POLY_MIN_TERMS_2_5690,
IRREDUCIBLE_POLY_MIN_TERMS_2_7407,
IRREDUCIBLE_POLY_MIN_TERMS_2_8842,
)

PARAMS = [
(2, 1, IRREDUCIBLE_POLYS_2_1),
(2, 2, IRREDUCIBLE_POLYS_2_2),
Expand Down Expand Up @@ -71,6 +80,14 @@
(5**2, 2, IRREDUCIBLE_POLYS_25_2),
]

PARAMS_DB = [
(2, 2262, IRREDUCIBLE_POLY_MIN_TERMS_2_2262),
(2, 5632, IRREDUCIBLE_POLY_MIN_TERMS_2_5632),
(2, 5690, IRREDUCIBLE_POLY_MIN_TERMS_2_5690),
(2, 7407, IRREDUCIBLE_POLY_MIN_TERMS_2_7407),
(2, 8842, IRREDUCIBLE_POLY_MIN_TERMS_2_8842),
]


def test_irreducible_poly_exceptions():
with pytest.raises(TypeError):
Expand Down Expand Up @@ -160,6 +177,18 @@ def test_minimum_terms(order, degree, polys):
assert f.coeffs.tolist() in min_term_polys


@pytest.mark.parametrize("order,degree,polys", PARAMS_DB)
def test_minimum_terms_from_database(order, degree, polys):
tick = time.time()
p = galois.irreducible_poly(order, degree, terms="min")
tock = time.time()
assert tock - tick < 1.0
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_large_degree():
"""
See https://github.com/mhostetter/galois/issues/360.
Expand Down

0 comments on commit 1402a77

Please sign in to comment.