-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_YMCounter.py
126 lines (86 loc) · 3.22 KB
/
test_YMCounter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import unittest
import numpy as np
import YMCounter as ym
class Test_chunks(unittest.TestCase):
def test_simples(self):
g = ym.YMCounter(1985,1,1985,12)
g.counter = np.array([1,0,1,0,1,0,1,0,1,0,1,0])
s, e = g.get_chunks(3)
self.assertEqual(s[0],0)
self.assertEqual(e[0],10)
self.assertEqual(len(s), 1)
self.assertEqual(len(e), 1)
def test_simples2(self):
g = ym.YMCounter(1985,1,1985,12)
g.counter = np.array([0,1,0,1,0,1,0,1,0,1,0,1])
s, e = g.get_chunks(3)
self.assertEqual(s[0],1)
self.assertEqual(e[0],11)
self.assertEqual(len(s), 1)
self.assertEqual(len(e), 1)
def test_all_present(self):
g = ym.YMCounter(1985,1,1985,12)
g.counter = np.array([1,1,1,1,1,1,1,1,1,1,1,1])
s, e = g.get_chunks(3)
self.assertEqual(s[0],0)
self.assertEqual(e[0],11)
self.assertEqual(len(s), 1)
self.assertEqual(len(e), 1)
def test_none(self):
g = ym.YMCounter(1985,1,1985,12)
g.counter = np.array([0,0,0,0,0,0,0,0,0,0,0,0])
s, e = g.get_chunks(3)
self.assertEqual(len(s), 0)
self.assertEqual(len(e), 0)
def test_onegap(self):
g = ym.YMCounter(1985,1,1985,12)
g.counter = np.array([1,1,1,0,0,0,1,1,1,1,1,1])
s, e = g.get_chunks(3)
self.assertEqual(s[0], 0)
self.assertEqual(e[0], 2)
self.assertEqual(s[1], 6)
self.assertEqual(e[1], 11)
class Test_yield(unittest.TestCase):
def test_endcase(self):
g = ym.YMCounter(1985, 1, 1985, 12)
g.counter = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
for yy1, mm1, yy2, mm2, cl in g.yield_start_and_end_dates(3):
pass
self.assertEqual(yy1, 1985)
self.assertEqual(yy2, 1985)
self.assertEqual(mm1, 12)
self.assertEqual(mm2, 12)
self.assertEqual(cl[0], 'end_edge_case')
def test_endcase(self):
g = ym.YMCounter(1985, 1, 1985, 12)
g.counter = np.array([1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0])
for yy1, mm1, yy2, mm2, cl in g.yield_start_and_end_dates(3):
pass
self.assertEqual(yy1, 1985)
self.assertEqual(yy2, 1985)
self.assertEqual(mm1, 1)
self.assertEqual(mm2, 6)
self.assertEqual(cl[0], 'start_edge_case')
def test_regular(self):
g = ym.YMCounter(1985, 1, 1985, 12)
g.counter = np.array([0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0])
for yy1, mm1, yy2, mm2, cl in g.yield_start_and_end_dates(3):
pass
self.assertEqual(yy1, 1985)
self.assertEqual(yy2, 1985)
self.assertEqual(mm1, 4)
self.assertEqual(mm2, 7)
self.assertEqual(cl[0], 'regular')
def test_new(self):
g = ym.YMCounter(1985, 1, 1985, 12)
g.counter = np.array([0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0])
for yy1, mm1, yy2, mm2, cl in g.yield_start_and_end_dates(3):
pass
self.assertEqual(yy1, 1985)
self.assertEqual(yy2, 1985)
self.assertEqual(mm1, 4)
self.assertEqual(mm2, 9)
self.assertIn('regular', cl)
self.assertIn('new', cl)
if __name__ == '__main__':
unittest.main()