Пример #1
0
 def test_getSlotNoFromRegNo(self):
     parkingLot = ParkingLot()
     res = parkingLot.createParkingLot(6)
     res = parkingLot.park("KA-01-HH-1234", "White")
     res = parkingLot.park("KA-01-HH-9999", "White")
     slotno = parkingLot.getSlotNoFromRegNo("KA-01-HH-9999")
     self.assertEqual(2, slotno)
 def test_park_two_cars_should_get_different_tickets(self):
     parking_lot = ParkingLot(2)
     car1 = Car('a')
     car2 = Car('b')
     t1 = parking_lot.park_car(car1)
     t2 = parking_lot.park_car(car2)
     self.assertNotEqual(t1, t2)
Пример #3
0
 def test_getSlotNoFromDriverAge(self):
     parkingLot = ParkingLot()
     res = parkingLot.createParkingLot(6)
     res = parkingLot.park("KA-01-HH-1234", "21")
     res = parkingLot.park("KA-01-HH-9999", "21")
     slotnos = parkingLot.getSlotNoFromDriverAge("21")
     self.assertIn("1", slotnos)
     self.assertIn("2", slotnos)
Пример #4
0
 def test_getSlotNoFromColor(self):
     parkingLot = ParkingLot()
     res = parkingLot.createParkingLot(6)
     res = parkingLot.park("KA-01-HH-1234", "White")
     res = parkingLot.park("KA-01-HH-9999", "White")
     slotnos = parkingLot.getSlotNoFromColor("White")
     self.assertIn("1", slotnos)
     self.assertIn("2", slotnos)
Пример #5
0
 def test_get_car(self):
     parking_lot = ParkingLot(1)
     car1 = Car(car_number=1,
                car_owner='li',
                contact_way=172,
                car_color='b',
                car_model=3)
     t1 = parking_lot.park_car(car1)
     taken_car1 = parking_lot.take_car(t1)
     self.assertEquals(car1, taken_car1)
Пример #6
0
 def test_get_car_with_wrong_ticket_should_get_exception(self):
     parking_lot = ParkingLot(1)
     car1 = Car(car_number=1,
                car_owner='li',
                contact_way=172,
                car_color='b',
                car_model=3)
     t1 = parking_lot.park_car(car1)
     t2 = "wrongticket"
     self.assertRaises(Exception, parking_lot.take_car(t2), '停车票错误')
Пример #7
0
def main():
    env = ParkingLot()

    initial_state = (125, 125, 0)
    robot = RRT_Robot(env.get_plots())
    robot.compute_config_space(env.obstacles)
    # robot.plot_config_space()
    robot.RRT_plan(initial_state, env.goals)
    # robot.RRT_star_plan(initial_state, env.goals)
    robot.plot_rrt_tree()
    robot.plot_path()
    plt.show()
Пример #8
0
 def test_when_park_car_and_parking_lot_is_full_should_get_exception(self):
     parking_lot = ParkingLot(1)
     car1 = Car(car_number=1,
                car_owner='li',
                contact_way=172,
                car_color='b',
                car_model=3)
     car2 = Car(car_number=2,
                car_owner='zhang',
                contact_way=176,
                car_color='w',
                car_model=3)
     parking_lot.park_car(car1)
     self.assertRaises(Exception, parking_lot.park_car(car2), "车库已满")
Пример #9
0
 def test_park_two_cars_should_get_different_tickets(self):
     parking_lot = ParkingLot(2)
     car1 = Car(car_number=1,
                car_owner='li',
                contact_way=172,
                car_color='b',
                car_model=3)
     car2 = Car(car_number=2,
                car_owner='zhang',
                contact_way=176,
                car_color='w',
                car_model=3)
     t1 = parking_lot.park_car(car1)
     t2 = parking_lot.park_car(car2)
     self.assertNotEquals(t1, t2)
