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([]))
def set_message_point_test(self): """Test replacing message points already added to a Way.""" way = Way() # 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") way.add_message_points([point1, point2, point3]) self.assertEqual(way.get_message_point_by_index(0), point1) self.assertEqual(way.get_message_point_by_index(2), point3) # replace some of the points point11 = Point(lat=51.0, lon=51.0, elevation=301.0, message="foo1") point31 = Point(lat=101.0, lon=101.0, elevation=1201.0, message="baz1") way.set_message_point_by_index(0, point11) way.set_message_point_by_index(2, point31) # check the points have been replaced self.assertEqual(way.get_message_point_by_index(0), point11) self.assertEqual(way.get_message_point_by_index(2), point31) # some sanity checks self.assertEqual(way.message_point_count, 3) self.assertListEqual(way.message_points, [point11, point2, point31]) self.assertListEqual( way.message_points_lle, [point11.getLLE(), point2.getLLE(), point31.getLLE()]) lol_point = Point(lat=50.0, lon=50.0, elevation=300, message="lol") with self.assertRaises(IndexError): way.set_message_point_by_index(3, lol_point) with self.assertRaises(IndexError): way.set_message_point_by_index(-100, lol_point) with self.assertRaises(IndexError): way.set_message_point_by_index(100, lol_point)