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
Exemple #2
0
def test_checkout_can_accept_basic() -> None:
    """check for can accept"""
    customer1 = Customer("bruce", [])
    line1 = RegularLine(3)
    assert line1.can_accept(customer1) is True
    line2 = ExpressLine(3)
    assert line2.can_accept(customer1) is True
    line3 = SelfServeLine(3)
    assert line3.can_accept(customer1) is True
def test_express_too_many_items() -> None:
    """ Test whether an express line accepts a customer with more than the limit
     of items."""
    line = ExpressLine(1)
    item_list = []

    for i in range(0, EXPRESS_LIMIT + 2):
        item_list.append(Item('bananas', i))

    jeff = Customer('Jeff', item_list)
    assert not line.accept(jeff)
Exemple #4
0
def test_close_line_no_one_in_line() -> None:
    """check close line with no one in line"""
    line1 = RegularLine(3)
    assert line1.close() == []
    assert line1.is_open is False
    line2 = ExpressLine(3)
    assert line2.close() == []
    assert line2.is_open is False
    line3 = SelfServeLine(3)
    assert line3.close() == []
    assert line3.is_open is False
Exemple #5
0
def test_checkout_cannot_accept_when_line_is_closed() -> None:
    """check if a customer can enter a line if line is closed"""
    customer1 = Customer("bruce", [])
    line1 = RegularLine(3)
    line1.is_open = False
    assert line1.can_accept(customer1) is False
    line2 = SelfServeLine(3)
    line2.is_open = False
    assert line2.can_accept(customer1) is False
    line3 = ExpressLine(3)
    line3.is_open = False
    assert line3.can_accept(customer1) is False
Exemple #6
0
def test_complete_checkout_no_customer_left() -> None:
    """check complete with no customer left"""
    customer1 = Customer("bruce", [Item("banana", 10)])
    line1 = RegularLine(3)
    assert line1.accept(customer1) is True
    assert line1.complete_checkout() is False
    line2 = ExpressLine(3)
    assert line2.accept(customer1) is True
    assert line2.complete_checkout() is False
    line3 = SelfServeLine(3)
    assert line3.accept(customer1) is True
    assert line3.complete_checkout() is False
Exemple #7
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
Exemple #8
0
def test_close_line_one_customer_in_line() -> None:
    """check close line with one customer in line"""
    customer1 = Customer("bruce", [])
    line1 = RegularLine(3)
    assert line1.accept(customer1) is True
    assert line1.close() == []
    assert line1.is_open is False
    line2 = ExpressLine(3)
    assert line2.accept(customer1) is True
    assert line2.close() == []
    assert line2.is_open is False
    line3 = SelfServeLine(3)
    assert line3.accept(customer1) is True
    assert line3.close() == []
    assert line3.is_open is False
Exemple #9
0
def test_complete_checkout_two_people_in_line() -> None:
    """check for complete checkout with two people in line"""
    customer1 = Customer("bruce", [Item("banana", 10)])
    customer2 = Customer("tom", [Item("banana", 10)])
    line1 = RegularLine(3)
    assert line1.accept(customer1) is True
    assert line1.accept(customer2) is True
    assert line1.complete_checkout() is True
    line2 = ExpressLine(3)
    assert line2.accept(customer1) is True
    assert line2.accept(customer2) is True
    assert line2.complete_checkout() is True
    line3 = SelfServeLine(3)
    assert line3.accept(customer1) is True
    assert line3.accept(customer2) is True
    assert line3.complete_checkout() is True
Exemple #10
0
def test_express_line_accept_over_packaged() -> None:
    """check if a over packaged customer can enter in line """
    customer1 = Customer("bruce", [Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10),\
                                   Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10), Item("banana", 10)])
    line1 = ExpressLine(2)
    assert line1.can_accept(customer1) is False
    assert line1.accept(customer1) is False
    assert customer1.arrival_time == -1
    assert line1.queue == []
    line2 = RegularLine(2)
    assert line2.can_accept(customer1) is True
    assert line2.accept(customer1) is True
    assert line2.queue == [customer1]
    line3 = SelfServeLine(2)
    assert line3.can_accept(customer1) is True
    assert line3.accept(customer1) is True
    assert line3.queue == [customer1]
Exemple #11
0
def test_complete_checkout() -> None:
    """Test the complete_checkout function of the Checkout Class."""
    a = RegularLine(3)
    b = ExpressLine(3)
    c = SelfServeLine(3)
    c1 = Customer('A', [Item('bananas', 7)])
    c2 = Customer('B', [])
    c3 = Customer('C', [Item('orange', 5)])
    c4 = Customer('D', [Item('grapes', 10), Item('avacado', 1)])
    a.queue = [c1]
    b.queue = [c2, c3]
    c.queue = [c4]
    assert a.complete_checkout() == False and a.queue == []
    a.queue = [c2, c1]
    assert a.complete_checkout() == True and a.queue == [c1]
    assert b.complete_checkout() == True and b.queue == [c3]
    assert c.complete_checkout() == False and c.queue == []
