-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_earthquake_analysis.py
140 lines (69 loc) · 3.47 KB
/
test_earthquake_analysis.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- coding: utf-8 -*-
"""
Unit tests for the functions defined in earthquake_analysis.
@author: Sackitey Joseph
"""
import earthquake_analysis, earthquake
def test_earthquake_count():
# count of all earthquakes with magnitude above 0
mag = 0
#expected count of all earthquakes with magnitude above o
expected_count = 97
#actual returned count from the function
computed_count = earthquake_analysis.earthquake_count(earthquake.data,mag)
# variable to store if the test passed
success = computed_count == expected_count
# message to display if the test fails
num_test_msg =f"computed {computed_count}, expected {expected_count}"
# count of earthquakes with magnitudes above 5
mag_above_five= 5
#expected return from the function of all earthquakes with magnitudes above 5
expected_output = 32
# computed output from the function
computed_output= earthquake_analysis.earthquake_count(earthquake.data,mag_above_five)
# variable to store passed variables
above_five_success= (computed_output==expected_output)
# message to display if test fails
above_five_test_msg=f"computed {computed_output}, expected {expected_output}"
assert above_five_success, above_five_test_msg
assert success, num_test_msg
#test_number_of_earthquakes()
def test_max_location():
#expected return from the function
expected_output = [['Indonesia',13]]
#actual returned string from the function
computed_output = earthquake_analysis.max_location(earthquake.data)
# variable to store if the test passed
success = computed_output == expected_output
# message to display if the test fails
num_test_msg=f"computed {computed_output}, expected {expected_output}"
assert success, num_test_msg
#test_location_with_most_earthquake()
def test_max_magnitude():
#expected return from the function
expected_output = [['2023-10-23T10:10:15.384Z', '2023-10-23', '10:10:15', -29.9476, -177.5191, 23.092, 6, 'New Zealand', 'Kermadec Islands, New Zealand']]
#actual returned string from the function
computed_output = earthquake_analysis.max_magnitude(earthquake.data,)
# variable to store if the test passed
success = computed_output == expected_output
# message to display if the test fails
highest_test_msg=f"computed {computed_output}, expected {expected_output}"
assert success, highest_test_msg
#test_highest_earthquake()
epsilon = 1e-10
def test_avg_magnitude():
depth = 100
#expected return from the function
expected_output = 4.79
#actual returned string from the function
computed_output = float(f"{earthquake_analysis.avg_magnitude(earthquake.data,depth):.2f}")
# variable to store if the test passed
success = abs(expected_output - computed_output) < epsilon
# message to display if the test fails
num_test_msg=f"computed {computed_output}, expected {expected_output}"
assert success,num_test_msg
if __name__ == "__main__":
test_avg_magnitude()
test_max_magnitude()
test_max_location()
test_earthquake_count()