def test_primitive_poly_exceptions(): with pytest.raises(TypeError): galois.primitive_poly(2.0, 3) with pytest.raises(TypeError): galois.primitive_poly(2, 3.0) with pytest.raises(ValueError): galois.primitive_poly(2**2 * 3**2, 3) with pytest.raises(ValueError): galois.primitive_poly(2, 0) with pytest.raises(ValueError): galois.primitive_poly(2, 3, method="invalid-argument")
def test_rs_generator_poly(): # S. Lin and D. Costello. Error Control Coding. Example 7.1, p. 238. p = galois.primitive_poly(2, 6) GF = galois.GF(2**6, irreducible_poly=p) a = GF.primitive_element assert galois.ReedSolomon(63, 57).generator_poly == galois.Poly(a**np.array([0, 59, 48, 43, 55, 10, 21]), field=GF) # Octave rsgenpoly() assert np.array_equal(galois.ReedSolomon(15, 13).generator_poly.coeffs, [1, 6, 8]) assert np.array_equal(galois.ReedSolomon(15, 11).generator_poly.coeffs, [1, 13, 12, 8, 7]) assert np.array_equal(galois.ReedSolomon(15, 9).generator_poly.coeffs, [1, 7, 9, 3, 12, 10, 12]) assert np.array_equal(galois.ReedSolomon(15, 7).generator_poly.coeffs, [1, 9, 4, 3, 4, 13, 6, 14, 12]) assert np.array_equal(galois.ReedSolomon(15, 5).generator_poly.coeffs, [1, 4, 8, 10, 12, 9, 4, 2, 12, 2, 7]) assert np.array_equal(galois.ReedSolomon(15, 3).generator_poly.coeffs, [1, 5, 9, 5, 8, 1, 4, 13, 9, 4, 12, 13, 8]) assert np.array_equal(galois.ReedSolomon(15, 1).generator_poly.coeffs, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) # Ensure we're using the correct default primitive polynomial assert np.array_equal(galois.ReedSolomon(7, 5).generator_poly.coeffs, [1, 6, 3]) assert np.array_equal(galois.ReedSolomon(15, 9).generator_poly.coeffs, [1, 7, 9, 3, 12, 10, 12]) assert np.array_equal(galois.ReedSolomon(31, 25).generator_poly.coeffs, [1, 17, 26, 30, 27, 30, 24]) assert np.array_equal(galois.ReedSolomon(63, 57).generator_poly.coeffs, [1, 61, 13, 55, 46, 48, 59]) assert np.array_equal(galois.ReedSolomon(127, 121).generator_poly.coeffs, [1, 126, 64, 68, 100, 34, 109]) assert np.array_equal(galois.ReedSolomon(255, 249).generator_poly.coeffs, [1, 126, 4, 158, 58, 49, 117]) assert np.array_equal(galois.ReedSolomon(511, 505).generator_poly.coeffs, [1, 126, 254, 108, 222, 26, 76])
def test_primitive_poly_random(order, degree): LUT = eval(f"PRIMITIVE_POLYS_{order}_{degree}") assert galois.primitive_poly(order, degree, method="random").coeffs.tolist() in LUT
def test_primitive_poly_max(order, degree): LUT = eval(f"PRIMITIVE_POLYS_{order}_{degree}") assert galois.primitive_poly(order, degree, method="max").coeffs.tolist() == LUT[-1]
def test_primitive_poly_min(order, degree): LUT = eval(f"PRIMITIVE_POLYS_{order}_{degree}") assert galois.primitive_poly(order, degree).coeffs.tolist() == LUT[0]