Пример #10
0
def process_create_line(line):
    _, num_slots = line.split()
    strategy = BasicParkingStrategy(int(num_slots))
    parking_lot = ParkingLot(strategy)
    output = f"Created a parking lot with {num_slots} slots"
    parser = create_parser_chain(parking_lot)
    return parser, output
Пример #11
0
 def test_createParkingLot(self):
     parkingLot = ParkingLot.ParkingLot()
     result = StringIO()
     sys.stdout = result
     parkingLot.createParkingLot('2')
     res = result.getvalue()
     self.assertEqual(2, parkingLot.MAX_SIZE)
     self.assertEqual(2, len(parkingLot.availableSlotList))
     self.assertEqual(res.replace('\n', ''),
                      'Created parking lot with 2 slots')
     del parkingLot
Пример #12
0
class Controller:
	def __init__(self):
		self.lot = None

	def run_cmd(self, line):
		args = line.split(" ")
		cmd = args[0]
		if cmd == "create_parking_lot":
			self.lot = ParkingLot(args[1])
			return "Created a parking lot with %s slots"%args[1]
		if not self.lot:
			raise Exception("Parking Lot is not created")

		if cmd == "park":
			return self.lot.assign_vehicle_slot(Car(args[1], args[2]))

		if cmd == "leave":
			return self.lot.release_vehicle(args[1])
		if cmd == "status":
			return self.lot.get_status()
		if cmd == "registration_numbers_for_cars_with_colour":
			return self.lot.registration_numbers_for_cars_with_colour(args[1])

		if cmd == "slot_number_for_registration_number":
			return self.lot.slot_number_for_registration_number(args[1])
		if cmd == "slot_numbers_for_cars_with_colour":
			return self.lot.slot_numbers_for_cars_with_colour(args[1])
		return "cmd %s is not valid"%cmd
Пример #13
0
 def test_get_slotno_from_color(self):
     parking = ParkingLot()
     result = parking.create_parking_lot(8)
     result = parking.park("KA-01-HH-2001", "Black")
     result = parking.park("KA-01-HH-2002", "White")
     result = parking.park("MH-01-HH-2004", "Blue")
     result = parking.park("KA-01-HH-2005", "Black")
     slotnos = parking.get_slotno_from_color("Black")
     self.assertIn("1", slotnos)
     self.assertNotIn("2", slotnos)
     self.assertNotIn("3", slotnos)
Пример #14
0
 def test_status(self):
     parkingLot = ParkingLot.ParkingLot()
     result = StringIO()
     sys.stdout = result
     parkingLot.status()
     parkingLot.createParkingLot('1')
     parkingLot.park("KA-01-HH-1234", "White")
     parkingLot.status()
     res = result.getvalue()
     self.assertEqual(
         res.replace('\n', ''),
         "Sorry, parking lot is not createdCreated parking lot with 1 slotsAllocated slot number: 1Slot No.\tRegistration No.\tColour1\tKA-01-HH-1234\tWhite"
     )
     del parkingLot
Пример #15
0
 def test_getSlotNumberFromRegNo(self):
     parkingLot = ParkingLot.ParkingLot()
     result = StringIO()
     sys.stdout = result
     parkingLot.getSlotNumberFromRegNo("KA-01-HH-1234")
     parkingLot.createParkingLot('1')
     parkingLot.park("KA-01-HH-1234", "White")
     parkingLot.getSlotNumberFromRegNo("KA-01-HH-1234")
     res = result.getvalue()
     self.assertEqual(
         res.replace('\n', ''),
         "Sorry, parking lot is not createdCreated parking lot with 1 slotsAllocated slot number: 11"
     )
     del parkingLot
Пример #16
0
 def test_park(self):
     parkingLot = ParkingLot.ParkingLot()
     result = StringIO()
     sys.stdout = result
     parkingLot.park("KA-01-HH-1234", "White")
     parkingLot.createParkingLot('1')
     parkingLot.park("KA-01-HH-1234", "White")
     parkingLot.park("KA-01-HH-9999", "White")
     res = result.getvalue()
     self.assertEqual(
         res.replace('\n', ''),
         "Sorry, parking lot is not createdCreated parking lot with 1 slotsAllocated slot number: 1Sorry, parking lot is full"
     )
     self.assertEqual(0, len(parkingLot.availableSlotList))
     del parkingLot
