def test_car_fuel_needed(self, id_, fuel, new_x, new_y): manager = SuperDuperManager() manager.add_vehicle('Car', id_, fuel) x, y = manager.get_vehicle_position(id_) fuel_needed = abs(new_x - x) + abs(new_y - y) manager.move_vehicle(id_, new_x, new_y) self.assertEquals(fuel - fuel_needed, manager.get_vehicle_fuel(id_))
def test_helicopter_fuel_needed(self, id_, fuel, new_x, new_y): manager = SuperDuperManager() manager.add_vehicle('Helicopter', id_, fuel) x, y = manager.get_vehicle_position(id_) fuel_needed = sqrt(abs(new_x - x)**2 + abs(new_y - y)**2) manager.move_vehicle(id_, new_x, new_y) self.assertEquals(int(fuel - fuel_needed), manager.get_vehicle_fuel(id_))
def test_move_car_changes_attributes(id_, fuel, new_x, new_y): # Similar to an assert: retries test when this property is false assume(abs(new_x) + abs(new_y) <= fuel) manager = SuperDuperManager() manager.add_vehicle('Car', id_, fuel) manager.move_vehicle(id_, new_x, new_y) assert manager.get_vehicle_position(id_) == (new_x, new_y) assert manager.get_vehicle_fuel(id_) == fuel - abs(new_x) - abs(new_y)
def test_carpet_move(self, id_, fuel, new_x, new_y): manager = SuperDuperManager() manager.add_vehicle('UnreliableMagicCarpet', id_, fuel) manager.move_vehicle(id_, new_x, new_y) x, y = manager.get_vehicle_position(id_) delta_x = abs(new_x - x) delta_y = abs(new_y - y) self.assertLessEqual(delta_x, 2) self.assertLessEqual(delta_y, 2)
def test_new_carpet_attributes(id_, fuel): manager = SuperDuperManager() manager.add_vehicle('UnreliableMagicCarpet', id_, fuel) assert manager.get_vehicle_fuel(id_) == fuel pos = manager.get_vehicle_position(id_) assert abs(pos[0]) <= 10 assert abs(pos[1]) <= 10
def test_new_carpet_attributes(self, id_, fuel): manager = SuperDuperManager() manager.add_vehicle('UnreliableMagicCarpet', id_, fuel) self.assertEqual(manager.get_vehicle_fuel(id_), fuel) self.assertLessEqual(abs(manager.get_vehicle_position(id_)[0]), 10) self.assertLessEqual(abs(manager.get_vehicle_position(id_)[1]), 10)
def test_new_helicopter_attributes(self, id_, fuel): manager = SuperDuperManager() manager.add_vehicle('Helicopter', id_, fuel) self.assertEqual(manager.get_vehicle_fuel(id_), fuel) self.assertEqual(manager.get_vehicle_position(id_), (3, 5))
def test_new_car_attributes(self, id_, fuel): manager = SuperDuperManager() manager.add_vehicle('Car', id_, fuel) self.assertEqual(manager.get_vehicle_fuel(id_), fuel) self.assertEqual(manager.get_vehicle_position(id_), (0, 0))
def test_new_helicopter_attributes(id_, fuel): manager = SuperDuperManager() manager.add_vehicle('Helicopter', id_, fuel) assert manager.get_vehicle_fuel(id_) == fuel assert manager.get_vehicle_position(id_) == (3, 5)
def test_new_car_attributes(id_, fuel): manager = SuperDuperManager() manager.add_vehicle('Car', id_, fuel) assert manager.get_vehicle_fuel(id_) == fuel assert manager.get_vehicle_position(id_) == (0, 0)
def test_helicopiter_move(self, id_, fuel, new_x, new_y): manager = SuperDuperManager() manager.add_vehicle('Helicopter', id_, fuel) manager.move_vehicle(id_, new_x, new_y) self.assertEqual((new_x, new_y), manager.get_vehicle_position(id_))
def test_carpet_fuel_needed(self, id_, fuel, new_x, new_y): manager = SuperDuperManager() manager.add_vehicle('UnreliableMagicCarpet', id_, fuel) manager.move_vehicle(id_, new_x, new_y) self.assertEqual(fuel, manager.get_vehicle_fuel(id_))