-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_statistics.py
More file actions
118 lines (107 loc) · 4.16 KB
/
Copy pathtest_statistics.py
File metadata and controls
118 lines (107 loc) · 4.16 KB
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
from unittest import TestCase
from statistics import Statistics
class TestStatistics(TestCase):
def test_verify_ids_unique(self):
s = Statistics()
data = [
{
"a":1,
"id":12
},
{
"b":1,
"id":12
}
]
get_unique_id = lambda x: x["id"]
with self.assertRaises(Exception):
s.verify_ids_unique(data, get_unique_id)
data[0]['id'] = 99
# Should not raise now.
s.verify_ids_unique(data, get_unique_id)
def test_get_annual_acres(self):
data = [
{ # Day 1
"data":[
{"name": "unchanged", "id": 1, "acres": 100},
{"name": "increasing", "id": 2, "acres": 100},
{"name": "decreasing", "id": 3, "acres": 100},
{"name": "vanished", "id": 4, "acres": 100},
],
"_year": 2021,
"_month": 6,
"_day": 28
},
{ # Day 2
"data": [
{"name": "unchanged", "id": 1, "acres": 100},
{"name": "increasing", "id": 2, "acres": 101},
{"name": "decreasing", "id": 3, "acres": 98},
{"name": "new", "id": 5, "acres": 3}, # +2 total
],
"_year": 2021,
"_month": 6,
"_day": 29
},
{ # Day 3
"data": [
{"name": "unchanged", "id": 1, "acres": 100},
{"name": "increasing", "id": 2, "acres": 102},
{"name": "decreasing", "id": 3, "acres": 96},
{"name": "new", "id": 5, "acres": 6}, # +2 since day 1
],
"_year": 2021,
"_month": 6,
"_day": 30
}
]
s = Statistics()
daily, overall_total_acres_burned = s.get_annual_acres_helper(data, 2021, None, lambda x:x['id'], lambda x:x['acres'])
self.assertEqual((2021, 6, 28, 400), daily[0])
self.assertEqual((2021, 6, 29, 2), daily[1])
self.assertEqual((2021, 6, 30, 2), daily[2])
self.assertEqual(overall_total_acres_burned, 404)
def test_get_annual_acres2(self):
data = [
{ # Day 1
"data":[
{"name": "unchanged", "id": 1, "acres": 100},
],
"_year": 2021,
"_month": 6,
"_day": 28
},
{ # Day 2
"data": [
{"name": "unchanged", "id": 1, "acres": 100},
],
"_year": 2021,
"_month": 6,
"_day": 29
},
{ # Day 3
"data": [
{"name": "unchanged", "id": 1, "acres": 100},
{"name": "new", "id": 2, "acres": 107},
],
"_year": 2021,
"_month": 6,
"_day": 30
}
]
s = Statistics()
daily, overall_total_acres_burned = s.get_annual_acres_helper(data, 2021, None, lambda x:x['id'], lambda x:x['acres'])
self.assertEqual((2021, 6, 28, 100), daily[0])
self.assertEqual((2021, 6, 29, 0), daily[1])
self.assertEqual((2021, 6, 30, 107), daily[2])
self.assertEqual(overall_total_acres_burned, 207)
daily, overall_total_acres_burned = s.get_annual_acres_helper(data,
2021,
None,
lambda x:x['id'],
lambda x:x['acres'],
cumulative=True)
self.assertEqual((2021, 6, 28, 100), daily[0])
self.assertEqual((2021, 6, 29, 100), daily[1])
self.assertEqual((2021, 6, 30, 207), daily[2])
self.assertEqual(overall_total_acres_burned, 207)