def test_leave_slot_free(self): parkingLot = create_parking_lot(str(6)) park_car(parkingLot, 'PB-01-HH-1234', '21') testResponse = leave_slot(parkingLot, '1') self.assertEqual('Slot number 1 vacated, the car with vehicle '\ 'registration number "PB-01-HH-1234" left the space, '\ 'the driver of the car was of age 21', testResponse)
def runCommand(parkingLot,command): if command[0] == 'create_parking_lot': parkingLot = create_parking_lot(command[1]) elif command[0] == 'park': park_car(parkingLot,command[1],command[2]) elif command[0] == 'leave': print(leave_parking(parkingLot,command[1])) elif command[0] == 'status': print(status(parkingLot).rstrip('\n')) elif command[0] == 'registration_numbers_for_cars_with_colour': print(get_registration_numbers_by_color(parkingLot,command[1])) elif command[0] == 'slot_numbers_for_cars_with_colour': print(get_slot_numbers_by_color(parkingLot,command[1])) elif command[0] == 'slot_number_for_registration_number': print(get_slot_number_for_registration_number(parkingLot,command[1])) else: print('command not applicable, please refer README file for valid interactive commands or execute using input_file.txt') return parkingLot
def test_nearest_allocation(self): testParkingLot = create_parking_lot(str(6)) park_car(testParkingLot, 'KA-01-HH-1234', 'White') park_car(testParkingLot, 'KA-02-HH-1234', 'White') park_car(testParkingLot, 'KA-03-aH-5234', 'White') assignedSlot = testParkingLot.get_slots()[3].get_slot() self.assertEqual(assignedSlot, 3)
def test_get_registration_number_by_color(self): testParkingLot = create_parking_lot(str(6)) park_car(testParkingLot, 'KA-01-HH-1234', 'White') park_car(testParkingLot, 'KA-01-HH-9999', 'White') park_car(testParkingLot, 'KA-01-P-333', 'White') result = get_registration_numbers_by_color(testParkingLot, 'White') self.assertEqual(result, 'KA-01-HH-1234, KA-01-HH-9999, KA-01-P-333')
def executeCommand(parkingLot, command): if command[0] == 'Create_parking_lot': parkingLot = create_parking_lot(command[1]) elif command[0] == 'Park': print(park_car(parkingLot, command[1], command[3])) elif command[0] == 'Leave': print(leave_slot(parkingLot, command[1])) elif command[0] == 'Slot_numbers_for_driver_of_age': print(get_slots_with_driver_age(parkingLot, command[1])) elif command[0] == 'Slot_number_for_car_with_number': print(get_slot_by_car_registration(parkingLot, command[1])) elif command[0] == 'Vehicle_registration_number_for_driver_of_age': print(get_vehical_regno_for_driver(parkingLot, command[1])) else: print('Undefined command!') return parkingLot
def test_leave_slot_not_present_in_parking(self): testParkingLot = create_parking_lot(str(6)) park_car(testParkingLot, 'KA-01-HH-1234', 'White') result = leave_parking(testParkingLot, str(7)) self.assertEqual(result, 'Slot number not in parking lot')
def test_leave_slot(self): testParkingLot = create_parking_lot(str(2)) park_car(testParkingLot, 'KA-01-HH-1234', 'White') result = leave_parking(testParkingLot, str(1)) self.assertEqual(result, 'Slot number 1 is free')
def test_parking_full(self): testParkingLot = create_parking_lot(str(2)) park_car(testParkingLot, 'KA-01-HH-1234', 'White') park_car(testParkingLot, 'KA-02-HH-1234', 'White') result = park_car(testParkingLot, 'KA-03-aH-5234', 'White') self.assertFalse(result)
def test_parking_lot_allocation(self): parkingLot = create_parking_lot(str(6)) testResponse = park_car(parkingLot, 'PB-01-HH-1234', '27') self.assertEqual('Car with vehicle registration number "PB-01-HH-1234" '\ 'has been parked at slot number 1', testResponse)
def test_park_car(self): testParkingLot = create_parking_lot(str(6)) result = park_car(testParkingLot, 'KA-01-HH-1234', 'White') self.assertTrue(result) result = park_car(testParkingLot, 'KA-01-HH-1234', 'White') self.assertFalse(result)
def test_registration_number_is_repeated(self): testParkingLot = create_parking_lot(str(6)) result = park_car(testParkingLot, 'KA-01-HH-1234', 'White') result = registration_number_is_repeated(testParkingLot, 'KA-01-HH-1234') self.assertTrue(result)
def test_get_drivers_of_age(self): parkingLot = create_parking_lot(str(6)) park_car(parkingLot, 'PB-01-HH-1234', '27') testResponse = get_slots_with_driver_age(parkingLot, '27') self.assertEqual(testResponse, '1')
def test_get_slot_number_by_color_not_found(self): testParkingLot = create_parking_lot(str(6)) park_car(testParkingLot, 'KA-01-HH-1234', 'White') result = get_slot_numbers_by_color(testParkingLot, 'Black') self.assertEqual(result, 'Not found')
def test_full_car_parking_lot(self): parkingLot = create_parking_lot(str(1)) park_car(parkingLot, 'PB-01-HH-1234', '27') testResponse = park_car(parkingLot, 'PB-01-HH-1222', '27') self.assertEqual('Sorry, parking lot is full!', testResponse)
def test_leave_slot_cannot_exit(self): parkingLot = create_parking_lot(str(6)) park_car(parkingLot, 'PB-01-HH-1234', '27') testResponse = leave_slot(parkingLot, '7') self.assertEqual('No such lot exists!', testResponse)
def test_unknown_car_slot_number(self): parkingLot = create_parking_lot(str(6)) park_car(parkingLot, 'PB-01-HH-1234', '27') testResponse = get_slot_by_car_registration(parkingLot, 'PB-01-HH-1233') self.assertEqual(testResponse, 'No such car found!')
def test_parking_without_car_park(self): testResponse = park_car(None, 'PB-01-HH-1234', 20) self.assertEqual('Parking lot has not been created yet', testResponse)
def test_get_regno_with_driver_age(self): parkingLot = create_parking_lot(str(6)) park_car(parkingLot, 'PB-01-HH-1234', '27') park_car(parkingLot, 'PB-01-HH-1233', '27') testResponse = get_vehical_regno_for_driver(parkingLot, '27') self.assertEqual(testResponse, 'PB-01-HH-1234, PB-01-HH-1233')
def test_status(self): testParkingLot = create_parking_lot(str(6)) park_car(testParkingLot, 'KA-01-HH-1234', 'White') park_car(testParkingLot, 'KA-01-HH-9999', 'White') park_car(testParkingLot, 'KA-01-BB-0001', 'Black') park_car(testParkingLot, 'KA-01-HH-7777', 'Red') park_car(testParkingLot, 'KA-01-HH-2701', 'Blue') park_car(testParkingLot, 'KA-01-HH-3141', 'Black') leave_parking(testParkingLot, str(4)) result = status(testParkingLot) self.assertEqual( result, 'Slot No. Registration No Colour\n1 KA-01-HH-1234 White\n2 KA-01-HH-9999 White\n3 KA-01-BB-0001 Black\n5 KA-01-HH-2701 Blue\n6 KA-01-HH-3141 Black\n' )
def test_get_slot_number_for_registration_number_not_found(self): testParkingLot = create_parking_lot(str(6)) park_car(testParkingLot, 'KA-01-HH-1234', 'White') result = get_slot_number_for_registration_number( testParkingLot, 'KA-01-HH-999') self.assertEqual(result, 'Not found')
def test_leave_slot_unoccupied(self): parkingLot = create_parking_lot(str(6)) park_car(parkingLot, 'PB-01-HH-1234', '27') testResponse = leave_slot(parkingLot, '2') self.assertEqual('No car found this in this slot!', testResponse)
def test_get_car_slot_number(self): parkingLot = create_parking_lot(str(6)) park_car(parkingLot, 'PB-01-HH-1234', '27') testResponse = get_slot_by_car_registration(parkingLot, 'PB-01-HH-1234') self.assertEqual(testResponse, 1)