コード例 #1
0
def test_express_normal_test_for_close_test() -> None:
    line = ExpressLine(2)
    lst = []
    lst2 = []
    lst3 = []
    for i in range(EXPRESS_LIMIT):
        lst.append(Item("lid", 10))
    for i in range(EXPRESS_LIMIT):
        lst2.append(Item("Item_2" + str(i), 1))
    for i in range(EXPRESS_LIMIT):
        lst3.append(Item("Item_3" + str(i), 2))

    c1 = Customer("Jon", lst2)
    c2 = Customer("James", lst3)
    c3 = Customer("Janice", lst)
    for item in [c1, c2, c3]:
        line.accept(item)
    assert len(line.queue) == line.capacity
    assert line.capacity == 2
    assert line.queue[0] is c1
    assert line.queue[1] is c2
    assert line.start_checkout() == EXPRESS_LIMIT
    assert line.complete_checkout() is True
    assert line.start_checkout() == EXPRESS_LIMIT * 2
    assert line.complete_checkout() is False
    assert line.start_checkout() == 0
    assert len(line) == 0
    assert len(line.queue) == 0
    assert line.complete_checkout() is False
コード例 #2
0
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
コード例 #3
0
def test_express_customer_joining_test() -> None:
    line = ExpressLine(3)
    lst = []
    lst2 = []
    lst3 = []
    for i in range(EXPRESS_LIMIT + 1):
        lst.append(Item("lid", 1))
    for i in range(EXPRESS_LIMIT):
        lst2.append(Item("Item_2" + str(i), 1))
    for i in range(EXPRESS_LIMIT):
        lst3.append(Item("Item_3" + str(i), 1))

    c1 = Customer("Jon", lst2)
    c2 = Customer("James", lst3)
    c3 = Customer("Janice", lst)
    counter = 1
    for item in [c1, c2, c3]:
        if counter in (1, 2):
            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 == 4
    assert len(line) == 2
    assert line.capacity == 3
    assert c1 in line.queue
    assert c2 in line.queue
    assert c3 not in line.queue
    assert line.queue[0] is c1
    assert line.queue[1] is c2
コード例 #4
0
def test_customer_num_items_empty() -> None:
    """ Test customer num_items when customer has no items.

    """
    item_list = []
    belinda = Customer('Belinda', item_list)
    assert belinda.num_items() == 0
コード例 #5
0
def test_item_time_no_items() -> None:
    """ Test customer get_item_time when customer has no items.

    """
    item_list = []
    belinda = Customer('Belinda', item_list)
    assert belinda.get_item_time() == 0
コード例 #6
0
def test_customer_num_items_with_multi_item() -> None:
    """check num item method with several items"""
    item1 = Item("banana", 10)
    item2 = Item("apple", 2)
    item3 = Item("orange", 9)
    customer1 = Customer("bruce", [item1, item2, item3])
    assert customer1.num_items() == 3
コード例 #7
0
def test_get_item_time_with_multi_item() -> None:
    """check get item time method with several items"""
    item1 = Item("banana", 10)
    item2 = Item("apple", 2)
    item3 = Item("orange", 9)
    customer1 = Customer("bruce", [item1, item2, item3])
    assert customer1.get_item_time() == 21
コード例 #8
0
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)
コード例 #9
0
def test_enter_first_occupied() -> None:
    """ Test whether customer enters correct line when first is occupied."""
    store = GroceryStore(GROCERY_STORE)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    item_list_2 = [Item('apples', 5)]
    arnold = Customer('Arnold', item_list_2)
    store.enter_line(arnold)
    assert store.enter_line(belinda) == 1
コード例 #10
0
def test_enter_line_lines_full() -> None:
    """ Test whether customer enters line with full line(s)."""
    store = GroceryStore(GROCERY_STORE_1_LINE_1_CAP)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    item_list_2 = [Item('apples', 5)]
    arnold = Customer('Arnold', item_list_2)
    store.enter_line(arnold)
    assert store.enter_line(belinda) == -1
コード例 #11
0
def test_item_time_many_items() -> None:
    """ Test customer get_item_time when customer has many items.

    """
    item_list = [Item('bananas', 1), Item('apples', 2), Item('kiwis', 3),
                 Item('strawberries', 4), Item('guavas', 5), Item('oranges', 6)]
    belinda = Customer('Belinda', item_list)
    assert belinda.get_item_time() == 21
    assert len(belinda._items) == 6
