forked from scisco/area
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
60 lines (44 loc) · 1.58 KB
/
test.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
import json
import unittest
from area import area
f = open('illinois.json', 'U')
illinois = json.loads(f.read())
world = {
'type': 'Polygon',
'coordinates': [
[
[-180, -90],
[-180, 90],
[180, 90],
[180, -90],
[-180, -90]
]
]
}
illinois_area = 145978332359.36746
world_area = 511207893395811.06
class AreaTestCase(unittest.TestCase):
def test_area_illinois_with_string(self):
""" Computer the area of illinois with string input """
# Go the top of the file
f.seek(0)
illinois = f.read()
self.assertEqual(round(area(illinois), 2), round(illinois_area, 2))
def test_area_illinois(self):
""" Compute the area of illinois """
self.assertEqual(round(area(illinois), 2), round(illinois_area, 2))
def test_area_world(self):
""" Compute the area of the whole world """
self.assertEqual(area(world), world_area)
def test_point_area(self):
""" Compute the area of a point """
self.assertEqual(area({'type': 'Point', 'coordinates': [0, 0]}), 0)
def test_liststring_area(self):
""" Compute the area of a line string """
self.assertEqual(area({'type': 'LineString', 'coordinates': [[0, 0], [1, 1]]}), 0)
def test_geometry_collection_area(self):
""" Compute the area of a geometry collection """
total = illinois_area + world_area
self.assertEqual(area({'type': 'GeometryCollection', 'geometries': [world, illinois]}), total)
if __name__ == '__main__':
unittest.main()