예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #5
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)
예제 #6
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)
예제 #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)
예제 #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)
예제 #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))
예제 #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)
예제 #11
0
 def test_distance_instantiates_with_zero_value(self):
     distance = Distance(0)
     self.assertIsInstance(distance, Distance)
     self.assertEqual(distance.in_nautical_miles, 0)
예제 #12
0
 def test_distance_fails_to_instantiate_with_negative_number(self):
     with self.assertRaises(ValueError):
         Distance(-2.0)
예제 #13
0
 def test_distance_instantiates_with_integer(self):
     distance = Distance(10)
     self.assertIsInstance(distance, Distance)
     self.assertEqual(distance.in_nautical_miles, 10)
예제 #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)
예제 #15
0
 def test_distance_converts_to_miles(self):
     distance = Distance(20)
     self.assertAlmostEqual(distance.in_miles, Decimal(23.0156))
예제 #16
0
 def test_distance_instantiates_with_less_than_one_greater_than_0(self):
     distance = Distance(0.2)
     self.assertIsInstance(distance, Distance)
     self.assertEqual(distance.in_nautical_miles, 0.2)
예제 #17
0
 def test_distance_converts_to_km(self):
     distance = Distance(10)
     self.assertAlmostEqual(distance.in_km, Decimal(18.52))
예제 #18
0
 def test_distance_instantiates_with_float(self):
     distance = Distance(19.2345)
     self.assertIsInstance(distance.in_nautical_miles, Decimal)
     self.assertEqual(distance.in_nautical_miles, 19.2345)
예제 #19
0
 def test_distance_instantiates_with_string_number_value(self):
     distance = Distance('10.60')
     self.assertIsInstance(distance, Distance)
예제 #20
0
 def test_sdt_intailises_with_speed_and_distance(self):
     speed = Speed(10)
     distance = Distance(20)
     sdt = SpeedDistanceTime(speed=speed, distance=distance)
     self.assertIsInstance(sdt, SpeedDistanceTime)
     self.assertEqual(sdt.time.in_seconds, 7200)