コード例 #12
0
def test_complete_checkout_more() -> None:
    """ Test whether customers left to checkout after checkout when
    line is empty."""
    store = GroceryStore(GROCERY_STORE_1_LINE_2_CAP)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    charlie = Customer('Charlie', item_list)
    store.enter_line(belinda)
    store.enter_line(charlie)
    assert store.complete_checkout(0)
コード例 #13
0
def test_is_ready_more_occupants() -> None:
    """ Test line is ready with more than one customer."""
    store = GroceryStore(GROCERY_STORE_1_LINE_2_CAP)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    item_list_2 = [Item('apples', 5)]
    arnold = Customer('Arnold', item_list_2)
    store.enter_line(belinda)
    store.enter_line(arnold)
    assert not store.line_is_ready(0)
コード例 #14
0
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
コード例 #15
0
def test_cannot_enter_line() -> None:
    """test for when the line capacity is full"""
    store1 = GroceryStore(StringIO(CONFIG_FILE2))
    customer1 = Customer("bruce", [])
    customer2 = Customer("tom", [])
    customer3 = Customer("mary", [])
    assert store1.enter_line(customer1) == 0
    assert store1.enter_line(customer2) == 1
    assert store1.enter_line(customer3) == -1
    assert customer3.arrival_time == -1
コード例 #16
0
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
コード例 #17
0
def test_close_line_people_in_line() -> None:
    """check close line with people in line"""
    store1 = GroceryStore(StringIO(CONFIG_FILE4))
    customer1 = Customer("bruce", [])
    customer2 = Customer("tom", [])
    customer3 = Customer("mary", [])
    assert store1.enter_line(customer1) == 0
    assert store1.enter_line(customer2) == 1
    assert store1.enter_line(customer3) == 0
    assert store1.close_line(0) == [customer3]
    assert store1.close_line(1) == []
コード例 #18
0
def test_get_first_in_line_one() -> None:
    """ Test whether get first in line returns correct customer with
    more than one customer in line."""
    store = GroceryStore(GROCERY_STORE_1_LINE_2_CAP)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    store.enter_line(belinda)
    item_list_2 = [Item('cherries', 5)]
    charlie = Customer('Charlie', item_list_2)
    store.enter_line(charlie)
    assert store.get_first_in_line(0) == belinda
コード例 #19
0
def test_close_line_more_occupants() -> None:
    """ Test whether line with more than one customer returns correct
    customers on close."""
    store = GroceryStore(GROCERY_STORE_1_LINE_2_CAP)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    store.enter_line(belinda)
    item_list_2 = [Item('cherries', 5)]
    charlie = Customer('Charlie', item_list_2)
    store.enter_line(charlie)
    assert store.close_line(0) == [charlie]
コード例 #20
0
def test_get_first_in_line() -> None:
    """check get first method"""
    store1 = GroceryStore(StringIO(CONFIG_FILE4))
    customer1 = Customer("bruce", [])
    customer2 = Customer("tom", [])
    customer3 = Customer("mary", [])
    assert store1.enter_line(customer1) == 0
    assert store1.enter_line(customer2) == 1
    assert store1.enter_line(customer3) == 0
    assert store1.get_first_in_line(0) == customer1
    assert store1.get_first_in_line(1) == customer2
コード例 #21
0
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
コード例 #22
0
def test_start_checkout_normal_line() -> None:
    """check the checkout for normal line"""
    store1 = GroceryStore(StringIO(CONFIG_FILE2))
    item1 = Item("banana", 10)
    item2 = Item("apple", 2)
    item3 = Item("orange", 9)
    customer1 = Customer("bruce", [item1, item2, item3])
    customer2 = Customer("tom", [item1, item2, item3])
    assert store1.enter_line(customer1) == 0
    assert store1.start_checkout(0) == 21
    assert store1.enter_line(customer2) == 1
    assert store1.start_checkout(1) == 21
