def test_close_line_people_in_line() -> None: """check close line with people in line""" customer1 = Customer("bruce", []) customer2 = Customer("tom", []) customer3 = Customer("mary", []) line1 = RegularLine(3) assert line1.accept(customer1) is True assert line1.accept(customer2) is True assert line1.accept(customer3) is True assert line1.close() == [customer2, customer3] assert line1.is_open is False assert line1.queue == [customer1] assert line1.can_accept(customer2) is False line2 = ExpressLine(3) assert line2.accept(customer1) is True assert line2.accept(customer2) is True assert line2.accept(customer3) is True assert line2.close() == [customer2, customer3] assert line2.is_open is False assert line2.queue == [customer1] assert line2.can_accept(customer2) is False line3 = SelfServeLine(3) assert line3.accept(customer1) is True assert line3.accept(customer2) is True assert line3.accept(customer3) is True assert line3.close() == [customer2, customer3] assert line3.is_open is False assert line3.queue == [customer1] assert line3.can_accept(customer2) is False
def test_start_checkout_non_empty() -> None: """ Test how many customers are left when a line with a customer starts checkout.""" line = RegularLine(1) item_list = [Item('bananas', 1), Item('apples', 2), Item('kiwis', 3)] jeff = Customer('Jeff', item_list) line.accept(jeff) assert line.start_checkout() == 6
def test_close_one_customer() -> None: """ Test whether customers are returned when a line with one customer closes.""" line = RegularLine(3) item_list = [Item('bananas', 1)] jeff = Customer('Jeff', item_list) line.accept(jeff) assert line.close() == []
def test_close_line_one_customer() -> None: """ Test whether close line returns customers when only one customer is in the line.""" line = RegularLine(4) items = [Item('Bananas', 6)] c1 = Customer('Alice', items) line.accept(c1) assert line.close() == []
def test_can_accept_no_room() -> None: """ Test whether line can accept when it doesn't have room.""" line = RegularLine(1) item_list = [Item('bananas', 1), Item('bananas', 1)] jeff = Customer('Jeff', item_list) item_list_2 = [Item('bananas', 1), Item('bananas', 1)] sofia = Customer('Sofia', item_list_2) line.accept(jeff) assert not line.can_accept(sofia)
def test_checkout_len_all_get_in_line() -> None: """test the length of a line""" customer1 = Customer("bruce", []) customer2 = Customer("tom", []) customer3 = Customer("mary", []) line1 = RegularLine(10) assert line1.accept(customer1) is True assert line1.accept(customer2) is True assert line1.accept(customer3) is True assert len(line1) == 3
def test_checkout_len_one_not_get_in_line() -> None: """check the length if some customer cannot get in line""" customer1 = Customer("bruce", []) customer2 = Customer("tom", []) customer3 = Customer("mary", []) line1 = RegularLine(2) assert line1.accept(customer1) is True assert line1.accept(customer2) is True assert line1.accept(customer3) is False assert len(line1) == 2
def test_start_checkout_two_in_line() -> None: """ Test how many customers are left when a line with more than one customer starts checkout.""" line = RegularLine(2) item_list = [Item('bananas', 1), Item('bananas', 1)] jeff = Customer('Jeff', item_list) item_list_2 = [Item('bananas', 1), Item('bananas', 1)] sofia = Customer('Sofia', item_list_2) line.accept(jeff) line.accept(sofia) assert line.start_checkout() == 2
def test_accept_has_room() -> None: """ Test whether line accepts when it has room.""" line = RegularLine(1) item_list = [Item('bananas', 1), Item('bananas', 1)] jeff = Customer('Jeff', item_list) assert line.accept(jeff) assert len(line) == 1
def test_accept_closed() -> None: """ Test whether line accepts when it is closed.""" line = RegularLine(1) line.is_open = False item_list = [Item('bananas', 1), Item('bananas', 1)] jeff = Customer('Jeff', item_list) assert not line.accept(jeff)
def test_accept() -> None: """Test the accept function of the Checkout Class.""" a = RegularLine(3) b = ExpressLine(3) c = SelfServeLine(3) d = ExpressLine(3) c1 = Customer('A', [Item('bananas', 7)]) c2 = Customer('B', [Item('apple', 2)]) c3 = Customer('C', [Item('orange', 5)]) c4 = Customer('D', [Item('grapes', 10)]) c5 = Customer('E', [Item('grapes', 10)]) c6 = Customer('F', [ Item('avacado', 1), Item('avacado', 1), Item('avacado', 1), Item('avacado', 1), Item('avacado', 1), Item('avacado', 1), Item('avacado', 1), Item('avacado', 1) ]) a.queue = [c1] b.queue = [c2, c3, c4] assert a.accept(c5) == True and a.queue == [c1, c5] assert b.accept(c5) == False and b.queue == [c2, c3, c4] assert c.accept(c5) == True and c.queue == [c5] assert d.accept(c6) == False and d.queue == [] assert d.accept(c5) == True and d.queue == [c5]
def test_regular_start_checkout_test() -> None: line = RegularLine(3) c1 = Customer("John", [Item("milk", 2), Item("lid", 1), Item("fan", 3)]) c2 = Customer("Jim", [Item("milk", 2), Item("lid", 1), Item("fan", 5)]) c3 = Customer("James", [Item("milk", 2), Item("lid", 1), Item("fan", 33)]) c4 = Customer("Janice", [Item("milk", 2), Item("lid", 1), Item("fan", 23)]) for item in [c1, c2, c3, c4]: if line.can_accept(item): line.accept(item) assert line.start_checkout() == 6 assert len(line) == 3 assert line.start_checkout() == 6 assert line.complete_checkout() is True assert line.start_checkout() == 8 assert line.complete_checkout() is True assert line.start_checkout() == 36 assert line.complete_checkout() is False assert line.start_checkout() == 0 assert line.complete_checkout() is False
def test_express_accept() -> None: """ Test whether an express line accepts a customer with less than the limit of items.""" line = RegularLine(1) item_list = [] for i in range(0, EXPRESS_LIMIT - 1): item_list.append(Item('bananas', i)) jeff = Customer('Jeff', item_list) assert line.accept(jeff)
def test_complete_checkout_no_customer_left() -> None: """check complete with no customer left""" customer1 = Customer("bruce", [Item("banana", 10)]) line1 = RegularLine(3) assert line1.accept(customer1) is True assert line1.complete_checkout() is False line2 = ExpressLine(3) assert line2.accept(customer1) is True assert line2.complete_checkout() is False line3 = SelfServeLine(3) assert line3.accept(customer1) is True assert line3.complete_checkout() is False
def test_regular_customer_joining_test() -> None: line = RegularLine(3) c1 = Customer("John", [Item("milk", 2), Item("lid", 1), Item("fan", 3)]) c2 = Customer("Jim", [Item("milk", 2), Item("lid", 1), Item("fan", 3)]) c3 = Customer("James", [Item("milk", 2), Item("lid", 1), Item("fan", 3)]) c4 = Customer("Janice", [Item("milk", 2), Item("lid", 1), Item("fan", 3)]) counter = 1 for item in [c1, c2, c3, c4]: if counter in (1, 2, 3): assert line.can_accept(item) assert line.accept(item) else: assert not line.can_accept(item) assert not line.accept(item) counter += 1 assert counter == 5 assert len(line) == 3 assert c1 in line.queue assert c2 in line.queue assert c3 in line.queue assert c4 not in line.queue assert line.queue[0] is c1 assert line.queue[1] is c2 assert line.queue[2] is c3
def test_regular_close_test() -> None: line = RegularLine(4) c1 = Customer("John", [Item("milk", 2), Item("lid", 1), Item("fan", 3)]) c2 = Customer("Jim", [Item("milk", 3), Item("lid", 1), Item("fan", 3)]) c5 = Customer("James", [Item("milk", 32), Item("lid", 1), Item("fan", 3)]) c6 = Customer("Janice", [Item("milk", 42), Item("lid", 1), Item("fan", 3)]) counter = 1 for item in [c1, c2, c5, c6]: if counter <= 3: assert line.can_accept(item) assert line.accept(item) if counter == 3: assert len(line.queue) == 3 assert line.queue[0] is c1 assert line.queue[1] is c2 assert line.queue[2] is c5 assert line.close() == [c2, c5] assert c1 in line.queue assert len(line.queue) == 1 assert line.queue[0] == c1 if counter > 3: assert not line.can_accept(item) assert not line.accept(item) counter += 1
def test_close_line_one_customer_in_line() -> None: """check close line with one customer in line""" customer1 = Customer("bruce", []) line1 = RegularLine(3) assert line1.accept(customer1) is True assert line1.close() == [] assert line1.is_open is False line2 = ExpressLine(3) assert line2.accept(customer1) is True assert line2.close() == [] assert line2.is_open is False line3 = SelfServeLine(3) assert line3.accept(customer1) is True assert line3.close() == [] assert line3.is_open is False
def test_complete_checkout_two_people_in_line() -> None: """check for complete checkout with two people in line""" customer1 = Customer("bruce", [Item("banana", 10)]) customer2 = Customer("tom", [Item("banana", 10)]) line1 = RegularLine(3) assert line1.accept(customer1) is True assert line1.accept(customer2) is True assert line1.complete_checkout() is True line2 = ExpressLine(3) assert line2.accept(customer1) is True assert line2.accept(customer2) is True assert line2.complete_checkout() is True line3 = SelfServeLine(3) assert line3.accept(customer1) is True assert line3.accept(customer2) is True assert line3.complete_checkout() is True
def test_express_line_accept_over_packaged() -> None: """check if a over packaged customer can enter in line """ customer1 = Customer("bruce", [Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10),\ Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10)]) line1 = ExpressLine(2) assert line1.can_accept(customer1) is False assert line1.accept(customer1) is False assert customer1.arrival_time == -1 assert line1.queue == [] line2 = RegularLine(2) assert line2.can_accept(customer1) is True assert line2.accept(customer1) is True assert line2.queue == [customer1] line3 = SelfServeLine(2) assert line3.can_accept(customer1) is True assert line3.accept(customer1) is True assert line3.queue == [customer1]
def test_len_non_empty() -> None: """ Test length of line when it has customers.""" line = RegularLine(5) item_list = [Item('bananas', 1)] jeff = Customer('Jeff', item_list) item_list_2 = [Item('apples', 1)] sofia = Customer('Sofia', item_list_2) item_list_3 = [Item('kiwis', 1)] aela = Customer('Aela', item_list_3) line.accept(jeff) line.accept(sofia) line.accept(aela) assert len(line) == 3
def test_close_many_customers() -> None: """ Test whether correct customers are returned when line with more than one customer closes.""" line = RegularLine(3) item_list = [Item('bananas', 1)] jeff = Customer('Jeff', item_list) item_list_2 = [Item('apples', 2)] sofia = Customer('Sofia', item_list_2) item_list_3 = [Item('kiwis', 1)] aela = Customer('Aela', item_list_3) line.accept(jeff) line.accept(sofia) line.accept(aela) moved_customers = line.close() assert moved_customers == [sofia, aela]
def test_regular_line_checkout_started() -> None: """check checkout started for regular line and express line""" customer1 = Customer("bruce", [ Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10) ]) customer2 = Customer("tom", [Item("banana", 10), Item("banana", 10)]) line1 = RegularLine(3) assert line1.accept(customer1) is True assert line1.accept(customer2) is True assert line1.start_checkout() == 90 line2 = ExpressLine(3) assert line2.accept(customer1) is False assert line2.accept(customer2) is True assert line2.start_checkout() == 20
def test_checkout_cannot_accept_line_capacity_full() -> None: """check if a customer can enter a line if the line is full""" customer1 = Customer("bruce", []) customer2 = Customer("tom", []) customer3 = Customer("mary", []) line1 = RegularLine(2) assert line1.accept(customer2) assert line1.accept(customer3) assert line1.can_accept(customer1) is False assert customer1.arrival_time == -1 assert line1.queue == [customer2, customer3] line2 = ExpressLine(2) assert line2.accept(customer2) assert line2.accept(customer3) assert line2.can_accept(customer1) is False assert customer2.arrival_time == -1 assert line2.queue == [customer2, customer3] line3 = SelfServeLine(2) assert line3.accept(customer2) assert line3.accept(customer3) assert line3.can_accept(customer1) is False assert customer3.arrival_time == -1 assert line3.queue == [customer2, customer3]