Пример #17
0
 def test_get_cars_when_a_car_is_taken_should_get_exception(self):
     parking_lot = ParkingLot(1)
     car = Car(car_number=1,
               car_owner='li',
               contact_way=172,
               car_color='b',
               car_model=3)
     t = parking_lot.park_car(car)
     parking_lot.take_car(t)
     self.assertRaises(Exception, parking_lot.take_car(t), "停车票错误")
Пример #18
0
def parkMyCar():  
    parkinglot = ParkingLot()

    print("=" * 25, "Welcome to Parking Lot system", "=" * 25)
    print("\nChoose an Option for Input Method:\n1. Command Line as Input\n2. Filename as Input")
    input_method = int(input("Enter your choice: "))

    if input_method == 1:
        while True:
            command = input("$ ")
            parkinglot.processInput(command)   
    else:
        filename = input("Enter the Filename\n")
        file = open(filename)
        for command in file.readlines():
            command = command.rstrip("\n")
            parkinglot.processInput(command)  
Пример #19
0
import unittest
from ParkingLot import ParkingLot

parking_lot = ParkingLot()


class TestParkingLot(unittest.TestCase):
    def test_create_parking_lot_valid(self):
        result = parking_lot.create_parking_lot(4)
        self.assertEqual(4, result)

    def test_create_parking_lot_invalid(self):
        result = parking_lot.create_parking_lot(4)
        self.assertNotEqual(5, result)

    def test_park(self):
        result = parking_lot.create_parking_lot(7)
        result = parking_lot.park("KA-01-HH-111", "White")
        result = parking_lot.park("KA-01-HH-112", "Black")
        self.assertNotEqual(-1, result)

    def test_leave_slot(self):
        result = parking_lot.create_parking_lot(6)
        result = parking_lot.park("KA-01-HH-1001", "White")
        result = parking_lot.park("KA-01-HH-1002", "Black")
        result = parking_lot.leave_slot(1)
        self.assertEqual(True, result)

    def test_get_regno_from_color(self):
        result = parking_lot.create_parking_lot(8)
        result = parking_lot.park("KA-01-HH-123", "White")
Пример #20
0
	def __init__(self, location, parkingSpots, w, l, h, f):
		self.floors = f
		ParkingLot.__init__(self, location, parkingSpots, w, l, h)
Пример #21
0
 def test_leave(self):
     parkingLot = ParkingLot()
     res = parkingLot.createParkingLot(6)
     res = parkingLot.park("KA-01-HH-1234", "White")
     res = parkingLot.leave(1)
     self.assertEqual(True, res)
Пример #22
0
import sys 
from ParkingLot import ParkingLot
from Car import Car

if __name__ == "__main__":
    if len(sys.argv) > 1: #case 1: input from file
        filename = sys.argv[1]
        with open(filename, "r") as f:
            while True:
                line = f.readline().rstrip()
                if not line: break
                line = line.split(" ")
                if line[0] == "create_parking_lot":
                    parking_lot = ParkingLot(int(line[1]))
                else:
                    getattr(parking_lot, line[0])(*line[1:])
    else: #case 2: interactive input
        user_input = raw_input().split(" ")
        parking_lot = ParkingLot(int(user_input[1]))
        user_input = raw_input()
        while user_input not in ["exit","\n",""]:# repeat till input is not equal to exit or newline
            user_input = user_input.split(" ")
            getattr(parking_lot, user_input[0])(*user_input[1:])
            user_input = raw_input()