Exemple #12
0
def test_close() -> None:
    """Test the close function of the Checkout Class."""
    a = RegularLine(3)
    b = ExpressLine(3)
    c = SelfServeLine(3)
    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 a.close() == [] and a.is_open == False
    assert b.close() == [c3, c4] and a.is_open == False
    assert c.close() == [] and a.is_open == False
    assert a.queue == [c1]
    assert b.queue == [c2]
    assert c.queue == []
Exemple #13
0
def test_accept() -> None:
    """Test the accept function of the Checkout Class."""
    a = RegularLine(3)
    b = ExpressLine(3)
    c = SelfServeLine(3)
    d = ExpressLine(3)
    c1 = Customer('A', [Item('bananas', 7)])
    c2 = Customer('B', [Item('apple', 2)])
    c3 = Customer('C', [Item('orange', 5)])
    c4 = Customer('D', [Item('grapes', 10)])
    c5 = Customer('E', [Item('grapes', 10)])
    c6 = Customer('F', [
        Item('avacado', 1),
        Item('avacado', 1),
        Item('avacado', 1),
        Item('avacado', 1),
        Item('avacado', 1),
        Item('avacado', 1),
        Item('avacado', 1),
        Item('avacado', 1)
    ])
    a.queue = [c1]
    b.queue = [c2, c3, c4]
    assert a.accept(c5) == True and a.queue == [c1, c5]
    assert b.accept(c5) == False and b.queue == [c2, c3, c4]
    assert c.accept(c5) == True and c.queue == [c5]
    assert d.accept(c6) == False and d.queue == []
    assert d.accept(c5) == True and d.queue == [c5]
Exemple #14
0
def test_close_line_people_in_line() -> None:
    """check close line with people in line"""
    customer1 = Customer("bruce", [])
    customer2 = Customer("tom", [])
    customer3 = Customer("mary", [])
    line1 = RegularLine(3)
    assert line1.accept(customer1) is True
    assert line1.accept(customer2) is True
    assert line1.accept(customer3) is True
    assert line1.close() == [customer2, customer3]
    assert line1.is_open is False
    assert line1.queue == [customer1]
    assert line1.can_accept(customer2) is False
    line2 = ExpressLine(3)
    assert line2.accept(customer1) is True
    assert line2.accept(customer2) is True
    assert line2.accept(customer3) is True
    assert line2.close() == [customer2, customer3]
    assert line2.is_open is False
    assert line2.queue == [customer1]
    assert line2.can_accept(customer2) is False
    line3 = SelfServeLine(3)
    assert line3.accept(customer1) is True
    assert line3.accept(customer2) is True
    assert line3.accept(customer3) is True
    assert line3.close() == [customer2, customer3]
    assert line3.is_open is False
    assert line3.queue == [customer1]
    assert line3.can_accept(customer2) is False
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
Exemple #16
0
def test_regular_line_checkout_started() -> None:
    """check checkout started for regular line and express line"""
    customer1 = Customer("bruce", [
        Item("banana", 10),
        Item("banana", 10),
        Item("banana", 10),
        Item("banana", 10),
        Item("banana", 10),
        Item("banana", 10),
        Item("banana", 10),
        Item("banana", 10),
        Item("banana", 10)
    ])
    customer2 = Customer("tom", [Item("banana", 10), Item("banana", 10)])
    line1 = RegularLine(3)
    assert line1.accept(customer1) is True
    assert line1.accept(customer2) is True
    assert line1.start_checkout() == 90
    line2 = ExpressLine(3)
    assert line2.accept(customer1) is False
    assert line2.accept(customer2) is True
    assert line2.start_checkout() == 20
Exemple #17
0
def test_checkout_cannot_accept_line_capacity_full() -> None:
    """check if a customer can enter a line if the line is full"""
    customer1 = Customer("bruce", [])
    customer2 = Customer("tom", [])
    customer3 = Customer("mary", [])
    line1 = RegularLine(2)
    assert line1.accept(customer2)
    assert line1.accept(customer3)
    assert line1.can_accept(customer1) is False
    assert customer1.arrival_time == -1
    assert line1.queue == [customer2, customer3]
    line2 = ExpressLine(2)
    assert line2.accept(customer2)
    assert line2.accept(customer3)
    assert line2.can_accept(customer1) is False
    assert customer2.arrival_time == -1
    assert line2.queue == [customer2, customer3]
    line3 = SelfServeLine(2)
    assert line3.accept(customer2)
    assert line3.accept(customer3)
    assert line3.can_accept(customer1) is False
    assert customer3.arrival_time == -1
    assert line3.queue == [customer2, customer3]
Exemple #18
0
def test_CheckoutLine_init() -> None:
    """Test the Initializer of the Checkout Class."""
    a = RegularLine(15)
    b = ExpressLine(10)
    c = SelfServeLine(5)
    assert a.capacity == 15
    assert a.queue == []
    assert a.is_open is True
    assert b.capacity == 10
    assert b.queue == []
    assert b.is_open is True
    assert c.capacity == 5
    assert c.queue == []
    assert c.is_open is True
