Ejemplo n.º 1
0
 def test_waypoint_initailises_with_coordinates(self):
     latitude = Coordinate(56, 42, 10, "S")
     longitude = Coordinate(2, 5, 19, "W")
     waypoint = Waypoint(latitude, longitude)
     self.assertIsInstance(waypoint, Waypoint)
     self.assertEqual(waypoint.latitude, latitude)
     self.assertEqual(waypoint.longitude, longitude)
Ejemplo n.º 2
0
 def test_waypoint_waypoint_is_coordinate_dict(self):
     latitude = Coordinate(56, 42, 10, "S")
     longitude = Coordinate(2, 5, 19, "W")
     waypoint = Waypoint(latitude, longitude)
     self.assertIsInstance(waypoint.waypoint, dict)
     self.assertEqual(waypoint.waypoint, {
         "latitude": latitude,
         "longitude": longitude
     })
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_distance_between_two_waypoint(self):
        latitude_a = Coordinate(56, 42, 10, "S")
        longitude_a = Coordinate(2, 5, 19, "W")
        latitude_b = Coordinate(56, 50, 10, "S")
        longitude_b = Coordinate(2, 6, 19, "W")

        wpt_a = Waypoint(latitude_a, longitude_a)
        wpt_b = Waypoint(latitude_b, longitude_b)

        distance = Waypoint.distance_between(wpt_a, wpt_b)
        self.assertAlmostEqual(distance.quantize(Decimal('.001')),
                               Decimal(8.033))
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 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)
Ejemplo n.º 8
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)
Ejemplo n.º 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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
 def test_coordinate_initailises_with_int_values(self):
     coordinate = Coordinate(56, 42, 10, "N")
     self.assertIsInstance(coordinate, Coordinate)
     self.assertIsInstance(coordinate.degrees, int)
     self.assertIsInstance(coordinate.minutes, int)
     self.assertIsInstance(coordinate.seconds, int)
     self.assertIsInstance(coordinate.compass, str)
Ejemplo n.º 12
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))
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def test_N_is_a_valid_compass_value(self):
     coordinate = Coordinate(56, 42, 10, "N")
     self.assertIsInstance(coordinate, Coordinate)
     self.assertEqual(coordinate.compass, "N")
Ejemplo n.º 15
0
 def test_waypoint_tuple_is_returned(self):
     coordinate = Coordinate(56, 42, 10, "N")
     self.assertIsInstance(coordinate.waypoint, tuple)
Ejemplo n.º 16
0
 def test_as_decimal_converts_from_south_lat(self):
     coordinate = Coordinate(56, 42, 10, "S")
     self.assertAlmostEqual(coordinate.as_decimal,
                            Decimal(-56.70277777777778))
Ejemplo n.º 17
0
 def test_as_decimal_converts_from_west_long(self):
     coordinate = Coordinate(2, 5, 19, "W")
     self.assertAlmostEqual(coordinate.as_decimal,
                            Decimal(-2.088611111111111))
Ejemplo n.º 18
0
 def test_as_decimal_converts_from_each_long(self):
     coordinate = Coordinate(10, 45, 19, "W")
     self.assertAlmostEqual(coordinate.as_decimal,
                            Decimal(-10.755277777777778))
Ejemplo n.º 19
0
 def test_returns_as_decimal_seconds_zero_seconds(self):
     coordinate = Coordinate(2, 46, 0, "W")
     self.assertEqual(coordinate.as_decimal_seconds, (2, 46, 0, "W"))
Ejemplo n.º 20
0
 def test_waypoint_fails_to_initalise_with_incorrect_params(self):
     with self.assertRaises(TypeError):
         Waypoint(10.5, Coordinate(2, 5, 19, "W"))
Ejemplo n.º 21
0
 def test_B_is_not_a_valid_compass_value(self):
     with self.assertRaises(ValueError):
         Coordinate(56, 42, 10, "B")