forked from python-metar/python-metar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_speed.py
54 lines (44 loc) · 2.4 KB
/
test_speed.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
import unittest
from metar.Datatypes import speed, UnitsError
class SpeedTest(unittest.TestCase):
def testDefaults(self):
self.assertEqual( speed("10").value(), 10.0 )
self.assertEqual( speed("5").string(), "5 mps" )
self.assertEqual( speed("10", "KT").value(), 10.0 )
self.assertEqual( speed("5", "KT").string(), "5 knots" )
self.assertEqual( speed("5", "KMH").string(), "5 km/h" )
self.assertEqual( speed("5", "MPH").string(), "5 mph" )
self.assertEqual( speed("5",None).string(), "5 mps" )
def testInputs(self):
self.assertEqual( speed("10").value(), 10.0 )
self.assertEqual( speed(10).value(), 10.0 )
self.assertEqual( speed(10.0).value(), 10.0 )
self.assertEqual( speed(10.0, None).value(), 10.0 )
self.assertEqual( speed("10", gtlt=">").value(), 10.0 )
self.assertEqual( speed("10", None, "<").value(), 10.0 )
def testErrorChecking(self):
self.assertRaises( ValueError, speed, "10KT" )
self.assertRaises( ValueError, speed, "10", "MPS", "=" )
self.assertRaises( ValueError, speed, "60", "KT", "gt" )
self.assertRaises( UnitsError, speed, "10", "NM" )
self.assertRaises( UnitsError, speed("10").value, "furlongs per fortnight" )
self.assertRaises( UnitsError, speed("5").string, "fps" )
def testConversions(self):
self.assertEqual( speed("10", "MPS").value("MPS"), 10.0 )
self.assertEqual( speed("10", "MPS").value("KMH"), 36.0 )
self.assertAlmostEqual( speed("10", "MPS").value("MPH"), 22.4, 1 )
self.assertAlmostEqual( speed("10", "MPS").value("KT"), 19.4, 1 )
self.assertEqual( speed("10", "KT").value("KT"), 10.0 )
self.assertAlmostEqual( speed("10", "KT").value("MPH"), 11.5, 1 )
self.assertAlmostEqual( speed("10", "KT").value("MPS"), 5.1, 1 )
self.assertAlmostEqual( speed("10", "KT").value("KMH"), 18.5, 1 )
self.assertEqual( speed("10", "MPH").value("MPH"), 10.0 )
self.assertAlmostEqual( speed("10", "MPH").value("KT"), 8.7, 1 )
self.assertAlmostEqual( speed("10", "MPH").value("MPS"), 4.5, 1 )
self.assertAlmostEqual( speed("10", "MPH").value("KMH"), 16.1, 1 )
self.assertEqual( speed("10", "KMH").value("KMH"), 10.0 )
self.assertAlmostEqual( speed("10", "KMH").value("KT"), 5.4, 1 )
self.assertAlmostEqual( speed("10", "KMH").value("MPS"), 2.8, 1 )
self.assertAlmostEqual( speed("10", "KMH").value("MPH"), 6.2, 1 )
if __name__=='__main__':
unittest.main()