generated from CambridgeEngineering/PartIA-Flood-Warning-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_geo.py
113 lines (92 loc) · 3.89 KB
/
test_geo.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
"""Unit test for the geo module."""
from collections import defaultdict
from floodsystem.geo import (rivers_by_station_number, rivers_with_station, stations_by_distance,
stations_by_river, stations_within_radius)
from floodsystem.station import MonitoringStation
def test_stations_by_distance():
stations = []
coord_list = [(52.2, 0.11), (53.79648, -1.54785), (50.718395, -1.883377)]
p = (51.509865, -0.118092)
for i in range(len(coord_list)):
# Create a station
s_id = "test-s-id n"
m_id = "test-m-id n"
label = "some station n"
coord = coord_list[i]
trange = (-2.3, 3.4445)
river = "River" + str(i)
town = "My Town" + str(i)
stations.append(MonitoringStation(s_id, m_id, label, coord, trange, river, town))
assert stations_by_distance(stations, p) == [(stations[0], 78.32212827453219),
(stations[2], 151.419460832818),
(stations[1], 271.9227491652322)]
def test_stations_within_radius():
stations = []
coord_list = [(52.2, 0.11), (53.79648, -1.54785), (50.718395, -1.883377)]
p = (51.509865, -0.118092)
for i in range(len(coord_list)):
# Create a station
s_id = "test-s-id n"
m_id = "test-m-id n"
label = "some station n"
coord = coord_list[i]
trange = (-2.3, 3.4445)
river = "River" + str(i)
town = "My Town" + str(i)
stations.append(MonitoringStation(s_id, m_id, label, coord, trange, river, town))
assert stations_within_radius(stations, p, 160) == [stations[0], stations[2]]
def test_rivers_with_station():
stations = []
coord_list = [(52.2, 0.11), (53.79648, -1.54785), (50.718395, -1.883377)]
for i in range(len(coord_list)):
# Create a station
s_id = "test-s-id n"
m_id = "test-m-id n"
label = "some station n"
coord = coord_list[i]
trange = (-2.3, 3.4445)
river = "River" + str(i)
town = "My Town" + str(i)
stations.append(MonitoringStation(s_id, m_id, label, coord, trange, river, town))
assert rivers_with_station(stations) == {stations[0].river, stations[1].river, stations[2].river}
def test_stations_by_river():
stations = []
Riv = defaultdict(list)
coord_list = [(52.2, 0.11), (53.79648, -1.54785), (50.718395, -1.883377)]
for i in range(len(coord_list)):
# Create a station
s_id = "test-s-id n"
m_id = "test-m-id n"
label = "some station n"
coord = coord_list[i]
trange = (-2.3, 3.4445)
river = "River" + str(i)
town = "My Town" + str(i)
stations.append(MonitoringStation(s_id, m_id, label, coord, trange, river, town))
Riv[stations[i].river].append(stations[i])
assert Riv == (stations_by_river(stations))
def test_rivers_by_station_number():
stations = []
coord_list = [(52.2, 0.11), (53.79648, -1.54785), (50.718395, -1.883377)]
coord_list2 = [(52.7, 0.67), (51.0006, -1.0), (50.718395, -0.9857)]
for i in range(len(coord_list)):
# Create a station
s_id = "test-s-id n"
m_id = "test-m-id n"
label = "some station n"
coord = coord_list[i]
trange = (-2.3, 3.4445)
river = "River" + str(i)
town = "My Town" + str(i)
stations.append(MonitoringStation(s_id, m_id, label, coord, trange, river, town))
for i in range(len(coord_list2)):
# Create a station
s_id = "test-s-id n"
m_id = "test-m-id n"
label = "some station n"
coord = coord_list2[i]
trange = (-2.3, 3.4445)
river = "River" + str(i**2)
town = "My Town" + str(i)
stations.append(MonitoringStation(s_id, m_id, label, coord, trange, river, town))
assert rivers_by_station_number(stations, 2) == [('River0', 2), ('River1', 2)]