Skip to content

Commit

Permalink
Merge pull request #24571 from eendebakpt/polynomial_tests
Browse files Browse the repository at this point in the history
MAINT: Add tests for Polynomial with fractions.Fraction coefficients
  • Loading branch information
charris committed Aug 29, 2023
2 parents f936356 + c1f9a3b commit 18d89cc
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions numpy/polynomial/tests/test_polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"""
from functools import reduce

from fractions import Fraction
import numpy as np
import numpy.polynomial.polynomial as poly
import pickle
from copy import deepcopy
from numpy.testing import (
assert_almost_equal, assert_raises, assert_equal, assert_,
assert_warns, assert_array_equal, assert_raises_regex)
assert_array_equal, assert_raises_regex)


def trim(x):
Expand Down Expand Up @@ -122,6 +122,25 @@ def test_polypow(self):
res = poly.polypow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)

class TestFraction:

def test_Fraction(self):
# assert we can use Polynomials with coefficients of object dtype
f = Fraction(2, 3)
one = Fraction(1, 1)
zero = Fraction(0, 1)
p = poly.Polynomial([f, f], domain=[zero, one], window=[zero, one])

x = 2 * p + p ** 2
assert_equal(x.coef, np.array([Fraction(16, 9), Fraction(20, 9),
Fraction(4, 9)], dtype=object))
assert_equal(p.domain, [zero, one])
assert_equal(p.coef.dtype, np.dtypes.ObjectDType())
assert_(isinstance(p(f), Fraction))
assert_equal(p(f), Fraction(10, 9))
p_deriv = poly.Polynomial([Fraction(2, 3)], domain=[zero, one],
window=[zero, one])
assert_equal(p.deriv(), p_deriv)

class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
Expand Down

0 comments on commit 18d89cc

Please sign in to comment.