Example #1
0
    def test_previous_leg(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "N")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)
        bearing = CompassBearing(190)
        leg = Leg(sdt, waypoint, bearing)
        leg2 = Leg(sdt, waypoint, bearing)
        legs = [leg, leg2]
        route = Route(legs)

        self.assertIsInstance(route, Route)
        self.assertEqual(route.previous_leg(1), leg)
Example #2
0
    def test_end_waypoint_exists(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "N")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)
        waypoint2 = Waypoint(latitude, longitude)
        bearing = CompassBearing(190)
        leg = Leg(sdt, waypoint, bearing)
        leg2 = Leg(sdt, waypoint2, bearing)
        legs = [leg, leg2]
        route = Route(legs)

        self.assertIsInstance(route.end_waypoint, Waypoint)
        self.assertEqual(str(route.end_waypoint), str(leg2.end_waypoint))
Example #3
0
 def test_leg_fails_to_initailise_without_valid_bearing(self):
     distance = Distance(10)
     time = Time(20)
     sdt = SpeedDistanceTime(distance=distance, time=time)
     waypoint = (10.123456, 2.324567)
     bearing = 190
     with self.assertRaises(TypeError):
         Leg(sdt, waypoint, bearing)
Example #4
0
    def test_leg_fails_to_initailise_without_bearing(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "S")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)

        with self.assertRaises(ValueError):
            Leg(sdt, waypoint)
Example #5
0
    def test_route_is_intialised_with_legs(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "N")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)
        bearing = CompassBearing(190)
        leg = Leg(sdt, waypoint, bearing)
        legs = [leg]
        route = Route(legs)

        self.assertIsInstance(route, Route)
Example #6
0
    def test_reverse_bearing_is_correct(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "N")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)
        bearing = CompassBearing(190)
        reverse_bearing = CompassBearing(10)
        leg = Leg(sdt, waypoint, bearing)

        self.assertIsInstance(leg.end_waypoint, Waypoint)
        self.assertEqual(leg.reverse_bearing.bearing, reverse_bearing.bearing)
Example #7
0
    def test_route_returns_correct_number_of_legs(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "N")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)
        bearing = CompassBearing(190)
        leg = Leg(sdt, waypoint, bearing)
        legs = [leg]
        route = Route(legs)

        self.assertIsInstance(route, Route)
        self.assertEqual(route.number_of_legs, 1)
Example #8
0
    def test_previous_leg_of_route_does_not_exist(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "N")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)
        bearing = CompassBearing(190)
        leg = Leg(sdt, waypoint, bearing)
        legs = [leg]
        route = Route(legs)

        self.assertIsInstance(route, Route)
        with self.assertRaises(IndexError):
            route.previous_leg(2)
Example #9
0
    def test_get_current_leg_bad_index(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "N")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)
        bearing = CompassBearing(190)
        leg = Leg(sdt, waypoint, bearing)
        legs = [leg]
        route = Route(legs)

        self.assertIsInstance(route, Route)
        with self.assertRaises(IndexError):
            route.current_leg(1)
Example #10
0
    def test_end_waypoint_is_generate_correctly(self):
        distance = Distance(10)
        time = Time(20)
        sdt = SpeedDistanceTime(distance=distance, time=time)
        latitude = Coordinate(56, 42, 10, "N")
        longitude = Coordinate(2, 5, 19, "W")
        waypoint = Waypoint(latitude, longitude)
        bearing = CompassBearing(190)

        expected_end_wpt = Waypoint(Coordinate(56, 32, 20, "N"),
                                    Coordinate(2, 8, 27, "W"))
        leg = Leg(sdt, waypoint, bearing)

        self.assertIsInstance(leg.end_waypoint, Waypoint)
        self.assertAlmostEqual(leg.end_waypoint.latitude.as_decimal,
                               expected_end_wpt.latitude.as_decimal)
        self.assertAlmostEqual(leg.end_waypoint.longitude.as_decimal,
                               expected_end_wpt.longitude.as_decimal)