forked from tkrajina/srtm.py
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
Latest commit
executable file
·144 lines (113 loc) · 6.07 KB
/
Copy pathtest.py
File metadata and controls
executable file
·144 lines (113 loc) · 6.07 KB
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
141
142
143
144
# -*- coding: utf-8 -*-
# Copyright 2013 Tomo Krajina
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Run all tests with:
$ python -m unittest test
"""
importpdb
importloggingasmod_logging
importunittestasmod_unittest
importsrtmasmod_srtm
mod_logging.basicConfig(level=mod_logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
classTests(mod_unittest.TestCase):
deftest_random_points(self):
geo_elevation_data=mod_srtm.get_data()
self.assertEqual(63, geo_elevation_data.get_elevation(46., 13.))
self.assertEqual(2714, geo_elevation_data.get_elevation(46.999999, 13.))
self.assertEqual(1643, geo_elevation_data.get_elevation(46.999999, 13.999999))
self.assertEqual(553, geo_elevation_data.get_elevation(46., 13.999999))
self.assertEqual(203, geo_elevation_data.get_elevation(45.2732, 13.7139))
self.assertEqual(460, geo_elevation_data.get_elevation(45.287, 13.905))
deftest_around_zero_longitude(self):
geo_elevation_data=mod_srtm.get_data()
self.assertEqual(61, geo_elevation_data.get_elevation(51.2, 0.0))
self.assertEqual(100, geo_elevation_data.get_elevation(51.2, -0.1))
self.assertEqual(59, geo_elevation_data.get_elevation(51.2, 0.1))
deftest_around_zero_latitude(self):
geo_elevation_data=mod_srtm.get_data()
self.assertEqual(393, geo_elevation_data.get_elevation(0, 15))
self.assertEqual(423, geo_elevation_data.get_elevation(-0.1, 15))
self.assertEqual(381, geo_elevation_data.get_elevation(0.1, 15))
deftest_point_with_invalid_elevation(self):
geo_elevation_data=mod_srtm.get_data()
self.assertEqual(None, geo_elevation_data.get_elevation(47.0, 13.07))
deftest_point_without_file(self):
geo_elevation_data=mod_srtm.get_data()
print((geo_elevation_data.get_elevation(0, 0)))
deftest_files_equality(self):
geo_elevation_data=mod_srtm.get_data()
self.assertEqual(geo_elevation_data.get_file(47.0, 13.99),
geo_elevation_data.get_file(47.0, 13.0))
self.assertEqual(geo_elevation_data.get_file(47.99, 13.99),
geo_elevation_data.get_file(47.0, 13.0))
self.assertEqual(geo_elevation_data.get_file(-47.0, 13.99),
geo_elevation_data.get_file(-47.0, 13.0))
self.assertEqual(geo_elevation_data.get_file(-47.99, 13.99),
geo_elevation_data.get_file(-47.0, 13.0))
self.assertEqual(geo_elevation_data.get_file(-47.0, -13.99),
geo_elevation_data.get_file(-47.0, -13.0))
self.assertEqual(geo_elevation_data.get_file(-47.99, -13.99),
geo_elevation_data.get_file(-47.0, -13.0))
self.assertEqual(geo_elevation_data.get_file(47.0, -13.99),
geo_elevation_data.get_file(47.0, -13.0))
self.assertEqual(geo_elevation_data.get_file(47.99, -13.99),
geo_elevation_data.get_file(47.0, -13.0))
deftest_invalit_coordinates_for_file(self):
geo_elevation_data=mod_srtm.get_data()
geo_file=geo_elevation_data.get_file(47.0, 13.99)
try:
self.assertFalse(geo_file.get_elevation(1, 1))
exceptExceptionase:
message=str(e)
self.assertEqual('Invalid latitude 1 for file N47E013.hgt', message)
try:
self.assertFalse(geo_file.get_elevation(47, 1))
exceptExceptionase:
message=str(e)
self.assertEqual('Invalid longitude 1 for file N47E013.hgt', message)
deftest_invalid_file(self):
geo_elevation_data=mod_srtm.get_data()
geo_file=geo_elevation_data.get_file(-47.0, -13.99)
self.assertEqual(None, geo_file)
deftest_coordinates_in_file(self):
geo_elevation_data=mod_srtm.get_data()
geo_file=geo_elevation_data.get_file(47.0, 13.99)
print(('file:', geo_file))
self.assertEqual(geo_file.get_elevation(47, 13),
geo_file.get_elevation(47, 13))
deftest_without_approximation(self):
geo_elevation_data=mod_srtm.get_data()
self.assertEqual(geo_elevation_data.get_elevation(47.1, 13.1, approximate=False),
geo_elevation_data.get_elevation(47.1, 13.1))
# SRTM elevations are always integers:
elevation=geo_elevation_data.get_elevation(47.1, 13.1)
self.assertTrue(int(elevation) ==elevation)
deftest_with_approximation(self):
geo_elevation_data=mod_srtm.get_data()
self.assertNotEqual(geo_elevation_data.get_elevation(47.1, 13.1, approximate=True),
geo_elevation_data.get_elevation(47.1, 13.1))
# When approximating a random point, it probably won't be a integer:
elevation=geo_elevation_data.get_elevation(47.1, 13.1, approximate=True)
self.assertTrue(int(elevation) !=elevation)
deftest_approximation(self):
# TODO(TK) Better tests for approximation here:
geo_elevation_data=mod_srtm.get_data()
elevation_without_approximation=geo_elevation_data.get_elevation(47, 13)
elevation_with_approximation=geo_elevation_data.get_elevation(47, 13, approximate=True)
print(elevation_without_approximation)
print(elevation_with_approximation)
self.assertNotEqual(elevation_with_approximation, elevation_without_approximation)
self.assertTrue(abs(elevation_with_approximation-elevation_without_approximation) <30)