Ejemplo n.º 1
0
 def execute(self, command_words):
     """
     Execute Command
     """
     parking_lot = ParkingLot()
     print parking_lot.registration_numbers_for_cars_with_colour(
         *command_words)
Ejemplo n.º 2
0
 def test_creation(self):
     """
     Can create parking lot with n number.
     Raise Exception
         * size is not a number.
     """
     parking_lot = ParkingLot()
     parking_lot.create_slot(5)
     self.assertEqual(parking_lot.size, 5)
     for slot in parking_lot.slots:
         self.assertIsNone(slot)
     try:
         ParkingLot("ABC")
     except Exception as e:
         self.assertEqual("Size need to be Integer: ABC", e.message)
Ejemplo n.º 3
0
 def test_park_a_car(self):
     """
     Test parking.
     """
     parking_lot = ParkingLot()
     parking_lot.create_slot(0)
     try:
         parking_lot.park_a_car("123", "123")
     except Exception as e:
         self.assertEqual(e.message, "Sorry, parking lot is full")
     parking_lot = ParkingLot(1)
     try:
         parking_lot.park_a_car("", "")
     except Exception as e:
         self.assertEqual(e.message, "vehicale information cannot be empty.\n")
Ejemplo n.º 4
0
 def execute(self, command_words):
     """
     Execute Command
     """
     parking_lot = ParkingLot()
     print parking_lot.slot_number_for_registration_number(*command_words)
Ejemplo n.º 5
0
 def execute(self, command_words):
     """
     Execute Command
     """
     parking_lot = ParkingLot()
     print parking_lot.status_of_parking_lot()
Ejemplo n.º 6
0
 def execute(self, command_words):
     """
     Execute Command
     """
     parking_lot = ParkingLot()
     print parking_lot.car_is_leaving(*command_words)
Ejemplo n.º 7
0
 def execute(self, command_words):
     """
     Execute Command
     """
     parking_lot = ParkingLot()
     print parking_lot.park_a_car(*command_words)
Ejemplo n.º 8
0
 def execute(self, command_words):
     """
     Execute Command
     """
     parking_lot = ParkingLot()
     parking_lot.create_slot(*command_words)
Ejemplo n.º 9
0
 def test_slot_number_for_registration_number(self):
     """
     Test slot_number_for_registration_number.
     """
     parking_lot = ParkingLot()
     parking_lot.create_slot(5)
     parking_lot.park_a_car("KA-01-HH-1234", "White")
     parking_lot.park_a_car("KA-01-BB-0001", "Black")
     parking_lot.park_a_car("KA-01-HH-9999", "White")
     parking_lot.park_a_car("KA-01-HH-2701", "Blue")
     parking_lot.park_a_car("KA-01-HH-3141", "Black")
     slot = parking_lot.slot_number_for_registration_number("KA-01-HH-1234")
     self.assertEqual(slot, "1")
     slot = parking_lot.slot_number_for_registration_number("KA-01-Hd-1234")
     self.assertEqual(slot, "Not found")
Ejemplo n.º 10
0
 def test_slot_numbers_for_cars_with_colour(self):
     """
     Return slot number of the registerd vehicale
     """
     parking_lot = ParkingLot()
     parking_lot.create_slot(5)
     parking_lot.park_a_car("KA-01-HH-1234", "White")
     parking_lot.park_a_car("KA-01-BB-0001", "Black")
     parking_lot.park_a_car("KA-01-HH-9999", "White")
     parking_lot.park_a_car("KA-01-HH-2701", "Blue")
     parking_lot.park_a_car("KA-01-HH-3141", "Black")
     slots = parking_lot.slot_numbers_for_cars_with_colour("BLACK")
     self.assertEqual("2, 5", slots)
     slots = parking_lot.slot_numbers_for_cars_with_colour("YELLOW")
     self.assertEqual("Not found", slots)
Ejemplo n.º 11
0
 def test_registration_numbers_for_cars_with_colour(self):
     """
     Test car with reg number color
     """
     parking_lot = ParkingLot()
     parking_lot.create_slot(5)
     parking_lot.park_a_car("KA-01-HH-1234", "White")
     parking_lot.park_a_car("KA-01-BB-0001", "Black")
     parking_lot.park_a_car("KA-01-HH-9999", "White")
     parking_lot.park_a_car("KA-01-HH-2701", "Blue")
     parking_lot.park_a_car("KA-01-HH-3141", "Black")
     registration_numbers = parking_lot.registration_numbers_for_cars_with_colour("WHITE")
     self.assertEqual(registration_numbers, "KA-01-HH-1234, KA-01-HH-9999")
     registration_numbers = parking_lot.registration_numbers_for_cars_with_colour("RED")
     self.assertEqual(registration_numbers, "Not found")
Ejemplo n.º 12
0
 def test_leave_a_car(self):
     """
     Test car leaving.
     """
     parking_lot = ParkingLot()
     parking_lot.create_slot(3)
     message = parking_lot.car_is_leaving(2)
     self.assertEqual("Slot number 2 is free", message)
     try:
         parking_lot.car_is_leaving(-1)
     except Exception as e:
         self.assertEqual("Slot number should be greater than zero.\n", e.message)
     try:
         parking_lot.car_is_leaving(4)
     except Exception as e:
         self.assertEqual("Slot number does not exist in parking lot.\n", e.message)
     parking_lot.park_a_car("123", "123")
     parking_lot.park_a_car("123", "123")
     parking_lot.park_a_car("123", "123")
     message = parking_lot.car_is_leaving(3)
     self.assertEqual("Slot number 3 is free", message)
Ejemplo n.º 13
0
    def test_status(self):
        """
        Test test_status
        """
        parking_lot = ParkingLot()
        parking_lot.create_slot(6)
        parking_lot.park_a_car("KA-01-HH-1234", "White")
        parking_lot.park_a_car("KA-01-HH-9999", "White")
        parking_lot.park_a_car("KA-01-BB-0001", "Black")
        parking_lot.park_a_car("KA-01-HH-7777", "Red")
        parking_lot.park_a_car("KA-01-HH-2701", "Blue")
        parking_lot.park_a_car("KA-01-HH-3141", "Black")
        parking_lot.car_is_leaving(4)
        import sys
        from StringIO import StringIO
        saved_stdout = sys.stdout
        try:
            out = StringIO()
            sys.stdout = out
            parking_lot.status_of_parking_lot()
            output = out.getvalue().strip()
            expected = """Slot No.    Registration No    Colour
1           KA-01-HH-1234      White
2           KA-01-HH-9999      White
3           KA-01-BB-0001      Black
5           KA-01-HH-2701      Blue
6           KA-01-HH-3141      Black"""
            self.assertEqual(len(expected), len(output))
            self.assertEqual(expected, output)

        finally:
            sys.stdout = saved_stdout