Example #1
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 #2
0
 def test_leg_fails_to_initailise_without_valid_waypoint(self):
     distance = Distance(10)
     time = Time(20)
     sdt = SpeedDistanceTime(distance=distance, time=time)
     waypoint = (10.123456, 2.324567)
     bearing = CompassBearing(190)
     with self.assertRaises(TypeError):
         Leg(sdt, waypoint, bearing)
Example #3
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 #4
0
    def test_starting_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)
        bearing = CompassBearing(190)
        leg = Leg(sdt, waypoint, bearing)
        legs = [leg]
        route = Route(legs)

        self.assertIsInstance(route, Route)
        self.assertEqual(route.start_waypoint, waypoint)
Example #5
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 #6
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 #7
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 #8
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 #9
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)
Example #10
0
 def test_compass_bearing_can_be_0(self):
     bearing = CompassBearing(0)
     self.assertIsInstance(bearing, CompassBearing)
     self.assertEqual(bearing.bearing, 0)
Example #11
0
 def test_compass_bearing_can_not_be_greater_than_360(self):
     with self.assertRaises(ValueError):
         CompassBearing(361)
Example #12
0
 def test_compass_bearing_can_not_be_negative_value(self):
     with self.assertRaises(ValueError):
         CompassBearing(-1)
Example #13
0
 def test_compass_bearing_initailises_with_int(self):
     bearing = CompassBearing(12)
     self.assertIsInstance(bearing, CompassBearing)
     self.assertEqual(bearing.bearing, 12)