コード例 #23
0
def test_get_first_in_line():
    f = StringIO(CONFIG_FILE_100_03)
    store4 = GroceryStore(f)
    customer1 = Customer('b', [Item('a', 29)])
    customer2 = Customer('c', [Item('a', 2)])
    store4.enter_line(customer1)
    store4.enter_line(customer2)
    assert store4.get_first_in_line(0) == customer1
    assert store4.complete_checkout(0)
    assert store4.get_first_in_line(0) == customer2
    assert not store4.complete_checkout(0)
    assert store4.get_first_in_line(0) is None
コード例 #24
0
def test_regular_customer_coming_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("Jon", [Item("milk", 2), Item("lid", 1), Item("fan", 3)])
    c4 = Customer("James", [Item("milk", 2), Item("lid", 1), Item("fan", 3)])
    c5 = Customer("Janice", [Item("milk", 2), Item("lid", 1), Item("fan", 3)])
    for item in [c1, c2, c3, c4, c5]:
        assert line.can_accept(item)
    line.close()
    for item in [c1, c2, c3, c4, c5]:
        assert not line.can_accept(item)
コード例 #25
0
def test_enter_line_lines_occupied() -> None:
    """ Test whether customer enters a line with another customer in it."""
    store = GroceryStore(GROCERY_STORE_2_LINES_2_CAP)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    item_list_2 = [Item('apples', 5)]
    arnold = Customer('Arnold', item_list_2)
    item_list_3 = [Item('carrots', 3)]
    charlie = Customer('Charlie', item_list_3)
    store.enter_line(arnold)
    store.enter_line(belinda)
    assert store.enter_line(charlie) == 0
    assert len(store._lines[0]) == 2
コード例 #26
0
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
コード例 #27
0
def test_enter_line2() -> None:
    """check if people can enter line correctly."""
    store = GroceryStore(StringIO(CONFIG_FILE2))
    customer1 = Customer('bruce', [])
    customer2 = Customer('tom', [Item('banana', 1), Item('banana', 1), Item('banana', 1),
                                 Item('banana', 1), Item('banana', 1), Item('banana', 1),
                                 Item('banana', 1), Item('banana', 1)])
    customer3 = Customer('jerry', [])
    customer4 = Customer('mary', [])
    assert store.enter_line(customer1) == 0
    assert store.enter_line(customer2) == -1
    assert store.enter_line(customer3) == 1
    assert store.enter_line(customer4) == -1
コード例 #28
0
def test_CheckoutLine_len() -> None:
    """Test the __len__ function of the Checkout Class."""
    a = RegularLine(15)
    b = ExpressLine(10)
    c = SelfServeLine(5)
    c1 = Customer('A', [Item('bananas', 7)])
    c2 = Customer('B', [Item('apple', 2)])
    c3 = Customer('C', [Item('orange', 5)])
    c4 = Customer('D', [Item('grapes', 10)])
    a.queue = [c1]
    b.queue = [c2, c3, c4]
    assert len(a) == 1
    assert len(b) == 3
    assert len(c) == 0
コード例 #29
0
def test_enter_line():
    f = StringIO(CONFIG_FILE_000_00)
    store1 = GroceryStore(f)
    customer = Customer('Chris', [Item('bread', 3)])
    assert store1.enter_line(customer) == -1
    f.close()
    f = StringIO(CONFIG_FILE_010_01)
    store2 = GroceryStore(f)
    lst = []
    for i in range(EXPRESS_LIMIT + 2):
        item = Item('pan', 2)
        lst.append(item)
    customer1 = Customer("Owen", lst)
    assert store2.enter_line(customer1) == -1
コード例 #30
0
def test_complete_checkout_with_customer_behind() -> None:
    """check complete with customers behind"""
    store1 = GroceryStore(StringIO(CONFIG_FILE4))
    customer1 = Customer("bruce", [])
    customer2 = Customer("tom", [])
    customer3 = Customer("mary", [])
    customer4 = Customer("jams", [])
    customer5 = Customer("jerry", [])
    assert store1.enter_line(customer1) == 0
    assert store1.enter_line(customer2) == 1
    assert store1.enter_line(customer3) == 0
    assert store1.enter_line(customer4) == 1
    assert store1.enter_line(customer5) == 0
    assert store1.complete_checkout(0) == 2
    assert store1.complete_checkout(1) == 1