def test_self_checkout_many_items() -> None:
    """ Test self serve line checkout time for customer with many items."""
    line = SelfServeLine(1)
    item_list = [Item('bananas', 1), Item('apples', 2), Item('kiwis', 3)]
    jeff = Customer('Jeff', item_list)
    line.accept(jeff)
    assert line.start_checkout() == 12
def test_can_accept_closed() -> None:
    """ Test whether line can accept 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.can_accept(jeff)
def test_start_checkout_non_empty() -> None:
    """ Test whether non empty line starts checkout."""
    store = GroceryStore(GROCERY_STORE)
    item_list = [Item('bananas', 6), Item('apples', 5), Item('carrots', 3)]
    belinda = Customer('Belinda', item_list)
    store.enter_line(belinda)
    assert store.start_checkout(0) == 14
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
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_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
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
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
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_customer_multi_item() -> None:
    """check for customer with several items"""
    item1 = Item("banana", 10)
    item2 = Item("apple", 2)
    item3 = Item("orange", 9)
    customer1 = Customer("bruce", [item1, item2, item3])
    assert customer1.name == "bruce"
    assert customer1.arrival_time == -1
    assert customer1._items == [item1, item2, item3]
def test_customer_init() -> None:
    """Test the Initializer of the Customer Class."""
    i1 = Item('mango', 1)
    i2 = Item('mango', 1)
    c = Customer('Anshul', [i1, i2])
    assert c.name == 'Anshul'
    assert c.arrival_time == -1
    assert c._items[0] == i1
    assert c._items[1] == i2
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_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
Exemplo n.º 14
0
def test_start_checkout_self_serve_line() -> None:
    """check for the checkout method for self serve line"""
    store1 = GroceryStore(StringIO(CONFIG_FILE3))
    item1 = Item("banana", 10)
    item2 = Item("apple", 2)
    item3 = Item("orange", 9)
    customer1 = Customer("bruce", [item1, item2, item3])
    assert store1.enter_line(customer1) == 0
    assert store1.start_checkout(0) == 42
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
def test_enter_over_express_limit() -> None:
    """ Test whether customer enters express line when they have too
    many items."""
    store = GroceryStore(GROCERY_STORE_EXPRESS)
    item_list = [Item('apples', 5)]
    for i in range(EXPRESS_LIMIT):
        item_list.append(Item('apples', i))
    arnold = Customer('Arnold', item_list)
    store.enter_line(arnold)
    assert store.enter_line(arnold) == -1
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)
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
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]
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_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
Exemplo n.º 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
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_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
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
Exemplo n.º 26
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
def test_line_is_ready_and_close():
    f = StringIO(CONFIG_FILE_100_03)
    store4 = GroceryStore(f)
    customer1 = Customer('b', [Item('a', 29)])
    customer2 = Customer('c', [Item('a', 2)])
    customer3 = Customer('d', [Item('a', 2)])
    store4.enter_line(customer1)
    assert store4.line_is_ready(0)
    store4.enter_line(customer2)
    store4.enter_line(customer3)
    assert len(store4.close_line(0)) == 2
    assert store4.line_is_ready(0)
    assert store4.start_checkout(0) == 29
    assert not store4.complete_checkout(0)
    assert not store4.line_is_ready(0)
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_customer_one_item() -> None:
    """check for customer with one item"""
    item1 = Item("banana", 10)
    customer1 = Customer("bruce", [item1])
    assert customer1.name == "bruce"
    assert customer1.arrival_time == -1
    assert customer1._items == [item1]
def test_complete() -> None:
    customer = Customer("test1", [
        Item('apple\\34', 34),
        Item('apple\\43', 43),
        Item('apple\\567', 567),
        Item('apple\\785', 785)
    ])
    assert customer.arrival_time == -1
    assert customer.name == "test1"
    for item in customer._items:
        lst = item.name.split('\\')
        assert lst[0].isalpha()
        assert lst[1].isnumeric()
        assert item.get_time() == int(lst[1])
    assert customer.num_items() == 4
    assert customer.get_item_time() == 77 + 567 + 785