def test_vehicle_parking_ticket_assignment(self): assigned_ticket_ids = set() for car_config in TestVehicle.cars_config: car = Car(*car_config) parking_ticket = FourWheelerParkingTicket() car.ticket = parking_ticket self.assertNotIn(parking_ticket.id_, assigned_ticket_ids)
def test_free_up_parking_spot(self): parking_lot = self._build_default_parking_lot() car = Car("DUMMY2", "White") parking_lot.allocate_parking_spot(car) parking_spot_id = car.parking_spot.id_ parking_lot.free_up_parking_spot(parking_spot_id) self.assertIsNone(car.ticket) self.assertIsNone(car.parking_spot) self.assertFalse(car.is_vehicle_parked())
def test_allocate_parking_spot(self): for car_config in TestVehicle.cars_config: car = Car(*car_config) parking_spot = FourWheelerSpot() # check vehicle's parking-spot before allocation self.assertFalse(car.is_vehicle_parked()) # check vehicle's parking-spot after allocation car.parking_spot = parking_spot self.assertTrue(car.is_vehicle_parked())
def test_vehicle_type(self): """ Assert if vehicle(car) type is VehicleType. """ for car_config in TestVehicle.cars_config: car = Car(*car_config) self.assertIsInstance(car.type_, VehicleType)
def test_vehicle_reg_no_is_upper_case(self): """ Assert if car's registration number is upper-case. """ for car_config in TestVehicle.cars_config: car = Car(*car_config) self.assertTrue(car.registration_number.isupper())
def test_vehicle_color_is_lower_case(self): """ Assert if car's color is lower-case. """ for car_config in TestVehicle.cars_config: car = Car(*car_config) self.assertTrue(car.color.islower())
def test_allocate_parking_spot(self): parking_lot = self._build_default_parking_lot() car = Car("DUMMY1", "White") parking_lot.allocate_parking_spot(car) self.assertIsInstance(car.parking_spot, (FourWheelerSpot, ParkingSpot)) self.assertIsInstance(car.ticket, (FourWheelerParkingTicket, ParkingTicket)) parking_spot = car.parking_spot ticket = car.ticket for __ in range(1): parking_lot.allocate_parking_spot(car) self.assertIs(car.parking_spot, parking_spot) self.assertIs(car.ticket, ticket) self.assertIsNotNone(car.ticket) self.assertIsNotNone(car.parking_spot) self.assertFalse(car.parking_spot.is_free()) self.assertTrue(car.is_vehicle_parked()) parking_lot.free_up_parking_spot(car.parking_spot.id_)
def test_occupy_spot(self): four_wheeler_parking_lot_builder = FourWheelerParkingLotBuilder() director = ParkingLotDirector(four_wheeler_parking_lot_builder) director.build_parking_lot(10) parking_lot = director.get_parking_lot() car = Car("dummy_reg_no", "dummy_color") parking_spot = FourWheelerSpot() parking_spot.occupy_spot(car) self.assertFalse(parking_spot.is_free())
def test_get_vehicle_spot_number(self): self.clean_up_parking_spot() parking_lot = self._build_default_parking_lot() for config in TestParkingLot.cars_config: car = Car(*config) parking_lot.allocate_parking_spot(car) self.assertEqual( parking_lot.get_vehicle_spot_number(car.registration_number), car.parking_spot.id_) parking_lot.free_up_parking_spot(car.parking_spot.id_)
def test_get_parking_lot_status_1(self): parking_lot = self._build_default_parking_lot() expected_results = [('Slot No.', 'Registration No', 'Colour')] for config in TestParkingLot.cars_config: car = Car(*config) parking_lot.allocate_parking_spot(car) parking_spot_id = car.parking_spot.id_ row = (parking_spot_id, car.registration_number, car.color.capitalize()) expected_results.append(row) status = parking_lot.get_parking_lot_status() self.assertListEqual(expected_results, status)
def test_get_parking_spot_numbers_of_vehicles_with_color(self): self.clean_up_parking_spot() parking_lot = self._build_default_parking_lot() colors_map = defaultdict(set) for config in TestParkingLot.cars_config: car = Car(*config) colors_map[config[1]].add(car) parking_lot.allocate_parking_spot(car) colors_map[config[1].lower()].add(car) for color in colors_map: parking_spot_ids = parking_lot.get_parking_spot_numbers_of_vehicles_with_color( color) self.assertEqual(len(colors_map[color]), len(parking_spot_ids)) for car in colors_map[color]: self.assertIn(car.parking_spot.id_, set(parking_spot_ids))
def test_get_registration_numbers_of_vehicle_with_color(self): parking_lot = self._build_default_parking_lot() colors_map = defaultdict(set) for config in TestParkingLot.cars_config: car = Car(*config) colors_map[config[1]].add(car) parking_lot.allocate_parking_spot(car) colors_map[config[1].lower()].add(car) for color in colors_map: vehicle_registration_numbers = \ set(parking_lot.get_registration_numbers_of_vehicle_with_color(color)) self.assertEqual(len(colors_map[color]), len(vehicle_registration_numbers)) for car in colors_map[color]: self.assertIn(car.registration_number, vehicle_registration_numbers)
def test_get_parking_lot_status_2(self): parking_lot = self._build_default_parking_lot() for config in TestParkingLot.cars_config: car = Car(*config) parking_lot.allocate_parking_spot(car) status = parking_lot.get_parking_lot_status() expected_results = [('Slot No.', 'Registration No', 'Colour')] for row in status[1:]: spot_id = row[0] if spot_id % 2 == 0: parking_lot.free_up_parking_spot(spot_id) continue expected_results.append(row) status = parking_lot.get_parking_lot_status() self.assertListEqual(expected_results, status)
def test__deallocate_parking_spot(self): for car_config in TestVehicle.cars_config: car = Car(*car_config) parking_spot = FourWheelerSpot() # allocate parking-spot car.parking_spot = parking_spot # parking-spot deallocation car._deallocate_parking_spot() self.assertFalse(car.is_vehicle_parked()) self.assertIsNone(car.parking_spot) self.assertIsNone(car.ticket)
def test_type_predicate(self): for car_config in TestVehicle.cars_config: car = Car(*car_config) self.assertTrue(car.type_predicate(VehicleType.CAR))
def __init__(self, registration_number: str, color: str): self._vehicle = Car(registration_number, color)