def test_line_is_ready_one_occupant() -> None:
    """ Test line is ready with exactly one customer."""
    store = GroceryStore(GROCERY_STORE)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    store.enter_line(belinda)
    assert store.line_is_ready(0)
def test_close_line_one_customer() -> None:
    """ Test whether line with one customer returns customers on close."""
    store = GroceryStore(GROCERY_STORE)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    store.enter_line(belinda)
    assert store.close_line(0) == []
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_get_first_in_line_many() -> None:
    """ Test whether get first in line returns correct customer with
    one customer in line."""
    store = GroceryStore(GROCERY_STORE)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    store.enter_line(belinda)
    assert store.get_first_in_line(0) == belinda
def test_complete_checkout_one() -> None:
    """ Test whether customers left to checkout after checkout when
    line has one customer."""
    store = GroceryStore(GROCERY_STORE)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    store.enter_line(belinda)
    assert not store.complete_checkout(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
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
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_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)
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
예제 #11
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
예제 #12
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
예제 #13
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) == []
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]
예제 #16
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_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
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
예제 #19
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
예제 #20
0
def test_start_checkout() -> None:
    """Test the start_checkout function of the GroceryStore Class."""
    gs = GroceryStore(StringIO(ONE_LINE_FILE_CONTENTS))
    gs2 = GroceryStore(StringIO(SELF_SERVE_FILE_CONTENTS))
    c1 = Customer('A', [Item('bananas', 7), Item('apple', 2), \
                        Item('orange', 5), Item('grapes', 10)])
    c2 = Customer('B', [Item('apple', 2)])
    c3 = Customer('C', [Item('orange', 5)])
    gs.enter_line(c1)
    gs.enter_line(c2)
    gs2.enter_line(c3)
    assert gs.start_checkout(0) == 24
    assert gs2.start_checkout(0) == 10
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
예제 #22
0
def test_complete_checkout() -> None:
    """Test the complete_checkout function of the GroceryStore Class."""
    gs = GroceryStore(StringIO(SHORT_FILE_CONTENTS))
    c1 = Customer('A', [Item('bananas', 7)])
    c2 = Customer('B', [Item('apple', 2)])
    c3 = Customer('C', [Item('orange', 5)])
    c4 = Customer('D', [Item('grapes', 10)])
    gs.enter_line(c1)
    gs.enter_line(c2)
    gs.enter_line(c3)
    gs.enter_line(c4)
    assert gs.complete_checkout(0) == True
    assert gs.complete_checkout(1) == False
    assert gs.complete_checkout(2) == False
예제 #23
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
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)
예제 #25
0
    def do(self, store: GroceryStore) -> List[Event]:
        """Return a list of events representing this customer joining a line in
        GroceryStore.

        A customer cannot join a line that does not have capacity for them.
        When there are no lines the customer can join, the “new customer”
        event should go back into the container, and have its timestamp
        increased by 1 (representing trying to join a line again at the
        next time interval.)

        If a new customer joins an empty checkout line, a new
        “begin checking out” event is added with the same timestamp
        as the join event.
        """
        line_entered = store.enter_line(self.customer)
        result = []
        marker = True
        while marker is True:
            if line_entered == -1:
                self.timestamp += 1
            else:
                event = CustomerArrival(self.timestamp, self.customer)
                result.append(event)
                marker = False
        return result
예제 #26
0
def test_close_line_and_get_first_in_line() -> None:
    """Test the close_line function of the GroceryStore Class."""
    gs = GroceryStore(StringIO(ONE_LINE_FILE_CONTENTS))
    gs2 = GroceryStore(StringIO(SELF_SERVE_FILE_CONTENTS))
    c1 = Customer('A', [Item('bananas', 7)])
    c2 = Customer('B', [Item('apple', 2)])
    c3 = Customer('C', [Item('orange', 5)])
    c4 = Customer('D', [Item('grapes', 10)])
    gs.enter_line(c1)
    gs.enter_line(c2)
    gs.enter_line(c3)
    gs.enter_line(c4)
    assert gs.close_line(0) == [c2, c3, c4]
    assert gs.get_first_in_line(0) == c1
    assert gs._checkout_lines[0].queue == [c1]
    assert gs2.get_first_in_line(0) is None
def test_enter_line() -> None:
    """ Test whether customer enters correct line with empty lines."""
    store = GroceryStore(GROCERY_STORE)
    item_list = [Item('bananas', 6)]
    belinda = Customer('Belinda', item_list)
    assert len(store._lines[0]) == 0
    assert store.enter_line(belinda) == 0
    assert len(store._lines[0]) == 1
예제 #28
0
def test_line_is_ready() -> None:
    """check the method of line is ready"""
    store1 = GroceryStore(StringIO(CONFIG_FILE2))
    customer1 = Customer("bruce", [])
    assert store1.line_is_ready(0) is False
    assert store1.line_is_ready(1) is False
    assert store1.enter_line(customer1) == 0
    assert store1.line_is_ready(0) is True
    assert store1.line_is_ready(1) is False
예제 #29
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
예제 #30
0
def test_enter_line() -> None:
    """check if people can enter line correctly"""
    store1 = GroceryStore(StringIO(CONFIG_FILE))
    customer1 = Customer("bruce", [])
    customer2 = Customer("tom", [])
    customer3 = Customer("mary", [])
    customer4 = Customer("a", [])
    customer5 = Customer("b", [])
    customer6 = Customer("c", [])
    customer7 = Customer("d", [])
    customer8 = Customer("e", [])
    customer9 = Customer("f", [])
    assert store1.enter_line(customer1) == 0
    assert store1.enter_line(customer2) == 1
    assert store1.enter_line(customer3) == 2
    assert store1.enter_line(customer4) == 3
    assert store1.enter_line(customer5) == 0
    assert store1.enter_line(customer6) == 1
    assert store1.enter_line(customer7) == 2
    assert store1.enter_line(customer8) == 3
    assert store1.enter_line(customer9) == -1