diff options
author | jbCodeHub <besselingcodehub@gmail.com> | 2021-02-28 09:58:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-28 09:58:54 +0100 |
commit | 592b71c8cd10ef3cf9bccebb6c3ed0198f105484 (patch) | |
tree | 00c9fa219be28ef288357b7e87192d5b42b7a686 | |
parent | 1932e4bdc460975d8b35ae8351e037d26e5ee6f8 (diff) | |
download | numpy-592b71c8cd10ef3cf9bccebb6c3ed0198f105484.tar.gz |
TST: Branch coverage improvement for `np.polynomial` (#18499)
* added tests for vander_nd in test_polyutils to cover some of the missed branches
* added tests to polyline and vander to improve branch coverage
* added tests to test_legendre.py to improve branch coverage
-rw-r--r-- | numpy/polynomial/tests/test_legendre.py | 12 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_polynomial.py | 7 | ||||
-rw-r--r-- | numpy/polynomial/tests/test_polyutils.py | 15 |
3 files changed, 34 insertions, 0 deletions
diff --git a/numpy/polynomial/tests/test_legendre.py b/numpy/polynomial/tests/test_legendre.py index a2a212c24..92399c160 100644 --- a/numpy/polynomial/tests/test_legendre.py +++ b/numpy/polynomial/tests/test_legendre.py @@ -305,6 +305,9 @@ class TestIntegral: res = leg.legint(c2d, k=3, axis=1) assert_almost_equal(res, tgt) + def test_legint_zerointord(self): + assert_equal(leg.legint((1, 2, 3), 0), (1, 2, 3)) + class TestDerivative: @@ -345,6 +348,9 @@ class TestDerivative: res = leg.legder(c2d, axis=1) assert_almost_equal(res, tgt) + def test_legder_orderhigherthancoeff(self): + c = (1, 2, 3, 4) + assert_equal(leg.legder(c, 4), [0]) class TestVander: # some random values in [-1, 1) @@ -393,6 +399,9 @@ class TestVander: van = leg.legvander3d([x1], [x2], [x3], [1, 2, 3]) assert_(van.shape == (1, 5, 24)) + def test_legvander_negdeg(self): + assert_raises(ValueError, leg.legvander, (1, 2, 3), -1) + class TestFitting: @@ -541,6 +550,9 @@ class TestMisc: def test_legline(self): assert_equal(leg.legline(3, 4), [3, 4]) + def test_legline_zeroscl(self): + assert_equal(leg.legline(3, 0), [3]) + def test_leg2poly(self): for i in range(10): assert_almost_equal(leg.leg2poly([0]*i + [1]), Llist[i]) diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py index 5fd1a82a2..a0a09fcf4 100644 --- a/numpy/polynomial/tests/test_polynomial.py +++ b/numpy/polynomial/tests/test_polynomial.py @@ -473,6 +473,10 @@ class TestVander: van = poly.polyvander3d([x1], [x2], [x3], [1, 2, 3]) assert_(van.shape == (1, 5, 24)) + def test_polyvandernegdeg(self): + x = np.arange(3) + assert_raises(ValueError, poly.polyvander, x, -1) + class TestCompanion: @@ -591,3 +595,6 @@ class TestMisc: def test_polyline(self): assert_equal(poly.polyline(3, 4), [3, 4]) + + def test_polyline_zero(self): + assert_equal(poly.polyline(3, 0), [3]) diff --git a/numpy/polynomial/tests/test_polyutils.py b/numpy/polynomial/tests/test_polyutils.py index 1b27f53b5..cc630790d 100644 --- a/numpy/polynomial/tests/test_polyutils.py +++ b/numpy/polynomial/tests/test_polyutils.py @@ -40,6 +40,21 @@ class TestMisc: assert_equal(pu.trimcoef(coef, 1), coef[:-3]) assert_equal(pu.trimcoef(coef, 2), [0]) + def test_vander_nd_exception(self): + # n_dims != len(points) + assert_raises(ValueError, pu._vander_nd, (), (1, 2, 3), [90]) + # n_dims != len(degrees) + assert_raises(ValueError, pu._vander_nd, (), (), [90.65]) + # n_dims == 0 + assert_raises(ValueError, pu._vander_nd, (), (), []) + + def test_div_zerodiv(self): + # c2[-1] == 0 + assert_raises(ZeroDivisionError, pu._div, pu._div, (1, 2, 3), [0]) + + def test_pow_too_large(self): + # power > maxpower + assert_raises(ValueError, pu._pow, (), [1, 2, 3], 5, 4) class TestDomain: |