# source:branches/numpy/anuga/coordinate_transforms/test_point.py@6442

Last change on this file since 6442 was 6360, checked in by rwilson, 15 years ago

Ongoing conversion changes.

File size: 4.6 KB
Line
1
2import unittest
3from point import Point
4from math import fabs
5
6#-------------------------------------------------------------
7
8class TestCase(unittest.TestCase):
9
10    def setUp(self):
11
12        self.eps = 0.001    # Accept 0.1 % relative error
13
14        self.RSISE = Point(-35.27456,149.12065)
15        self.Home = Point(-35.25629,149.12494)     # 28 Scrivener Street, ACT
16        self.Syd = Point(-33.93479,151.16794)      # Sydney Airport
18        self.Kobenhavn = Point(55.70248, 12.58364) # Kobenhavn, Denmark
19
20
21    def testBearingNorth(self):
22
23        eps = 1.0e-12
24
25        p1 = Point(0.0,0.0)
26        p2 = Point(1.0,0.0)
27        p3 = Point(0.0,1.0)
28
29        # Assert that bearing is correct within double precision
30        self.failUnless((fabs(p1.BearingTo(p2)-0) < eps),\
31                        'Computed northward bearing: %d, Should have been: %d'\
32                         %(p1.BearingTo(p2), 0))
33
34
35    def testBearingSouth(self):
36
37        eps = 1.0e-12
38
39        p1 = Point(0.0,0.0)
40        p2 = Point(1.0,0.0)
41        p3 = Point(0.0,1.0)
42
43        # Assert that bearing is correct within double precision
44        self.failUnless((fabs(p2.BearingTo(p1)-180) < eps),\
45                        'Computed southhward bearing: %d, Should have been: %d'\
46                         %(p2.BearingTo(p1), 180))
47
48
49    def testBearingWest(self):
50
51        eps = 1.0e-12
52
53        p1 = Point(0.0,0.0)
54        p2 = Point(1.0,0.0)
55        p3 = Point(0.0,1.0)
56
57        # Assert that bearing is correct within double precision
58        self.failUnless((fabs(p3.BearingTo(p1)-270) < eps),\
59                        'Computed westward bearing: %d, Should have been: %d'\
60                         %(p3.BearingTo(p1), 270))
61
62    def testBearingEast(self):
63
64        eps = 1.0e-12
65
66        p1 = Point(0.0,0.0)
67        p2 = Point(1.0,0.0)
68        p3 = Point(0.0,1.0)
69
70        # Assert that bearing is correct within double precision
71        self.failUnless((fabs(p1.BearingTo(p3)-90) < eps),\
72                        'Computed eastward bearing: %d, Should have been: %d'\
73                         %(p1.BearingTo(p3), 90))
74
75
76
77    def testRSISE2Home(self):
78        D = 2068   # True Distance to Home
79        B = 11     # True Bearing to Home
80        self.failUnless((fabs(self.RSISE.DistanceTo(self.Home) - D)/D < self.eps),\
81                        'Dist to Home failed')
82        self.failUnless((self.RSISE.BearingTo(self.Home) - B == 0),\
83                        'Computed bearing to Home: %d, Should have been: %d'\
84                         %(self.RSISE.BearingTo(self.Home), B))
85
86
87
88    def testRSISE2Sydney(self):
89        D = 239.5 * 1000   # True Distance to Sydney Airport
90        B = 52             # True Bearing to Sydney Airport
91        self.failUnless((fabs(self.RSISE.DistanceTo(self.Syd) - D)/D < self.eps),\
92                        'Dist to Sydney failed')
93        self.failUnless((self.RSISE.BearingTo(self.Syd) - B == 0),\
94                        'Computed bearing to Sydney: %d, Should have been: %d'\
95                         %(self.RSISE.BearingTo(self.Syd), B))
96
97
99        D = 3406.1 * 1000   # True Distance to Nadi Airport
100        B = 63              # True Bearing to Nadi Airport
101        self.failUnless((fabs(self.RSISE.DistanceTo(self.Nadi) - D)/D < self.eps),\
103
104        self.failUnless((self.RSISE.BearingTo(self.Nadi) - B == 0),\
105                        'Computed bearing to Nadi: %d, Should have been: %d'\
107
108
109    def testRSISE2Kobenhavn(self):
110        D = 16025 * 1000   # True Distance to Kobenhavn
111        B = 319            # True Bearing to Kobenhavn
112        self.failUnless((fabs(self.RSISE.DistanceTo(self.Kobenhavn) - D)/D < self.eps),\
113                        'Computed Distance to Kobenhavn: %d, Should have been: %d' \
114                        %(self.RSISE.DistanceTo(self.Kobenhavn), D))
115        self.failUnless((self.RSISE.BearingTo(self.Kobenhavn) - B == 0),\
116                        'Computed Bearing to Kobenhavn: %d, Should have been: %d' \
117                        %(self.RSISE.BearingTo(self.Kobenhavn), B))
118
119#-------------------------------------------------------------
120
121if __name__ == "__main__":
122    mysuite = unittest.makeSuite(TestCase,'test')
123    runner = unittest.TextTestRunner()
124    runner.run(mysuite)
125
Note: See TracBrowser for help on using the repository browser.