From 6a88cb9cced64ba2e0079c5df48b9734ec0f05bc Mon Sep 17 00:00:00 2001 From: endolith Date: Wed, 27 Nov 2013 00:27:04 -0500 Subject: TST: Add tests for np.poly() --- numpy/lib/tests/test_polynomial.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'numpy/lib') diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py index 5c15941e6..8574fd813 100644 --- a/numpy/lib/tests/test_polynomial.py +++ b/numpy/lib/tests/test_polynomial.py @@ -89,6 +89,28 @@ class TestDocs(TestCase): def test_doctests(self): return rundocs() + def test_poly(self): + assert_array_almost_equal(np.poly([3, -np.sqrt(2), np.sqrt(2)]), + [1, -3, -2, 6]) + + # From matlab docs + A = [[1, 2, 3], [4, 5, 6], [7, 8, 0]] + assert_array_almost_equal(np.poly(A), [1, -6, -72, -27]) + + # Should produce real output for perfect conjugates + assert_(np.isrealobj(np.poly([+1.082j, +2.613j, -2.613j, -1.082j]))) + assert_(np.isrealobj(np.poly([0+1j, -0+-1j, 1+2j, 1-2j, 1.+3.5j, 1-3.5j]))) + assert_(np.isrealobj(np.poly([1j, -1j, 1+2j, 1-2j, 1+3j, 1-3.j]))) + assert_(np.isrealobj(np.poly([1j, -1j, 1+2j, 1-2j]))) + assert_(np.isrealobj(np.poly([1j, -1j, 2j, -2j]))) + assert_(np.isrealobj(np.poly([1j, -1j]))) + assert_(np.isrealobj(np.poly([1, -1]))) + + assert_(np.iscomplexobj(np.poly([1j, -1.0000001j]))) + + a = rand(100) + 1j* rand(100) + assert_(np.isrealobj(np.poly(np.concatenate((a, np.conjugate(a)))))) + def test_roots(self): assert_array_equal(np.roots([1, 0, 0]), [0, 0]) -- cgit v1.2.1