forked from selabhvl/ing301public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_gpscomputer.py
68 lines (44 loc) · 2.39 KB
/
test_gpscomputer.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
import unittest
import gpscomputer
class TestComputerMethods(unittest.TestCase):
ACCURACY = 0.5
def setUp(self):
self.gps_data = [
(28800, 60.376988, 5.227082, 10),
(28810, 60.385390, 5.217217, 20),
(28840, 60.379527, 5.3227322, 10),
(28870, 60.385390, 5.217217, 40),
(28880, 60.376988, 5.227082, 50)]
def test_total_distance(self):
EXP_TOTALDISTANCE = 1080 + 5835 + 5835 + 1080
self.assertAlmostEqual(gpscomputer.total_distance(self.gps_data), EXP_TOTALDISTANCE, delta=self.ACCURACY)
def test_total_elevation(self):
EXP_TOTALELEVATION = 10 + 30 + 10
self.assertAlmostEqual(gpscomputer.total_elevation(self.gps_data), EXP_TOTALELEVATION, delta=self.ACCURACY)
def total_time(self):
EXP_TOTALTIME = 1 * 60 + 20
self.assertAlmostEqual(gpscomputer.total_time(self.gps_data), EXP_TOTALTIME, delta=self.ACCURACY)
def test_segment_speeds(self):
EXP_SPEEDS = [(108.0 * 60 * 60) / 1000, (194.5 * 60 * 60) / 1000, (194.5 * 60 * 60) / 1000,
(108.0 * 60 * 60) / 1000]
speeds = gpscomputer.segment_speeds(self.gps_data)
self.assertEqual(len(speeds), len(EXP_SPEEDS))
for i in range(1, len(EXP_SPEEDS)):
self.assertAlmostEqual(speeds[i], EXP_SPEEDS[i], delta=self.ACCURACY)
def test_max_speed(self):
EXP_MAXSPEED = (194.5 * 60 * 60 / 1000)
self.assertAlmostEqual(gpscomputer.max_speed(self.gps_data), EXP_MAXSPEED, delta=self.ACCURACY)
def test_average_speed(self):
EXP_TOTALDISTANCE = 1080 + 5835 + 5835 + 1080
EXP_TOTALTIME = 1 * 60 + 20
EXP_AVERAGESPEED = ((EXP_TOTALDISTANCE / EXP_TOTALTIME) * 60 * 60) / 1000
self.assertAlmostEqual(gpscomputer.average_speed(self.gps_data), EXP_AVERAGESPEED, delta=self.ACCURACY)
def test_kcal(self):
MS = 2.236936
self.assertAlmostEqual(gpscomputer.kcal(1.0, 1, 13.0 / MS), 8.0 / 3600.0, delta=self.ACCURACY)
self.assertAlmostEqual(gpscomputer.kcal(2.0, 1, 13.0 / MS), 2 * 8.0 / 3600.0, delta=self.ACCURACY)
self.assertAlmostEqual(gpscomputer.kcal(3.0, 2, 13.0 / MS), 3 * 2 * 8.0 / 3600.0, delta=self.ACCURACY)
def test_total_energy(self):
self.assertAlmostEqual(gpscomputer.total_energy(self.gps_data, 80.0), 24.88, delta=self.ACCURACY)
if __name__ == '__main__':
unittest.main()