Пример #23
0
    def handle_client_traffic(self, client_socket, client_addr):
        """
        This method will handle incoming traffic from a given client.
        :param client_socket:
        :param client_addr:
        :return:
        """
        data = client_socket.recv(4096)
        packet = ParKingPacket.unpack_packet(data)

        if packet[0] is not ParKingPacket.MESSAGE_TYPE_INIT:
            self.write_to_log('Something is borken!!! Expeceted INIT got : ' . str(packet))
            client_socket.close()
            return

        parking_lot = ParkingLot(packet[1], packet[2], packet[3])

        while self.running:

            client_socket.settimeout(300)
            # set the timeout on the socket so that if there is no activity for 5 mintues we assume that the lot has lost
            # connectivity and cannot be reached
            try:
                data = client_socket.recv(4096)
                # print(str(data))
            except socket.timeout :
                client_socket.close()
                parking_lot.tear_down()
                self.write_to_log('client died!!! WHAT THE WHAT?!')
                return

            self.write_to_log('accepted something from client')
            if len(data) is 0:
                print('Closing client socket D:')
                client_socket.close
                return

            try:
                (message_type, lot_id, capacity, vacancies) = ParKingPacket.unpack_packet(data)
            except error:
                print('struct.error')
                print('unpacking packet : ' + str(data))
            print("**********************************************")
            if message_type is ParKingPacket.MESSAGE_TYPE_ALIVE:
                print('ITS ALIVE!!!')
                continue
            elif message_type is ParKingPacket.MESSAGE_TYPE_IN:
                t = threading.Thread(target=parking_lot.goes_in, args=())
                t.daemon = True
                t.start()
                print('GOES INS')
            elif message_type is ParKingPacket.MESSAGE_TYPE_OUT:
                t = threading.Thread(target=parking_lot.goes_out, args=())
                t.daemon = True
                t.start()
                print("GOES OUTS")
            elif message_type is ParKingPacket.MESSAGE_TYPE_CLOSE:
                print('Closing connection')
                return;
            else:
                print("Unrecognized message type : " . str(message_type))
Пример #24
0
print("Create_parking_lot 6")
print("Park KA-01-HH-1234 driver_age 21")
print("Park PB-01-HH-1234 driver_age 21")
print("Slot_numbers_for_driver_of_age 21")
print("Park PB-01-TG-2341 driver_age 40")
print("Slot_number_for_car_with_number PB-01-HH-1234")
print("Leave 2")
print("Park HR-29-TG-3098 driver_age 39")
print("Vehicle_registration_number_for_driver_of_age 18")
print("---------------ENTER COMMAND NOW--------------------")

for line in fileinput.input():
    '''here reading command one by one'''
    if 'Create_parking_lot' in line:
        data = line.split()
        parkingLot = ParkingLot(int(data[1]))
    if 'Park ' in line:
        data = line.split()
        slotflag = parkingLot.isSlotAvailable()
        if slotflag == True:
            slotNumber = parkingLot.getAvailableSlot()
            parkingLot.parkThePark(slotNumber, data[1], data[3])
        else:
            print("Sorry, parking lot is full")
    if 'Leave' in line:
        data = line.split()
        parkingLot.leaveTheCar(int(data[1]))
    if 'Status' in line:
        parkingLot.showParkingStatus()
    if 'Slot_numbers_for_driver_of_age' in line:
        data = line.split()
Пример #25
0
 def test_park(self):
     parkingLot = ParkingLot()
     res = parkingLot.createParkingLot(6)
     res = parkingLot.park("KA-01-HH-1234", "White")
     self.assertNotEqual(-1, res)
        if (bar_in.open == True):
            # 3초 동안 차단바 통과
            for i in range(3):
                bar_in.blockbar_close(False)
                time.sleep(1)
            # 차단바 통과 완료
            bar_in.blockbar_close(True)


    # 주차
    elif(a == '2'):
        # ParkingLot 객체 생성
        # ParkingLot 객체는
        # ParkingSpot 객체 리스트를 가지고 있음
        my_pklt = ParkingLot(db_path)

        print("실행할 프로세스를 선택하세요.")
        print("1. 주차하기     2. 차빼기")
        choice = input()

        mypmsdb.cur.execute("SELECT Parking_status FROM PARKINGLOT_LIST")
        spot_list = []
        for row in mypmsdb.cur:
            spot_list.append(row[0])

        pklt_empty = [] # 빈 칸 인덱스 리스트
        pklt_occu = [] # 주차된 칸 인덱스 리스트

        for i in range(len(spot_list)):
            if(spot_list[i] == 0):
