def test_isSlotFree(self): """ test isSlotFree method 1. Check lot free for non zero postive number 2. Check for zero """ oParking = Parking(2) self.assertEquals(oParking.isSlotFree(), 0) oParking.lSlot[0] = 1 self.assertEquals(oParking.isSlotFree(), 1) oParking.lSlot[1] = 1 self.assertEquals(oParking.isSlotFree(), -1) oParking = Parking(0) self.assertEquals(oParking.isSlotFree(), -1)
def test_init(self): """ On creatation there should be empty Slots 1. assign non zero Parking lot 2. assign zero parking lot 3. assign negative number """ oParking = Parking(1) self.assertEquals(len(oParking), 1) for oSlot in oParking.lSlot: self.assertIsNone(oSlot) oParking = Parking(0) self.assertEquals(len(oParking), 0) oParking = Parking(-1) self.assertEquals(len(oParking), 0)
def test_addCar(self): """ test addCar 1. Add non zero Cars. Check list filled up with Lot type """ oParking = Parking(2) sMessage = oParking.addCar("a", "b") self.assertEquals(len(oParking.dCarsColor["b"]), 1) self.assertEquals(sMessage, "Allocated slot number: {}".format(1)) self.assertIsInstance(oParking.lSlot[0], Slot) sMessage = oParking.addCar("a", "b") self.assertEquals(len(oParking.dCarsColor["b"]), 2) self.assertIsInstance(oParking.lSlot[1], Slot) self.assertEquals(sMessage, "Allocated slot number: {}".format(2)) sMessage = oParking.addCar("a", "b") self.assertEquals(len(oParking.dCarsColor["b"]), 2) self.assertEquals(sMessage, "Sorry, parking lot is full")
def test_removeCar(self): """ test removeCar test if slot number greater than no of slots check for non zero slot """ oParking = Parking(0) sMessage = oParking.removeCar(1) self.assertEquals(sMessage, "There is no Slot number {}".format(1)) oParking = Parking(2) sMessage = oParking.removeCar(2) self.assertEquals(sMessage, "Slot number {} is free".format(2)) oParking.addCar("12", "white") oParking.addCar("13", "black") sMessage = oParking.removeCar(2) self.assertFalse("black" in oParking.dCarsColor) self.assertEquals(sMessage, "Slot number {} is free".format(2))
def test_status(self): """ test status """ oParking = Parking(3) sMessage = oParking.status() self.assertEquals(sMessage, "Slot No.\tRegistration No\t\tColour\n") oParking.lSlot[0] = Slot("1234", "123") sMessage = oParking.status() self.assertEquals( sMessage, "Slot No.\tRegistration No\t\tColour\n1\t\t1234\t\t\t123\n") oParking.lSlot[2] = Slot("1234", "123") sMessage = oParking.status() self.assertEquals( sMessage, "Slot No.\tRegistration No\t\tColour\n1\t\t1234\t\t\t123\n3\t\t1234\t\t\t123\n" )
def test_carsWithColor(self): """ test cars with Color check output after insert and delete to be excepted """ oParking = Parking(2) sMessage = oParking.carsWithColor("white") self.assertEquals("", "") oParking.addCar("12", "white") sMessage = oParking.carsWithColor("white") self.assertEquals(sMessage, "12") oParking.addCar("13", "black") sMessage = oParking.carsWithColor("white") self.assertEquals(sMessage, "12") oParking.removeCar(1) sMessage = oParking.carsWithColor("white") self.assertEquals(sMessage, "")
def test_slotNumber(self): """ test slot Number of car check output after insert and delete to be excepted """ oParking = Parking(2) sMessage = oParking.carsWithColor("white") self.assertEquals("", "") oParking.addCar("12", "white") sMessage = oParking.slotNumber("12") self.assertEquals(sMessage, "1") oParking.addCar("13", "black") sMessage = oParking.slotNumber("12") self.assertEquals(sMessage, "1") oParking.removeCar(1) sMessage = oParking.slotNumber("12") self.assertEquals(sMessage, "None Found") sMessage = oParking.slotNumber("13") self.assertEquals(sMessage, "2")
if not bInteractive: input_file = open(sys.argv[1], 'r') getCommand = input_file.readline else: getCommand = raw_input if bInteractive: print "Input:" sCommand = getCommand() while sCommand: lCommands = sCommand.split() iLength = len(lCommands) if iLength: if bInteractive: print "\nOutput:" if lCommands[0] == "create_parking_lot" and iLength == 2: oParking = Parking(int(lCommands[1])) elif lCommands[0] == "park" and iLength == 3: print oParking.addCar(lCommands[1], lCommands[2]) + "\n" elif lCommands[0] == "leave" and iLength == 2: print oParking.removeCar(int(lCommands[1])) + "\n" elif lCommands[0] == "status": print oParking.status() elif lCommands[ 0] == "registration_numbers_for_cars_with_colour" and iLength == 2: print oParking.carsWithColor(lCommands[1]) + "\n" elif lCommands[ 0] == "slot_number_for_registration_number" and iLength == 2: print oParking.slotNumber(lCommands[1]) + "\n" if bInteractive: print "Input:" sCommand = getCommand()