generated from CambridgeEngineering/PartIA-Flood-Warning-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_geo.py
88 lines (70 loc) · 2.49 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
from floodsystem import geo
from floodsystem import station
from Flood import stations_level_over_threshold
def test_data():
s_id = "test-s-1"
m_id = "test-m-1"
label = "oxford station"
coord = (-2.0, 4.0)
trange = (-2.3, 3.4445)
river = "River X"
town = "oxford"
s1 = station.MonitoringStation(s_id, m_id, label, coord, trange, river, town)
s_id = "test-s-2"
m_id = "test-m-2"
label = "cambridge station"
coord = (0, 1)
town = "cambridge"
s2 = station.MonitoringStation(s_id, m_id, label, coord, trange, river, town)
s_id = "test-s-3"
m_id = "test-m-3"
label = "cambridge station 2"
coord = (0, 2)
s3 = station.MonitoringStation(s_id, m_id, label, coord, trange, river, town)
s_id = "test-s-4"
m_id = "test-m-4"
label = "cambridge station 3"
coord = (0, 2)
river = "River Y"
s4 = station.MonitoringStation(s_id, m_id, label, coord, trange, river, town)
s4.latest_level = 5
s4.typical_range = (-2.3, 3.4445)
river = 'River Z'
s5 = station.MonitoringStation(s_id, m_id, label, coord, trange, river, town)
s5.latest_level = 0.1
s5.typical_range = (-2.3, 3.4445)
return [s1, s2, s3, s4, s5]
def test_stations_by_distance():
result = geo.stations_by_distance(test_data(), (0, 0))
assert result[0] == ('cambridge station', 111.1950802335329)
def test_stations_within_radius():
result = geo.stations_within_radius(test_data(), (0, 0), 0)
assert len(result) == 0
assert type(result) == list
def test_rivers_with_station():
result = geo.rivers_with_station(test_data())
assert len(result) == 3
assert result.__contains__('River X' and 'River Y' and 'River Z')
def test_stations_by_river():
result = geo.stations_by_river(test_data())
assert (len(result["River Y"])) == 1
assert (type(result) == dict)
def test_rivers_by_station_number():
result = geo.rivers_by_station_number(test_data(), 1)
assert len(result) == 1
assert result[0] == ['River X', 3]
def test_relative_water_level():
result = stations_level_over_threshold(test_data(), 0.8)
result[0] = list(result[0])
result[0][0] = result[0][0].name
result[0] = tuple(result[0])
assert result == [('cambridge station 3', 1.2707807468012882)]
def alltest():
test_stations_by_distance()
test_stations_within_radius()
test_rivers_with_station()
test_stations_by_river()
test_rivers_by_station_number()
test_relative_water_level()
print("ALL CLEAR")
alltest()