1 """
2 Test cases for analysis modules.
3 - testCorrelation1: test for the autocorrelation of a single time serie.
4 - testCorrelation2: test for the autocorrelation of a two dimensional time serie.
5 - testCorrelation3: another test for the autocorrelation of a two dimensional time serie.
6 """
7
8 import unittest
9
10 from Scientific.N import array, zeros
11
12 from nMoldyn.Core.Mathematics.Analysis import correlation
13
15
16 """
17 Tests Analysis module functionnalities.
18 """
19
21
22 self.series1 = array([0,1,0,4,6,5])
23
24 self.results1 = array([13.0,10.8,6.0,2.0,2.5,0.0])
25
26
27 self.series2 = array([
28 [0,0,0,0,0,0,0,0,0,0],
29 [1,1,1,1,1,1,1,1,1,1],
30 [0,0,0,0,0,0,0,0,0,0],
31 [4,4,4,4,4,4,4,4,4,4],
32 [6,6,6,6,6,6,6,6,6,6],
33 [5,5,5,5,5,5,5,5,5,5]
34 ])
35
36 self.results2 = array([130.0,108.0,60.0,20.0,25.0,0.0])
37
38
39 self.series3 = array([
40 [0,2,0],
41 [1,1,-1],
42 [0,1,0],
43 [4,0,-4],
44 [6,5,0],
45 [5,0,3]
46 ])
47
48
49 self.results3 = array([22.5,11.4,5.75,11.0/3,6,0])
50
52 corr = correlation(self.series1)
53 errorMax = max(abs(corr-self.results1))
54 self.assertAlmostEqual(errorMax, 0.0, 10)
55
57 corr = correlation(self.series2)
58 errorMax = max(abs(corr-self.results2))
59 self.assertAlmostEqual(errorMax, 0.0, 10)
60
62 corr = correlation(self.series3)
63 errorMax = max(abs(corr-self.results3))
64 self.assertAlmostEqual(errorMax, 0.0, 10)
65
66 if __name__ == '__main__':
67 unittest.main()
68