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_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 do(self, store: GroceryStore) -> List[Event]: """ return a CheckoutComplete event of this customer """ return [CheckoutCompleted(self.timestamp + store.start_checkout\ (self.line_number), self.line_number,\ store.get_first_in_line(self.line_number))]
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_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_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
def do(self, store: GroceryStore) -> List[Event]: """ return a CustomerArrival event if this customer cannot get in line with the timestamp plus one, return CheckoutStarted event if the line is empty or return an empty list if this customer is wait in line """ self._line_num = GroceryStore.enter_line(store, self.customer) if self._line_num == -1: self.timestamp += 1 return [CustomerArrival(self.timestamp, self.customer)] else: self.customer.arrival_time = self.timestamp if store.get_first_in_line(self._line_num) == self.customer: return [CheckoutStarted(self.timestamp, self._line_num)] else: return []
def test_get_first_in_line_empty() -> None: """ Test whether get first in line returns correct customer with empty line.""" store = GroceryStore(GROCERY_STORE) assert store.get_first_in_line(0) is None
def test_get_first_in_line_no_one_in_line() -> None: """che get first method with no person in line""" store1 = GroceryStore(StringIO(CONFIG_FILE4)) assert store1.get_first_in_line(0) is None