'''
Created on 2014-11-29

@author: ouyangsiqi
'''
from ParkingLot import ParkingLot

parkingLot = ParkingLot()

carsCount = int(raw_input("input the count of the cars waiting to park:"))
usedCards = []
while parkingLot.allowToPark() and carsCount > 0:
    card = parkingLot.parkTheCar()
    usedCards.append(card)
    carsCount -= 1
else:
    print "the parking lot is full, the cars after NO." + str(parkingLot.getTotalSpaceCount()) + " shall be waiting for empty space."

parkingLot.showParkingStatus()
print str(parkingLot.getTotalEmptySpaceCount()) + " empty spaces left"

for card in usedCards:
    parkingLot.leaveTheCar(card)
print str(parkingLot.getTotalEmptySpaceCount()) + " empty spaces left after all the cards returned"
Пример #28
0
class TestParkingLot(unittest.TestCase):
    """
    Test class for testing parking lot
    """
    def setUp(self):
        """
        This will be called everytime a new test is run
        :return:
        """
        self.parkinglot = ParkingLot(6)

    def test_park(self):
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 1)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 2)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 3)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 4)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 5)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 6)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), PARKING_LOT_FULL)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), PARKING_LOT_FULL)

    def test_leave(self):
        self.assertEqual(self.parkinglot.leave(slot_index=1), False)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 1)
        self.assertEqual(self.parkinglot.leave(slot_index=1), True)
        self.assertEqual(self.parkinglot.leave(slot_index=1), False)
        self.assertEqual(self.parkinglot.leave(slot_index=2), False)

    def test_get_registration_numbers_for_cars_with_colour(self):
        self.assertEqual(
            self.parkinglot.get_registration_numbers_for_cars_with_colour(
                'White'), '')
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 1)
        self.assertEqual(
            self.parkinglot.get_registration_numbers_for_cars_with_colour(
                'White'), 'KA-01-HH-1234')
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1235',
                                 colour='White'), 2)
        self.assertEqual(
            self.parkinglot.get_registration_numbers_for_cars_with_colour(
                'White'), 'KA-01-HH-1234, KA-01-HH-1235')
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1235',
                                 colour='Black'), 3)
        self.assertEqual(
            self.parkinglot.get_registration_numbers_for_cars_with_colour(
                'White'), 'KA-01-HH-1234, KA-01-HH-1235')

    def test_get_slot_numbers_for_cars_with_colour(self):
        self.assertEqual(
            self.parkinglot.get_slot_numbers_for_cars_with_colour('White'), '')
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 1)
        self.assertEqual(
            self.parkinglot.get_slot_numbers_for_cars_with_colour('White'),
            '1')
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1235',
                                 colour='White'), 2)
        self.assertEqual(
            self.parkinglot.get_slot_numbers_for_cars_with_colour('White'),
            '1, 2')
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1235',
                                 colour='Black'), 3)
        self.assertEqual(
            self.parkinglot.get_slot_numbers_for_cars_with_colour('White'),
            '1, 2')

    def test_get_slot_number_for_registration_number(self):
        self.assertEqual(
            self.parkinglot.get_slot_number_for_registration_number(
                'KA-01-HH-1234'), 'Not found')
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1234',
                                 colour='White'), 1)
        self.assertEqual(
            self.parkinglot.get_slot_number_for_registration_number(
                'KA-01-HH-1234'), 1)
        self.assertEqual(
            self.parkinglot.park(registration_number='KA-01-HH-1235',
                                 colour='White'), 2)
        self.assertEqual(
            self.parkinglot.get_slot_number_for_registration_number(
                'KA-01-HH-1234'), 1)
        self.assertEqual(
            self.parkinglot.get_slot_number_for_registration_number(
                'KA-01-HH-1235'), 2)
