comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/polynomial/tests/test_polyutils.py @ 87:2a2c65a20a8b

Add Python libs and headers
author Chris Cannam
date Wed, 25 Feb 2015 14:05:22 +0000
parents
children
comparison
equal deleted inserted replaced
86:413a9d26189e 87:2a2c65a20a8b
1 """Tests for polyutils module.
2
3 """
4 from __future__ import division, absolute_import, print_function
5
6 import numpy as np
7 import numpy.polynomial.polyutils as pu
8 from numpy.testing import (
9 TestCase, assert_almost_equal, assert_raises,
10 assert_equal, assert_, run_module_suite)
11
12
13 class TestMisc(TestCase):
14
15 def test_trimseq(self):
16 for i in range(5):
17 tgt = [1]
18 res = pu.trimseq([1] + [0]*5)
19 assert_equal(res, tgt)
20
21 def test_as_series(self):
22 # check exceptions
23 assert_raises(ValueError, pu.as_series, [[]])
24 assert_raises(ValueError, pu.as_series, [[[1, 2]]])
25 assert_raises(ValueError, pu.as_series, [[1], ['a']])
26 # check common types
27 types = ['i', 'd', 'O']
28 for i in range(len(types)):
29 for j in range(i):
30 ci = np.ones(1, types[i])
31 cj = np.ones(1, types[j])
32 [resi, resj] = pu.as_series([ci, cj])
33 assert_(resi.dtype.char == resj.dtype.char)
34 assert_(resj.dtype.char == types[i])
35
36 def test_trimcoef(self):
37 coef = [2, -1, 1, 0]
38 # Test exceptions
39 assert_raises(ValueError, pu.trimcoef, coef, -1)
40 # Test results
41 assert_equal(pu.trimcoef(coef), coef[:-1])
42 assert_equal(pu.trimcoef(coef, 1), coef[:-3])
43 assert_equal(pu.trimcoef(coef, 2), [0])
44
45
46 class TestDomain(TestCase):
47
48 def test_getdomain(self):
49 # test for real values
50 x = [1, 10, 3, -1]
51 tgt = [-1, 10]
52 res = pu.getdomain(x)
53 assert_almost_equal(res, tgt)
54
55 # test for complex values
56 x = [1 + 1j, 1 - 1j, 0, 2]
57 tgt = [-1j, 2 + 1j]
58 res = pu.getdomain(x)
59 assert_almost_equal(res, tgt)
60
61 def test_mapdomain(self):
62 # test for real values
63 dom1 = [0, 4]
64 dom2 = [1, 3]
65 tgt = dom2
66 res = pu. mapdomain(dom1, dom1, dom2)
67 assert_almost_equal(res, tgt)
68
69 # test for complex values
70 dom1 = [0 - 1j, 2 + 1j]
71 dom2 = [-2, 2]
72 tgt = dom2
73 x = dom1
74 res = pu.mapdomain(x, dom1, dom2)
75 assert_almost_equal(res, tgt)
76
77 # test for multidimensional arrays
78 dom1 = [0, 4]
79 dom2 = [1, 3]
80 tgt = np.array([dom2, dom2])
81 x = np.array([dom1, dom1])
82 res = pu.mapdomain(x, dom1, dom2)
83 assert_almost_equal(res, tgt)
84
85 # test that subtypes are preserved.
86 dom1 = [0, 4]
87 dom2 = [1, 3]
88 x = np.matrix([dom1, dom1])
89 res = pu.mapdomain(x, dom1, dom2)
90 assert_(isinstance(res, np.matrix))
91
92 def test_mapparms(self):
93 # test for real values
94 dom1 = [0, 4]
95 dom2 = [1, 3]
96 tgt = [1, .5]
97 res = pu. mapparms(dom1, dom2)
98 assert_almost_equal(res, tgt)
99
100 # test for complex values
101 dom1 = [0 - 1j, 2 + 1j]
102 dom2 = [-2, 2]
103 tgt = [-1 + 1j, 1 - 1j]
104 res = pu.mapparms(dom1, dom2)
105 assert_almost_equal(res, tgt)
106
107
108 if __name__ == "__main__":
109 run_module_suite()