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_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]
Beispiel #3
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 do(self, store: GroceryStore) -> List[Event]:
     """
     return a list of CustomerArrival events of all the other
     customers behind with timestamps have difference
     of 1, or an empty list if there is no customer behind
     """
     output = []
     self._name_list.extend(store.close_line(self.line_number))
     lens = len(self._name_list)
     for i in self._name_list:
         output.append(CustomerArrival(self.timestamp + lens, i))
         lens -= 1
     return output
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)
Beispiel #6
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_close_line_empty() -> None:
    """ Test whether empty line returns customers on close."""
    store = GroceryStore(GROCERY_STORE)
    assert store.close_line(0) == []
Beispiel #8
0
def test_close_line_no_people_in_line() -> None:
    """check close line with no people in line"""
    store1 = GroceryStore(StringIO(CONFIG_FILE4))
    assert store1.close_line(0) == []