Example #1
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 #2
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 #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_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 #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_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 #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_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_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 #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)
Example #11
0
 def test_time_is_integer(self):
     time = Time(200)
     self.assertIsInstance(time.in_seconds, int)
Example #12
0
 def test_sdt_initailises_with_speed_and_time(self):
     speed = Speed(10)
     time = Time(20)
     sdt = SpeedDistanceTime(speed=speed, time=time)
     self.assertIsInstance(sdt, SpeedDistanceTime)
     self.assertEqual(sdt.distance.in_nautical_miles, 200)
Example #13
0
 def test_time_fails_to_instantiate_with_negative_value(self):
     with self.assertRaises(ValueError):
         Time(-20)
Example #14
0
 def test_sdt_initailises_with_distance_and_time(self):
     distance = Distance(10)
     time = Time(20)
     sdt = SpeedDistanceTime(distance=distance, time=time)
     self.assertIsInstance(sdt, SpeedDistanceTime)
     self.assertEqual(sdt.speed.in_knots, 0.5)
Example #15
0
 def test_time_in_hours_is_correct(self):
     time = Time(5400)  # 1.5 hours
     self.assertEqual(time.in_hours, 1.5)
Example #16
0
 def test_time_fails_to_instantiate_with_zero_value(self):
     with self.assertRaises(ValueError):
         Time(0)
Example #17
0
 def test_time_in_minutes_is_correct(self):
     time = Time(60)
     self.assertEqual(time.in_minutes, 1)
Example #18
0
 def test_time_fails_to_instantiate_with_float(self):
     with self.assertRaises(TypeError):
         Time(20.01)