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
예제 #2
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
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_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 do(self, store: GroceryStore) -> List[Event]:
     """
     return an empty list if there is no customer in line
     or return a CheckoutStarted event of this
     line when there is customer behind
     """
     lens = store.complete_checkout(self.line_number)
     if lens == 0:
         return []
     else:
         return [CheckoutStarted(self.timestamp, self.line_number)]
예제 #6
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)
def test_start_and_complete_check_out():
    f = StringIO(CONFIG_FILE_111_02)
    store3 = GroceryStore(f)
    lst = []
    for i in range(EXPRESS_LIMIT + 3):
        item = Item('pan', 2)
        lst.append(item)
    customer3 = Customer('a', lst)
    customer4 = Customer('b', [Item('a', 2)])
    customer5 = Customer('c', [Item('a', 20)])
    customer6 = Customer('d', [Item('a', 2)])
    customer9 = Customer('g', [Item('a', 2)])
    lst10 = []
    for i in range(EXPRESS_LIMIT + 2):
        item = Item('pan', 2)
        lst10.append(item)
    customer10 = Customer('h', lst10)
    store3.enter_line(customer4)
    store3.enter_line(customer3)
    store3.enter_line(customer5)
    store3.enter_line(customer6)
    store3.enter_line(customer10)
    store3.enter_line(customer9)
    assert store3.start_checkout(0) == 2
    assert store3.complete_checkout(0)
    assert store3.start_checkout(0) == 2
    assert not store3.complete_checkout(0)
    assert store3.start_checkout(1) == 20
    assert store3.complete_checkout(1)
    assert store3.start_checkout(1) == 2
    assert not store3.complete_checkout(1)
    assert store3.start_checkout(2) == 40
    assert store3.complete_checkout(2)
    assert store3.start_checkout(2) == 36
    assert not store3.complete_checkout(2)
    assert store3.start_checkout(0) == 0
    assert store3.start_checkout(1) == 0
    assert store3.start_checkout(2) == 0
def test_complete_checkout_empty() -> None:
    """ Test whether customers left to checkout after checkout when
    line is empty."""
    store = GroceryStore(GROCERY_STORE)
    assert not store.complete_checkout(0)
예제 #10
0
def test_complete_checkout_no_customer_behind() -> None:
    """check for the checkout method with no customer behind"""
    store1 = GroceryStore(StringIO(CONFIG_FILE4))
    customer1 = Customer("bruce", [])
    assert store1.enter_line(customer1) == 0
    assert store1.complete_checkout(0) == 0