-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_map_camps_timehistory.py
47 lines (38 loc) · 1.66 KB
/
test_map_camps_timehistory.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
import map_camps_timehistory as mct
import pandas as pd
import unittest
class test_mct(unittest.TestCase):
def setUp(self):
N = 100
popn = [n * 500 for n in range(N)]
self.t = {"Bujumbura":popn, "Bubanza":popn}
self.ts = pd.DataFrame(data=self.t)
self.d = {'name': ["Bujumbura","Bubanza"],
'longitude': [29.3644,29.391],
'latitude' :[-3.3822,-3.0804],
'location_type': ["conflict","city"],
'time': [20,50]}
self.df = pd.DataFrame(data=self.d)
i = 0
def test_get_loctype(self):
for location in self.df.itertuples():
loctype = mct.get_loctype(location, self.ts.index)
assert len(loctype) == len(self.ts.index)
for t in range(location.time):
self.assertEqual(loctype[t], 'city')
for t in range(location.time, len(loctype)):
self.assertEqual(loctype[t], 'conflict')
def test_get_population(self):
# get_population(timeseries_data, name, defaultpop=1000)
pop_buj = mct.get_population(self.ts, 'Bujumbura')
assert (pop_buj == self.ts['Bujumbura']).all()
# Test handling missing location
pop_dflt = mct.get_population(self.ts, 'Not a place', defaultpop=919)
assert (pop_dflt == 919).all(), pop_dflt
def test_make_features(self):
# Smoke test - check that it doesn't crash doing this
mct.make_features(locations_file='blocations.csv',
timeseries_file='burundioutput.csv',
startdate='2015-05-01')
if __name__ == '__main__':
unittest.main()