Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rtmooy authored Dec 17, 2018
0 parents commit 88c3943
Show file tree
Hide file tree
Showing 21 changed files with 667 additions and 0 deletions.
187 changes: 187 additions & 0 deletions funcsTests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import unittest
from quakeFuncs import *

class TestCases(unittest.TestCase):

def test_earthquake_init(self):
quake = Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290)
self.assertEqual(quake.place, '12km SSW of Idyllwild, CA')
self.assertAlmostEqual(quake.mag, 0.97)
self.assertAlmostEqual(quake.longitude, -116.7551651)
self.assertAlmostEqual(quake.latitude, 33.6391678)
self.assertEqual(quake.time, 1488177290)

def test_earthquake_init2(self):
quake = Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538)
self.assertEqual(quake.place, '5km S of Gilroy, California')
self.assertAlmostEqual(quake.mag, 2.19)
self.assertAlmostEqual(quake.longitude, -121.5801697)
self.assertAlmostEqual(quake.latitude, 36.9580002)
self.assertEqual(quake.time, 1488173538)
def test_earthquake_repr(self):
quake = Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538)
self.assertEqual(repr(quake), '2.19 -121.5801697 36.9580002 1488173538 5km S of Gilroy, California\n')
def test_earthquake_str(self):
quake = Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538)
self.assertEqual(str(quake), '(2.19) 5km S of Gilroy, California at 2017-02-26 21:32:18 (-121.580, 36.958)')
def test_earthquakes_equal_0(self):
quake1 = Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290)
quake2 = Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290)
self.assertEqual(quake1, quake2)

