Exemplo n.º 1
0
 def clear_test(self):
     """Test if the clear() methods of the Way class works correctly."""
     # put some regular points to the way first
     first = (0.0, 0.0, 0.0)
     second = (1.0, 1.0, 100.0)
     third = (2.0, 2.0, 200.0)
     lle_list = [first, second, third]
     way = Way(points=lle_list)
     # add some message points
     point1 = Point(lat=50.0, lon=50.0, elevation=300.0, message="foo")
     point2 = Point(lat=75.0, lon=75.0, elevation=600.0, message="bar")
     way.add_message_point(point1)
     way.add_message_point(point2)
     # check there are points & message points
     self.assertEqual(way.point_count, 3)
     self.assertEqual(way.message_point_count, 2)
     self.assertTrue(len(way.points_lle) > 0)
     self.assertTrue(len(way.message_points) > 0)
     self.assertTrue(len(way.message_points_lle) > 0)
     # call the clear methods
     way.clear()
     way.clear_message_points()
     # check that the way is empty
     self.assertEqual(way.point_count, 0)
     self.assertEqual(way.message_point_count, 0)
     self.assertListEqual(way.points_lle, [])
     self.assertListEqual(way.message_points, [])
     self.assertListEqual(way.message_points_lle, [])
Exemplo n.º 2
0
 def basic_message_points_test(self):
     """Test using Way with message points."""
     # put some regular points to the way first
     first = (0.0, 0.0, 0.0)
     second = (1.0, 1.0, 100.0)
     third = (2.0, 2.0, 200.0)
     lle_list = [first, second, third]
     way = Way(points=lle_list)
     # add some message points
     point1 = Point(lat=50.0, lon=50.0, elevation=300.0, message="foo")
     point2 = Point(lat=75.0, lon=75.0, elevation=600.0, message="bar")
     point3 = Point(lat=100.0, lon=100.0, elevation=1200.0, message="baz")
     point4 = Point(lat=125.0, lon=125.0, elevation=2400.0, message="abc")
     point5 = Point(lat=150.0, lon=150.0, elevation=4800.0, message="def")
     way.add_message_point(point1)
     way.add_message_point(point2)
     self.assertEqual(way.message_point_count, 2)
     self.assertListEqual(way.message_points, [point1, point2])
     expected_list1 = [(50.0, 50.0, 300.0), (75.0, 75.0, 600.0)]
     self.assertListEqual(way.message_points_lle, expected_list1)
     way.add_message_points([point3, point4, point5])
     expected_list2 = expected_list1.copy()
     expected_list2.extend([(100.0, 100.0, 1200.0), (125.0, 125.0, 2400.0),
                            (150.0, 150.0, 4800.0)])
     self.assertEqual(way.message_point_count, 5)
     self.assertListEqual(way.message_points,
                          [point1, point2, point3, point4, point5])
     self.assertListEqual(way.message_points_lle, expected_list2)
     # check getters
     self.assertTrue(
         self._compare_points(way.get_message_point_by_index(2), point3))
     self.assertTrue(
         self._compare_points(way.get_message_point_by_index(-1), point5))
     # get message point index
     # - note that this takes into account the point instance,
     #   so two points with the same content will not be considered the same
     # - it's a question if this a correct behavior or not :)
     self.assertEqual(way.get_message_point_index(point1), 0)
     self.assertEqual(way.get_message_point_index(point3), 2)
     foo_point = Point(lat=50.0, lon=50.0, elevation=300, message="foo")
     # foo_point has the same content as point1 but will be considered different
     self.assertIsNone(way.get_message_point_index(foo_point))
     # same thing for stuff that's not points
     self.assertIsNone(way.get_message_point_index(None))
     self.assertIsNone(way.get_message_point_index(1))
     self.assertIsNone(way.get_message_point_index(True))
     self.assertIsNone(way.get_message_point_index("bar"))
     self.assertIsNone(way.get_message_point_index([]))
Exemplo n.º 3
0
 def get_closest_point_test(self):
     """Test the get-closest-point functions of the Way class."""
     # put some regular points to the way first
     first = (0.0, 0.0, 0.0)
     second = (1.0, 0.0, 100.0)
     third = (2.0, 0.0, 200.0)
     lle_list = [first, second, third]
     way = Way(points=lle_list)
     # add some message points
     point1 = Point(lat=50.0, lon=0.0, elevation=300.0, message="foo")
     point2 = Point(lat=75.0, lon=0.0, elevation=600.0, message="bar")
     way.add_message_point(point1)
     way.add_message_point(point2)
     # get closest point
     result = way.get_closest_point(Point(lat=2.5, lon=0.0))
     self.assertEqual(result.getLLE(), third)
     # get closest message point
     result = way.get_closest_message_point(Point(lat=76.0, lon=0.0))
     self.assertEqual(result, point2)