Skip to content

Commit

Permalink
Improve class factory code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed May 12, 2022
1 parent 94db928 commit eadc6a3
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions tests/fields/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,6 @@ def test_basic_exceptions():
galois.GF(2**8, display="invalid-argument")


@pytest.mark.parametrize("characteristic,degree", [(2,8), (3,5)])
def test_specify_irreducible_poly(characteristic, degree):
GF = galois.GF(characteristic**degree)
poly = GF.irreducible_poly
assert galois.GF(characteristic**degree, irreducible_poly=int(poly)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=str(poly)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=tuple(poly.coeffs)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=list(poly.coeffs)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=np.array(poly.coeffs)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=poly.coeffs) is GF
assert galois.GF(characteristic**degree, irreducible_poly=poly) is GF


def test_irreducible_poly_exceptions():
with pytest.raises(TypeError):
galois.GF(2**8, irreducible_poly=285.0)
Expand All @@ -103,6 +90,38 @@ def test_irreducible_poly_exceptions():
galois.GF(3, irreducible_poly=[1, 1])


def test_primitive_element_exceptions():
with pytest.raises(TypeError):
galois.GF(2**8, primitive_element=2.0)
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=256)
with pytest.raises(ValueError):
galois.GF(7, primitive_element=10)
with pytest.raises(ValueError):
galois.GF(7, primitive_element=4)
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=galois.Poly([1, 0], field=galois.GF(3)))
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=galois.Poly([1, 0], field=galois.GF(3)))
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=galois.Poly([1, 0, 0, 0, 1, 1, 1, 0, 1]))
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=galois.Poly([1, 1, 1]))


@pytest.mark.parametrize("characteristic,degree", [(2,8), (3,5)])
def test_specify_irreducible_poly(characteristic, degree):
GF = galois.GF(characteristic**degree)
poly = GF.irreducible_poly
assert galois.GF(characteristic**degree, irreducible_poly=int(poly)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=str(poly)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=tuple(poly.coeffs)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=list(poly.coeffs)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=np.array(poly.coeffs)) is GF
assert galois.GF(characteristic**degree, irreducible_poly=poly.coeffs) is GF
assert galois.GF(characteristic**degree, irreducible_poly=poly) is GF


@pytest.mark.parametrize("characteristic,degree", [(2,1), (3,1)])
def test_specify_primitive_element_prime(characteristic, degree):
GF = galois.GF(characteristic**degree)
Expand All @@ -121,16 +140,3 @@ def test_specify_primitive_element_extension(characteristic, degree):
assert galois.GF(characteristic**degree, primitive_element=np.array(poly.coeffs)) is GF
assert galois.GF(characteristic**degree, primitive_element=poly.coeffs) is GF
assert galois.GF(characteristic**degree, primitive_element=poly) is GF


def test_primitive_element_exceptions():
with pytest.raises(TypeError):
galois.GF(2**8, primitive_element=2.0)
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=256)
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=galois.Poly([1, 0], field=galois.GF(3)))
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=galois.Poly([1, 0, 0, 0, 1, 1, 1, 0, 1]))
with pytest.raises(ValueError):
galois.GF(2**8, primitive_element=galois.Poly([1, 1, 1]))

0 comments on commit eadc6a3

Please sign in to comment.