def test_earthquakes_equal_1(self):
quake1 = Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290)
quake2 = Earthquake('13km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290)
self.assertNotEqual(quake1, quake2)

def test_read_file_0(self):
quakes = []
quakes.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
quakes.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
# call read_file with 'test0.txt'
self.assertEqual(read_quakes_from_file('test0.txt'), quakes)

def test_read_file_1(self):
quakes = []
quakes.append(Earthquake('12km SSW of Idyllwild, CA', 0.98, -116.7551651, 33.6391678, 1488177290))
quakes.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
# call read_file with 'test0.txt'
self.assertNotEqual(read_quakes_from_file('test0.txt'), quakes)

def test_filter_by_mag_0(self):
quakes = []
quakes.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
quakes.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
quakes.append(Earthquake('100km SE of King Salmon, Alaska', 1.9, -155.2835, 58.1548, 1488219604))
filtered = []
filtered.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
filtered.append(Earthquake('100km SE of King Salmon, Alaska', 1.9, -155.2835, 58.1548, 1488219604))
self.assertEqual(filter_by_mag(quakes, 1, 3), filtered)

def test_filter_by_mag_1(self):
quakes = []
quakes.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
quakes.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
quakes.append(Earthquake('100km SE of King Salmon, Alaska', 1.9, -155.2835, 58.1548, 1488219604))
filtered = []
filtered.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
filtered.append(Earthquake('100km SE of King Salmon, Alaska', 1.9, -155.2835, 58.1548, 1488219604))
self.assertEqual(filter_by_mag(quakes, 0, 2), filtered)

def test_filter_by_place_0(self):
quakes = []
quakes.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
quakes.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
quakes.append(Earthquake('100km SE of King Salmon, Alaska', 1.9, -155.2835, 58.1548, 1488219604))
filtered = []
filtered.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
filtered.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
self.assertEqual(filter_by_place(quakes, "ca"), filtered)

def test_filter_by_place_1(self):
quakes = []
quakes.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
quakes.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
quakes.append(Earthquake('100km SE of King Salmon, Alaska', 1.9, -155.2835, 58.1548, 1488219604))
filtered = []
filtered.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
filtered.append(Earthquake('100km SE of King Salmon, Alaska', 1.9, -155.2835, 58.1548, 1488219604))
self.assertEqual(filter_by_place(quakes, "al"), filtered)

def test_sort_by_mag_0(self):
quakes = []
quakes.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
quakes.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
quakes.append(Earthquake('100km SE of King Salmon, Alaska', 0.56, -155.2835, 58.1548, 1488219604))
sort = []
sort.append(Earthquake('5km S of Gilroy, California', 2.19, -121.5801697, 36.9580002, 1488173538))
sort.append(Earthquake('100km SE of King Salmon, Alaska', 0.56, -155.2835, 58.1548, 1488219604))
sort.append(Earthquake('12km SSW of Idyllwild, CA', 0.97, -116.7551651, 33.6391678, 1488177290))
self.assertNotEqual(sort_quakes(quakes, "m"), sort)
# Use this test when ready to work on the json data.
def test_quake_from_feature(self):
feature = {
"geometry": {
"coordinates": [
-117.4906667,
33.9131667,
0.25
],
"type": "Point"
},
"id": "ci37814000",
"properties": {
"code": "37814000",
"detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci37814000.geojson",
"dmin": 0.2836,
"gap": 87,
"ids": ",ci37814000,",
"mag": 1.24,
"magType": "ml",
"net": "ci",
"nst": 8,
"place": "5km NE of Home Gardens, CA",
"rms": 0.27,
"sig": 24,
"sources": ",ci,",
"status": "automatic",
"time": 1488179250520,
"title": "M 1.2 - 5km NE of Home Gardens, CA",
"tsunami": 0,
"type": "earthquake",
"types": ",geoserve,nearby-cities,origin,phase-data,scitech-link,",
"tz": -480,
"updated": 1488179487273,
"url": "http://earthquake.usgs.gov/earthquakes/eventpage/ci37814000"
},
"type": "Feature"
}
quake1 = quake_from_feature(feature)
quake2 = Earthquake("5km NE of Home Gardens, CA", 1.24, -117.4906667, 33.9131667, 1488179250)
self.assertEqual(quake1, quake2)

def test_quake_from_feature2(self):
feature = {
"geometry": {
"coordinates": [
-117.4906667,
33.9131667,
0.25
],
"type": "Point"
},
"id": "ci37814000",
"properties": {
"code": "37814000",
"detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci37814000.geojson",
"dmin": 0.2836,
"gap": 87,
"ids": ",ci37814000,",
"mag": 1.24,
"magType": "ml",
"net": "ci",
"nst": 8,
"place": "5km NE of Home Gardens, CA",
"rms": 0.27,
"sig": 24,
"sources": ",ci,",
"status": "automatic",
"time": 1488179250520,
"title": "M 1.2 - 5km NE of Home Gardens, CA",
"tsunami": 0,
"type": "earthquake",
"types": ",geoserve,nearby-cities,origin,phase-data,scitech-link,",
"tz": -480,
"updated": 1488179487273,
"url": "http://earthquake.usgs.gov/earthquakes/eventpage/ci37814000"
},
"type": "Feature"
}
quake1 = quake_from_feature(feature)
quake2 = Earthquake("5km NE of Home Gardens, CA", 2.03, -117.4906667, 33.9131667, 1488179250)
self.assertNotEqual(quake1, quake2)

# Run the unit tests.
if __name__ == '__main__':
unittest.main()

2 changes: 2 additions & 0 deletions in0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
q

13 changes: 13 additions & 0 deletions in1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
s
m
f
p
ca
f
m
2
5
s
a
q

8 changes: 8 additions & 0 deletions in2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
f
m
2.1
5
s
m
q

12 changes: 12 additions & 0 deletions my_out0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Earthquakes:
------------
(1.05) 9km E of Running Springs, CA at 2017-02-27 00:51:05 (-117.008, 34.204)
(2.19) 5km S of Gilroy, California at 2017-02-26 21:32:18 (-121.580, 36.958)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice:
79 changes: 79 additions & 0 deletions my_out1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Earthquakes:
------------
(2.80) 12km W of Harper, Kansas at 2017-02-27 00:36:40 ( -98.161, 37.287)
(1.79) 7km WNW of The Geysers, California at 2017-02-28 11:16:03 (-122.837, 38.798)
(5.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)
(3.85) 6km SW of Valencia, CA at 2017-02-28 10:58:54 (-118.622, 34.426)
(1.00) 30km WSW of Salcha, Alaska at 2017-02-28 10:28:04 (-147.444, 64.378)
(2.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)
(5.00) 9km WNW of Laiwui, Indonesia at 2017-02-28 11:08:33 ( 127.592, -1.312)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice: Sort by (m)agnitude, (t)ime, (l)ongitude, or l(a)titude?
Earthquakes:
------------
(5.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)
(5.00) 9km WNW of Laiwui, Indonesia at 2017-02-28 11:08:33 ( 127.592, -1.312)
(3.85) 6km SW of Valencia, CA at 2017-02-28 10:58:54 (-118.622, 34.426)
(2.80) 12km W of Harper, Kansas at 2017-02-27 00:36:40 ( -98.161, 37.287)
(2.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)
(1.79) 7km WNW of The Geysers, California at 2017-02-28 11:16:03 (-122.837, 38.798)
(1.00) 30km WSW of Salcha, Alaska at 2017-02-28 10:28:04 (-147.444, 64.378)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice: Filter by (m)agnitude or (p)lace? Search for what string?
Earthquakes:
------------
(5.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)
(3.85) 6km SW of Valencia, CA at 2017-02-28 10:58:54 (-118.622, 34.426)
(2.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)
(1.79) 7km WNW of The Geysers, California at 2017-02-28 11:16:03 (-122.837, 38.798)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice: Filter by (m)agnitude or (p)lace? Lower bound: Upper bound:
Earthquakes:
------------
(5.00) 9km WNW of Laiwui, Indonesia at 2017-02-28 11:08:33 ( 127.592, -1.312)
(3.85) 6km SW of Valencia, CA at 2017-02-28 10:58:54 (-118.622, 34.426)
(2.80) 12km W of Harper, Kansas at 2017-02-27 00:36:40 ( -98.161, 37.287)
(2.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice: Sort by (m)agnitude, (t)ime, (l)ongitude, or l(a)titude?
Earthquakes:
------------
(5.00) 9km WNW of Laiwui, Indonesia at 2017-02-28 11:08:33 ( 127.592, -1.312)
(3.85) 6km SW of Valencia, CA at 2017-02-28 10:58:54 (-118.622, 34.426)
(5.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)
(2.06) 8km ENE of Coso Junction, CA at 2017-02-28 11:08:41 (-117.863, 36.078)
(2.80) 12km W of Harper, Kansas at 2017-02-27 00:36:40 ( -98.161, 37.287)
(1.79) 7km WNW of The Geysers, California at 2017-02-28 11:16:03 (-122.837, 38.798)
(1.00) 30km WSW of Salcha, Alaska at 2017-02-28 10:28:04 (-147.444, 64.378)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice:
43 changes: 43 additions & 0 deletions my_out2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Earthquakes:
------------
(1.05) 9km E of Running Springs, CA at 2017-02-27 00:51:05 (-117.008, 34.204)
(2.19) 5km S of Gilroy, California at 2017-02-26 21:32:18 (-121.580, 36.958)
(2.06) 6km SW of Volcano, Hawaii at 2017-02-27 10:55:59 (-155.280, 19.383)
(4.50) 122km SSE of Chignik Lake, Alaska at 2017-02-27 08:07:28 (-157.822, 55.289)
(2.80) 12km W of Harper, Kansas at 2017-02-27 00:36:40 ( -98.161, 37.287)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice: Filter by (m)agnitude or (p)lace? Lower bound: Upper bound:
Earthquakes:
------------
(2.19) 5km S of Gilroy, California at 2017-02-26 21:32:18 (-121.580, 36.958)
(4.50) 122km SSE of Chignik Lake, Alaska at 2017-02-27 08:07:28 (-157.822, 55.289)
(2.80) 12km W of Harper, Kansas at 2017-02-27 00:36:40 ( -98.161, 37.287)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice: Sort by (m)agnitude, (t)ime, (l)ongitude, or l(a)titude?
Earthquakes:
------------
(4.50) 122km SSE of Chignik Lake, Alaska at 2017-02-27 08:07:28 (-157.822, 55.289)
(2.80) 12km W of Harper, Kansas at 2017-02-27 00:36:40 ( -98.161, 37.287)
(2.19) 5km S of Gilroy, California at 2017-02-26 21:32:18 (-121.580, 36.958)
(2.06) 6km SW of Volcano, Hawaii at 2017-02-27 10:55:59 (-155.280, 19.383)
(1.05) 9km E of Running Springs, CA at 2017-02-27 00:51:05 (-117.008, 34.204)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice:
13 changes: 13 additions & 0 deletions out0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Earthquakes:
------------
(1.05) 9km E of Running Springs, CA at 2017-02-27 00:51:05 (-117.008, 34.204)
(2.19) 5km S of Gilroy, California at 2017-02-26 21:32:18 (-121.580, 36.958)

Options:
(s)ort
(f)ilter
(n)ew quakes
(q)uit

Choice:
Loading

0 comments on commit 88c3943

Please sign in to comment.