Update to 2.0.0 tree from current Fremantle build
[opencv] / tests / swig_python / roots_tests.py
1 #!/usr/bin/env python
2
3 # 2009-01-16, Xavier Delacour <xavier.delacour@gmail.com>
4
5 import unittest
6 from numpy import *;
7 from numpy.linalg import *;
8 import sys;
9
10 import cvtestutils
11 from cv import *;
12 from adaptors import *;
13
14 ## these are mostly to test bindings, since there are more/better tests in tests/cxcore
15
16 def verify(x,y):
17     x = Ipl2NumPy(x);
18     assert(all(abs(x - y)<1e-4));
19
20 class roots_test(unittest.TestCase):
21     
22     def test_cvSolvePoly(self):
23         
24         verify(cvSolvePoly(asmatrix([-1,1]).astype(float64)),
25                     array([[(1.000000, 0.000000)]]));
26
27         verify(cvSolvePoly(asmatrix([-1,1]).astype(float32)),
28                     array([[(1.000000, 0.000000)]]));
29
30         verify(cvSolvePoly(asmatrix([-1,0,0,0,0,1]).astype(float64)),
31                array([[(1, 0)],[(0.309017, 0.951057)],[(0.309017, -0.951057)],
32                       [(-0.809017, 0.587785)],[(-0.809017, -0.587785)]]))
33
34         verify(cvSolvePoly(asmatrix([-1,0,0,0,0,1]).astype(float32)),
35                array([[(1, 0)],[(0.309017, 0.951057)],[(0.309017, -0.951057)],
36                       [(-0.809017, 0.587785)],[(-0.809017, -0.587785)]]))
37
38     def test_cvSolveCubic(self):
39
40         verify(cvSolveCubic(asmatrix([-1,0,0,1]).astype(float32))[1],
41                array([[1],[0],[0]]));
42
43         verify(cvSolveCubic(asmatrix([-1,0,0,1]).astype(float64))[1],
44                array([[1],[0],[0]]));
45
46 def suite():
47     return unittest.TestLoader().loadTestsFromTestCase(roots_test)
48
49 if __name__ == '__main__':
50     unittest.TextTestRunner(verbosity=2).run(suite())
51