class ParkService(ABC): def __init__(self): self.lotHandler = None @property def IsInitialized(self): return self.lotHandler is not None @abstractmethod def allow(self, car, slotNum): pass def InitializeParkingLot(self, capacity): if self.lotHandler is None: self.lotHandler = LotHandler(capacity) return ParkingLotInit.format(capacity), self.lotHandler else: raise Exception('Already Initialized Parking Lot') def CheckCarParkedAlready(self, car): return self.lotHandler.IsCarParked(car) def ShowStatus(self): return self.lotHandler.slots def RegNumsByColor(self, color): result = self.lotHandler.GetRegNumsByColor(color) return ', '.join(result) def SlotNumsByColor(self, color): result = self.lotHandler.GetSlotNumsByColor(color) return ', '.join(result) def SlotNumForRegNum(self, regNum): return self.lotHandler.GetSlotNumByRegNum(regNum)
def test_get_slot_nums_by_color(self): # Arrange lh = LotHandler(4) car1 = Car('KA-01-HH-1234', 'White') car2 = Car('KA-04-HH-1231', 'Blue') car3 = Car('KA-08-HH-1111', 'Red') car4 = Car('KA-02-HH-9999', 'Blue') lh.FillSlot(car1, 1) lh.FillSlot(car2, 2) lh.FillSlot(car3, 3) lh.FillSlot(car4, 4) expectedBlueSlots = ['2', '4'] expectedRedslots = ['3'] # Act actualBlueSlots = lh.GetSlotNumsByColor('Blue') actualRedSlots = lh.GetSlotNumsByColor('Red') actualYellowSlots = lh.GetSlotNumsByColor('Yellow') # Assert self.assertEqual(expectedBlueSlots, actualBlueSlots) self.assertEqual(expectedRedslots, actualRedSlots) self.assertEqual([], actualYellowSlots)