Package sabx10 :: Package oxm :: Module geom_test
[hide private]
[frames] | no frames]

Source Code for Module sabx10.oxm.geom_test

  1  #! /usr/bin/python 
  2  ############################################################################### 
  3  # 
  4  # sabx10.oxm - an SABX file manipulation library 
  5  # Copyright (C) 2009, 2010 Jay Farrimond (jay@sabikerides.com) 
  6  # 
  7  # This file is part of sabx10.oxm. 
  8  # 
  9  # sabx10.oxm is free software: you can redistribute it and/or modify it under 
 10  # the terms of the GNU Lesser General Public License as published by the Free 
 11  # Software Foundation, either version 3 of the License, or (at your option) any 
 12  # later version. 
 13  # 
 14  # sabx10.oxm is distributed in the hope that it will be useful, but WITHOUT ANY 
 15  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
 16  # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
 17  # details. 
 18  # 
 19  # You should have received a copy of the GNU Lesser General Public License 
 20  # along with sabx10.oxm.  If not, see <http://www.gnu.org/licenses/>. 
 21  # 
 22  ############################################################################### 
 23   
 24  import unittest 
 25   
 26  from geom import * 
 27  from utils import meter_feet 
 28   
29 -class TestGeomPoint(unittest.TestCase):
30
31 - def test_create_blank(self):
32 test_pt = Point() 33 self.assertEquals(test_pt.lat, 0.0) 34 self.assertEquals(test_pt.lon, 0.0) 35 self.assertEquals(test_pt.ele, None) 36 self.assertEquals(test_pt.usgs, None) 37 self.assertEquals(test_pt.id, None)
38
39 - def test_create_populated(self):
40 test_pt = Point(10.10, 11.11, 100.1, 200.2, '10') 41 self.assertEquals(test_pt.lat, 10.10) 42 self.assertEquals(test_pt.lon, 11.11) 43 self.assertEquals(test_pt.ele, 100.1) 44 self.assertEquals(test_pt.usgs, 200.2) 45 self.assertEquals(test_pt.id, '10')
46
47 - def test_dist_self(self):
48 test_pt = Point() 49 self.assertEquals(test_pt.calculate_distance(test_pt), 0.0)
50
51 -class TestGeomLine(unittest.TestCase):
52
53 - def setUp(self):
54 points = [ 55 Point(29.738246, -98.103823, 213.6, 206.44480896, '6'), 56 Point(29.738285, -98.103958, 213.1, 206.279098511, '7'), 57 Point(29.738286, -98.103996, 212.6, 206.126815796, '8'), 58 Point(29.738416, -98.10415, 212.1, 205.945068359, '9') 59 ] 60 self.line = Line(points)
61
62 - def test_calc_length(self):
63 self.assertAlmostEqual(self.line.calc_length(), 0.023686084161068356)
64
65 - def test_find_lowest_highest(self):
66 lowest, highest = self.line.find_lowest_highest() 67 self.assertEquals(lowest, 212.1 * meter_feet) 68 self.assertEquals(highest, 213.6 * meter_feet)
69
70 -class TestGeomBox(unittest.TestCase):
71
72 - def setUp(self):
73 self.test_box = Box(10.0, 20.0, 30.0, 40.0)
74
75 - def test_create_blank(self):
76 blank_box = Box() 77 self.assertEquals(blank_box.min_lat, 200.0) 78 self.assertEquals(blank_box.min_lon, 200.0) 79 self.assertEquals(blank_box.max_lat, -200.0) 80 self.assertEquals(blank_box.max_lon, -200.0)
81
82 - def test_create_populated(self):
83 self.assertEquals(self.test_box.min_lat, 10.0) 84 self.assertEquals(self.test_box.min_lon, 20.0) 85 self.assertEquals(self.test_box.max_lat, 30.0) 86 self.assertEquals(self.test_box.max_lon, 40.0)
87
88 - def test_is_pt_in_box_yes(self):
89 self.assert_(self.test_box.is_pt_in_box(20.0, 30.0))
90
91 - def test_is_pt_in_box_no(self):
92 self.assertFalse(self.test_box.is_pt_in_box(5.0, 10.0))
93
94 - def test_resize(self):
95 self.test_box.resize(1.0, 1.0) 96 self.assertAlmostEqual(self.test_box.width(), 1.0, 3) 97 self.assertAlmostEqual(self.test_box.height(), 1.0, 3)
98
99 - def test_expand_to_point_in(self):
100 self.test_box.expand_to_point(20.0, 30.0) 101 self.assertEquals(self.test_box.min_lat, 10.0) 102 self.assertEquals(self.test_box.min_lon, 20.0) 103 self.assertEquals(self.test_box.max_lat, 30.0) 104 self.assertEquals(self.test_box.max_lon, 40.0)
105
106 - def test_expand_to_point_out(self):
107 self.test_box.expand_to_point(5.0, 5.0) 108 self.assertEquals(self.test_box.min_lat, 5.0) 109 self.assertEquals(self.test_box.min_lon, 5.0) 110 self.assertEquals(self.test_box.max_lat, 30.0) 111 self.assertEquals(self.test_box.max_lon, 40.0)
112
113 - def test_expand_to_box_in(self):
114 new_box = Box(11.0, 21.0, 29.0, 39.0) 115 self.test_box.expand_to_box(new_box) 116 self.assertEquals(self.test_box.min_lat, 10.0) 117 self.assertEquals(self.test_box.min_lon, 20.0) 118 self.assertEquals(self.test_box.max_lat, 30.0) 119 self.assertEquals(self.test_box.max_lon, 40.0)
120
122 new_box = Box(5.0, 15.0, 30.0, 40.0) 123 self.test_box.expand_to_box(new_box) 124 self.assertEquals(self.test_box.min_lat, 5.0) 125 self.assertEquals(self.test_box.min_lon, 15.0) 126 self.assertEquals(self.test_box.max_lat, 30.0) 127 self.assertEquals(self.test_box.max_lon, 40.0)
128
130 new_box = Box(9.0, 19.0, 31.0, 41.0) 131 self.test_box.expand_to_box(new_box) 132 self.assertEquals(self.test_box.min_lat, 9.0) 133 self.assertEquals(self.test_box.min_lon, 19.0) 134 self.assertEquals(self.test_box.max_lat, 31.0) 135 self.assertEquals(self.test_box.max_lon, 41.0)
136 137 if __name__ == "__main__": 138 unittest.main() 139