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)
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)
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)
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)
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)
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)
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)
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)
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))
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)
def test_distance_instantiates_with_zero_value(self): distance = Distance(0) self.assertIsInstance(distance, Distance) self.assertEqual(distance.in_nautical_miles, 0)
def test_distance_fails_to_instantiate_with_negative_number(self): with self.assertRaises(ValueError): Distance(-2.0)
def test_distance_instantiates_with_integer(self): distance = Distance(10) self.assertIsInstance(distance, Distance) self.assertEqual(distance.in_nautical_miles, 10)
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)
def test_distance_converts_to_miles(self): distance = Distance(20) self.assertAlmostEqual(distance.in_miles, Decimal(23.0156))
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)
def test_distance_converts_to_km(self): distance = Distance(10) self.assertAlmostEqual(distance.in_km, Decimal(18.52))
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)
def test_distance_instantiates_with_string_number_value(self): distance = Distance('10.60') self.assertIsInstance(distance, Distance)
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)