Пример #29
0
 def test_create_parking_lot(self):
     parkingLot = ParkingLot()
     res = parkingLot.createParkingLot(6)
     self.assertEqual(6, res)
Пример #30
0
    def handle_client_traffic(self, client_socket, client_addr):
        """
        This method will handle incoming traffic from a given client.
        :param client_socket:
        :param client_addr:
        :return:
        """
        data = client_socket.recv(4096)
        packet = ParKingPacket.unpack_packet(data)

        if packet[0] is not ParKingPacket.MESSAGE_TYPE_INIT:
            self.write_to_log(
                'Something is borken!!! Expeceted INIT got : '.str(packet))
            client_socket.close()
            return

        parking_lot = ParkingLot(packet[1], packet[2], packet[3])

        while self.running:

            client_socket.settimeout(300)
            # set the timeout on the socket so that if there is no activity for 5 mintues we assume that the lot has lost
            # connectivity and cannot be reached
            try:
                data = client_socket.recv(4096)
                # print(str(data))
            except socket.timeout:
                client_socket.close()
                parking_lot.tear_down()
                self.write_to_log('client died!!! WHAT THE WHAT?!')
                return

            self.write_to_log('accepted something from client')
            if len(data) is 0:
                print('Closing client socket D:')
                client_socket.close
                return

            try:
                (message_type, lot_id, capacity,
                 vacancies) = ParKingPacket.unpack_packet(data)
            except error:
                print('struct.error')
                print('unpacking packet : ' + str(data))
            print("**********************************************")
            if message_type is ParKingPacket.MESSAGE_TYPE_ALIVE:
                print('ITS ALIVE!!!')
                continue
            elif message_type is ParKingPacket.MESSAGE_TYPE_IN:
                t = threading.Thread(target=parking_lot.goes_in, args=())
                t.daemon = True
                t.start()
                print('GOES INS')
            elif message_type is ParKingPacket.MESSAGE_TYPE_OUT:
                t = threading.Thread(target=parking_lot.goes_out, args=())
                t.daemon = True
                t.start()
                print("GOES OUTS")
            elif message_type is ParKingPacket.MESSAGE_TYPE_CLOSE:
                print('Closing connection')
                return
            else:
                print("Unrecognized message type : ".str(message_type))
Пример #31
0
 def setUp(self):
     """
     This will be called everytime a new test is run
     :return:
     """
     self.parkinglot = ParkingLot(6)
Пример #32
0
# 继承停车小弟
class SmartParkingBoy(ParkingBoy):
    def __init__(self, name):
        super().__init__(name)

    # 重写停车方法
    def park_car(self, car, parkingLotList):
        # 求出所有停车场的空车位个数
        parkingLot_free_num_list = [parkingLot.capacity - len(parkingLot.cars) for parkingLot in parkingLotList]
        if sum(parkingLot_free_num_list) <= 0:
            raise Exception("所有停车场都已经没有空位!")
        else:
            max_index = parkingLot_free_num_list.index(max(parkingLot_free_num_list))
            parkingLot = parkingLotList[max_index]
            # 返回车票
            return parkingLot.park_car(car)

if __name__ == "__main__":
    smartParkingBoy = SmartParkingBoy("tom")
    parking_lot = ParkingLot(3)
    parking_lot1 = ParkingLot(2)
    parking_lot_list = [parking_lot, parking_lot1]
    car = Car('a')
    car1 = Car('b')
    car2 = Car('c')
    parking_lot.park_car(car)
    parking_lot.park_car(car1)
    smartParkingBoy.park_car(car2,parking_lot_list)
    print([car.get_name() for car in parking_lot.cars])
    print([car.get_name() for car in parking_lot1.cars])