Exemple #19
0
def test_checkout_basic() -> None:
    """check for basic value of attribute"""
    line1 = RegularLine(3)
    assert line1.capacity == 3
    assert line1.is_open is True
    assert line1.queue == []
    line2 = SelfServeLine(3)
    assert line2.capacity == 3
    assert line2.is_open is True
    assert line2.queue == []
    line3 = ExpressLine(3)
    assert line3.capacity == 3
    assert line3.is_open is True
    assert line3.queue == []
def test_express_joining_in_extreme() -> 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 + 1):
        lst2.append(Item("Item_2" + str(i), 1))
    for i in range(EXPRESS_LIMIT + 1):
        lst3.append(Item("Item_3" + str(i), 1))

    c1 = Customer("Jon", lst2)
    c2 = Customer("James", lst3)
    c3 = Customer("Janice", lst)
    for item in [c1, c2, c3]:
        assert not line.can_accept(item)
        assert not line.accept(item)

    assert len(line) == 0
    assert line.capacity == 3
    assert c1 not in line.queue
    assert c2 not in line.queue
    assert c3 not in line.queue
def test_children_init() -> None:
    """ Test all three line types for correct initialization.
    """
    line1 = RegularLine(5)
    assert line1.capacity == 5
    assert line1.is_open
    assert line1.queue == []
    line2 = ExpressLine(5)
    assert line2.capacity == 5
    assert line2.is_open
    assert line2.queue == []
    line3 = SelfServeLine(5)
    assert line3.capacity == 5
    assert line3.is_open
    assert line3.queue == []
def test_express_customer_coming_test() -> None:
    line = ExpressLine(3)
    lst = []
    for i in range(EXPRESS_LIMIT + 1):
        lst.append(Item("lid", 1))
    c1 = Customer("Jameson", lst)
    c2 = Customer("Jim", [Item("milk", 2), Item("lid", 1), Item("fan", 3)])
    c3 = Customer("Jon", [Item("milk", 2), Item("lid", 1), Item("fan", 3)])
    c4 = Customer("James", [Item("milk", 2), Item("lid", 1), Item("fan", 3)])
    c5 = Customer("Janice", [Item("milk", 2), Item("lid", 1), Item("fan", 3)])
    counter = 1
    for item in [c1, c2, c3, c4, c5]:
        if counter == 1:
            assert not line.can_accept(item)
        elif item.num_items() <= EXPRESS_LIMIT:
            assert line.can_accept(item)
        else:
            assert not line.can_accept(item)
        counter += 1

    line.close()
    for item in [c1, c2, c3, c4, c5]:
        assert not line.can_accept(item)
def test_express_close_test() -> None:
    line = ExpressLine(4)
    lst = []
    lst2 = []
    lst3 = []
    lst4 = []
    lst5 = []
    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))
    for i in range(EXPRESS_LIMIT):
        lst4.append(Item("lid", 100))
    counter = 1
    c1 = Customer("Jon", lst2)
    c2 = Customer("James", lst3)
    c3 = Customer("Janice", lst)
    c4 = Customer("Johnny", lst4)
    for item in [c1, c2, c3, c4]:
        if counter <= 3:
            assert line.can_accept(item)
            assert line.accept(item)
        if counter == 3:
            assert len(line.queue) == 3
            assert line.queue[0] is c1
            assert line.queue[1] is c2
            assert line.queue[2] is c3
            assert line.close() == [c2, c3]
            assert c1 in line.queue
            assert len(line.queue) == 1
            assert line.queue[0] == c1
        if counter > 3:
            assert not line.can_accept(item)
            assert not line.accept(item)
        counter += 1
Exemple #24
0
def test_start_checkout() -> None:
    """Test the start_checkout function of the Checkout Class."""
    a = RegularLine(3)
    b = ExpressLine(3)
    c = SelfServeLine(3)
    c1 = Customer('A', [Item('bananas', 7)])
    c2 = Customer('B', [])
    c3 = Customer('C', [Item('orange', 5)])
    c4 = Customer('D', [Item('grapes', 10), Item('avacado', 1)])
    a.queue = [c1]
    b.queue = [c2, c3]
    c.queue = [c4]
    assert a.start_checkout() == 7
    a.queue = [c1, c2]
    assert a.start_checkout() == 7
    assert b.start_checkout() == 0
    b.queue = [c3]
    assert b.start_checkout() == 5
    assert c.start_checkout() == 22
    c.queue = [c1, c2, c3, c4]
    assert c.start_checkout() == 14
def test_express_start_checkout_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 - 1):
        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)
    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 len(line.queue) == 2
    assert line.capacity == 3
    assert line.queue[0] is c1
    assert line.queue[1] is c2
    assert line.start_checkout() == EXPRESS_LIMIT - 1
    assert len(line) == 2
    assert line.start_checkout() == EXPRESS_LIMIT - 1
    assert line.complete_checkout() is True
    assert line.start_checkout() == 2 * EXPRESS_LIMIT
    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_express_init_() -> None:
    line = ExpressLine(3)
    assert len(line) == 0
    assert line.is_open == True
    assert len(line.queue) == 0
def test_express_empty_line() -> None:
    line = ExpressLine(3)
    assert line.complete_checkout() is False
    assert line.start_checkout() == 0