def test_park_car(self): """ Test that it can park a car """ parking = park.Parking(2) result = park.parkNewCar(parking, 'KA-01-HH-1234', 21) self.assertEqual(result, 1)
def test_slot4Car_neg(self): """ Test that it can return None where an invalid car is passed """ parking = park.Parking(2) park.parkNewCar(parking, 'KA-01-HH-1234', 21) result = park.slot4Car(parking, 'KA-01-HH-1235') self.assertIsNone(result)
def test_slot4Car(self): """ Test that it can return slot where a car is parked """ parking = park.Parking(2) park.parkNewCar(parking, 'KA-01-HH-1234', 21) result = park.slot4Car(parking, 'KA-01-HH-1234') self.assertEqual(result, 1)
def test_leave_car(self): """ Test that it can empty a slot """ parking = park.Parking(2) park.parkNewCar(parking, 'KA-01-HH-1234', 21) result = park.leaveSlot(parking, 1) self.assertIsInstance(result, park.Car)
def test_closest_parking_scenario(self): """ Test that it can always park in the spot closest to the entrance """ parking = park.Parking(3) park.parkNewCar(parking, 'KA-01-HH-1234', 21) park.parkNewCar(parking, 'KA-01-HH-1235', 21) park.leaveSlot(parking, 1) result = park.parkNewCar(parking, 'KA-01-HH-1236', 21) self.assertEqual(result, 1)
def test_regs_for_age(self): """ Test that it can return list of registrations for age """ parking = park.Parking(2) park.parkNewCar(parking, 'KA-01-HH-1234', 21) park.parkNewCar(parking, 'KA-01-HH-1235', 21) result = park.age_to_reg(parking, 21) self.expected = ['KA-01-HH-1234', 'KA-01-HH-1235'] self.assertListEqual(result, self.expected)
def test_slots_for_age(self): """ Test that it can return list of slots for age """ parking = park.Parking(2) park.parkNewCar(parking, 'KA-01-HH-1234', 21) park.parkNewCar(parking, 'KA-01-HH-1235', 21) result = park.age_to_slots(parking, 21) self.expected = [1, 2] self.assertListEqual(result, self.expected)
def test_car_exists_scenario(self): """ Test that it can return None when we try to park a car after parking has become full """ parking = park.Parking(2) result = park.parkNewCar(parking, 'KA-01-HH-1234', 21) self.assertEqual(result, 1) result = park.parkNewCar(parking, 'KA-01-HH-1235', 21) self.assertEqual(result, 2) result = park.parkNewCar(parking, 'KA-01-HH-1235', 21) self.assertIsNone(result)
def runCommands(commands): """ Takes a list of valid commands as parameter. Runs them in order. Prints the results. Raises KeyError if invalid command is passed. """ for item in commands: command = item[0] args = item[1] if (command == 'Create_parking_lot'): parking = park.Parking(*args) print(f'Created parking of {args[0]} slots') elif (command == 'Park'): result = park.parkNewCar(parking, *args) if (result != None): print( f'Car with vehicle registration number "{args[0]}" has been parked at slot number {result}' ) else: print('Car exists') if result == None else print( 'Car parking is full') elif (command == 'Leave'): result = park.leaveSlot(parking, *args) if (result == None): print(f'Slot {slot} is already empty') else: print( f'Slot number {args[0]} vacated, the car with vehicle registration number "{result.registration}" left the space, the driver of the car was of age {result.driver_age}' ) elif (command == 'Slot_numbers_for_driver_of_age'): result = park.age_to_slots(parking, *args) print(','.join(list( str(slot) for slot in result))) if result != None or len(result) > 0 else print( 'No slots occcupied by drivers of this age in parking') elif (command == 'Vehicle_registration_number_for_driver_of_age'): result = park.age_to_reg(parking, *args) print(','.join( result)) if result != None or len(result) > 0 else print( 'No cars with drivers of this age in parking') elif (command == 'Slot_number_for_car_with_number'): slot = park.slot4Car(parking, *args) print(f'{slot}') else: raise KeyError return True