Skip to content

Commit

Permalink
Add unit tests for Poly.coefficients()
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Dec 14, 2021
1 parent d3f2974 commit a89fd86
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/polys/test_operations.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
"""
A pytest module to test various Galois field polynomial operations.
"""
import pytest
import numpy as np

import galois
from galois._polys._poly import DensePoly, BinaryPoly, SparsePoly


def test_coefficients_exceptions():
GF = galois.GF(7)
p = galois.Poly([3, 0, 5, 2], field=GF)

with pytest.raises(TypeError):
p.coefficients(8.0)
with pytest.raises(TypeError):
p.coefficients(order=1)
with pytest.raises(ValueError):
p.coefficients(3)
with pytest.raises(ValueError):
p.coefficients(order="ascending")


def test_coefficients():
GF = galois.GF(7)
p = galois.Poly([3, 0, 5, 2], field=GF)
assert np.array_equal(p.coefficients(), p.coeffs)

coeffs = p.coefficients()
assert np.array_equal(coeffs, [3, 0, 5, 2])
assert type(coeffs) is GF

coeffs = p.coefficients(order="asc")
assert np.array_equal(coeffs, [2, 5, 0, 3])
assert type(coeffs) is GF

coeffs = p.coefficients(6)
assert np.array_equal(coeffs, [0, 0, 3, 0, 5, 2])
assert type(coeffs) is GF

coeffs = p.coefficients(6, order="asc")
assert np.array_equal(coeffs, [2, 5, 0, 3, 0, 0])
assert type(coeffs) is GF


def test_copy():
p1 = galois.Poly([2,0,1,2], field=galois.GF(3))
assert isinstance(p1, DensePoly)
Expand Down

0 comments on commit a89fd86

Please sign in to comment.