def test_three_close(self): rt = [PointXyz(0, 0, 0), PointXyz(10, 0, 0), PointXyz(20, 0, 0)] routeutils.remove_close_points(rt, 100) self.assertEqual(2, len(rt)) self.assertEqual(PointXyz(0, 0, 0), rt[0]) self.assertEqual(PointXyz(20, 0, 0), rt[1])
def test_multiple_points(self): self.assertEqual( 20, routeutils.get_length( [PointXyz(0, 0, 0), PointXyz(10, 0, 0), PointXyz(20, 0, 0)]))
def test_wrong_point_id(self): rt0: PointXyzList = [PointXyz(0, 0, 0)] candidates = [RouteCandidateInfo(rt0[0], 1, 0)] self.assertRaises(Exception, routeutils.remove_not_same_direction, PointXyz(0.1, 0, 0), PointXyz(1.1, 0, 0), candidates, [rt0], 20)
def test_close_to_begin(self): rt = [ PointXyz(1, 0, 0), PointXyz(8, 0, 0), PointXyz(9, 0, 0), PointXyz(10, 0, 0) ] self.assertEqual(1, routeutils.get_mid_point_index(rt, 0, 3))
def test_close_to_end(self): rt = [ PointXyz(1, 0, 0), PointXyz(2, 0, 0), PointXyz(3, 0, 0), PointXyz(10, 0, 0) ] self.assertEqual(2, routeutils.get_mid_point_index(rt, 0, 3))
def test_one_mid(self): rt = [ PointXyz(1, 0, 0), PointXyz(2, 0, 0), PointXyz(3, 0, 0), PointXyz(10, 0, 0) ] self.assertEqual(2, routeutils.get_mid_point_index(rt, 1, 3))
def test_get_within_distance(self): locator = RouteCandidateInfoLocator(100) locator.put(RouteCandidateInfo(PointXyz(11, 11, 0), 0, 0)) locator.put(RouteCandidateInfo(PointXyz(12, 12, 0), 1, 1)) res = locator.get(PointXyz(13, 12, 0), 1) self.assertEqual(1, len(res)) self.assertEqual(PointXyz(12, 12, 0), res[0].point) self.assertEqual(1, res[0].point_id) self.assertEqual(1, res[0].route_id)
def test_wrong_or_close_indices(self): rt = [ PointXyz(1, 0, 0), PointXyz(2, 0, 0), PointXyz(3, 0, 0), PointXyz(10, 0, 0) ] self.assertRaises(Exception, routeutils.get_mid_point_index, rt, 5, 2) self.assertRaises(Exception, routeutils.get_mid_point_index, rt, -1, 2) self.assertRaises(Exception, routeutils.get_mid_point_index, rt, -2, -1) self.assertIsNone(routeutils.get_mid_point_index(rt, 1, 2)) self.assertIsNone(routeutils.get_mid_point_index(rt, 1, 1))
def test_many_mid(self): rt = [ PointXyz(0, 0, 0), PointXyz(30, 0, 0), PointXyz(40, 0, 0), PointXyz(50, 0, 0), PointXyz(100, 0, 0) ] routeutils.remove_close_points(rt, 25) self.assertEqual(4, len(rt)) self.assertEqual(PointXyz(0, 0, 0), rt[0]) self.assertEqual(PointXyz(30, 0, 0), rt[1]) self.assertEqual(PointXyz(50, 0, 0), rt[2]) self.assertEqual(PointXyz(100, 0, 0), rt[3])
def test_three_close_end(self): rt = [PointXyz(0, 0, 0), PointXyz(90, 0, 0), PointXyz(100, 0, 0)] routeutils.remove_close_points(rt, 20) self.assertEqual(3, len(rt)) self.assertEqual(PointXyz(0, 0, 0), rt[0]) self.assertEqual(PointXyz(90, 0, 0), rt[1]) self.assertEqual(PointXyz(100, 0, 0), rt[2])
def test_many_in_mid(self): rt = [ PointXyz(1, 0, 0), PointXyz(2, 0, 0), PointXyz(3, 0, 0), PointXyz(4, 0, 0), PointXyz(8, 0, 0), PointXyz(9, 0, 0), PointXyz(10, 0, 0) ] self.assertEqual(3, routeutils.get_mid_point_index(rt, 0, 6))
def test_all_wrong_direction(self): rt0: PointXyzList = [ PointXyz(0, 0, 0), PointXyz(1, 0, 0), PointXyz(2, 0, 0), PointXyz(3, 0, 0) ] rt1: PointXyzList = [ PointXyz(0, 0, 0), PointXyz(1, 1, 0), PointXyz(2, 2, 0), PointXyz(3, 3, 0) ] candidates = [ RouteCandidateInfo(rt0[0], 1, 0), RouteCandidateInfo(rt1[0], 1, 1) ] routeutils.remove_not_same_direction(PointXyz(2, 1, 0), PointXyz(1.1, 2, 0), candidates, [rt0, rt1], 20) self.assertEqual(0, len(candidates))
def test_two_points_between_first_kept(self): rt = [ PointXyz(0, 0, 0), PointXyz(20, 0, 0), PointXyz(22, 0, 0), PointXyz(30, 0, 0) ] routeutils.remove_close_points(rt, 25) self.assertEqual(3, len(rt)) self.assertEqual(PointXyz(0, 0, 0), rt[0]) self.assertEqual(PointXyz(20, 0, 0), rt[1]) self.assertEqual(PointXyz(30, 0, 0), rt[2])
def test_all_removed(self): rt0: PointXyzList = [ PointXyz(0, 0, 0), PointXyz(1, 0, 0), PointXyz(2, 0, 0), PointXyz(30, 0, 0) ] rt1: PointXyzList = [ PointXyz(0.1, 0, 0), PointXyz(1.1, 0.1, 0), PointXyz(3.1, 0.2, 0), PointXyz(40.1, 0.3, 0) ] candidates = [ RouteCandidateInfo(rt0[1], 1, 0), RouteCandidateInfo(rt1[1], 1, 1) ] routeutils.advance_candidates(PointXyz(10, 0, 0), candidates, [rt0, rt1], 0.6) self.assertEqual(0, len(candidates))
def test_no_candidates(self): candidates = [] routeutils.advance_candidates(PointXyz(1, 0, 0), candidates, [], 1) self.assertEqual(0, len(candidates))
def test_one(self): rt = [PointXyz(0, 0, 0)] routeutils.remove_close_points(rt, 10) self.assertEqual(1, len(rt)) self.assertEqual(PointXyz(0, 0, 0), rt[0])
def test_one(self): self.assertEqual(1, len(routeutils.split_by_time([PointXyz(0, 0, 0)], 5)))
def test_wrong_point_id(self): rt0: PointXyzList = [PointXyz(0, 0, 0)] candidates = [RouteCandidateInfo(rt0[0], 1, 0)] self.assertRaises(Exception, routeutils.advance_candidates, PointXyz(1.1, 0, 0), candidates, [rt0], 1)
def test_no_candidates(self): candidates = [] routeutils.remove_not_same_direction(PointXyz(0, 0, 0), PointXyz(1, 0, 0), candidates, [], 10) self.assertEqual(0, len(candidates))