コード例 #1
0
    def test10_NewCashierSetupCorrectly(self):
        """ New Customer should have lane, line, exit_pool, customer are set correctly. """
        line = []
        exit_pool = []
        cashier = PS.Cashier(1, line, exit_pool)


        self.assertEqual(cashier.lane, 1, "Lane should be set to the value passed in")
        self.assertIs(cashier.line, line, "Line should be set to the line list that is passed in.")
        self.assertIs(cashier.exit_pool, exit_pool, "exit_pool should be set to the exit pool that is passed in.")
        self.assertIs(cashier.customer, None, "Current Customer should be set to None when initialized.  There is no customer at the register")        
コード例 #2
0
    def test13_update_Cashier_customer_is_none_then_it_takes_first_customer_from_line(self):
        cust = PS.Customer(10, 1, 4)
        line = [cust]
        exit_pool = []

        cashier = PS.Cashier(4, line, exit_pool)
        clock = 2
        cashier.update(clock)

        # After the udpate the cashier should have a customer from the line.  The line should be empty now in this case.
        self.assertIs(cashier.customer, cust, "Customer from the list should now be the customer cashier.")
        self.assertEqual(len(cashier.line), 0, "When the last customer is taken out of line the line is empty")
コード例 #3
0
    def test17_update_Cashier_customer_has_items_reduced(self):
        cust = PS.Customer(12, 1, 4)
        line = [cust]
        exit_pool = []

        cashier = PS.Cashier(6, line, exit_pool)
        clock = 6

        cashier.update(clock)
        self.assertEqual(cust.items, 4, "The customer should have the initial amount of items")
        clock = clock + 1
        cashier.update(clock)
        self.assertEqual(cust.items, 3, "The current customer should have items reduced")
コード例 #4
0
    def test15_update_Cashier_customer_is_none_and_line_is_empty_no_error_is_thrown(self):
        line = []
        exit_pool = []

        cashier = PS.Cashier(4, line, exit_pool)
        clock = 4

        try:
            cashier.update(clock)   
            # After the udpate the cashier should have a customer from the line.  The line should be empty now in this case.
            self.assertIs(cashier.customer, None, "Customer from the list should now be None.")
            self.assertEqual(len(cashier.line), 0, "The line shouldn't change")
        except Exception as ex:
            self.fail("There was an error of type {} thrown when the cashier has no customer and the line is empty".format(type(ex)))
コード例 #5
0
    def test14_update_Cashier_customer_is_none_then_it_takes_first_customer_from_line_line_has_oneleft(self):
        cust = PS.Customer(10, 1, 4)
        cust2 = PS.Customer(11, 1, 4)
        line = [cust, cust2]
        exit_pool = []

        cashier = PS.Cashier(4, line, exit_pool)
        clock = 3
        cashier.update(clock)

        # After the udpate the cashier should have a customer from the line.  The line should be empty now in this case.
        self.assertIs(cashier.customer, cust, "Customer from the list should now be the customer cashier.")
        self.assertEqual(len(cashier.line), 1, "If the list had 2 customers and one gets moved to the cashier, then the line has one less")
        self.assertIs(cashier.line[0], cust2, "Only item in listis the Customer 2. ")
コード例 #6
0
    def test18_update_Cashier_customer_when_customer_items_is_zero_then_they_leave_register_and_enter_exit_pool(self):
        cust = PS.Customer(12, 2, 1)
        line = [cust]
        exit_pool = []

        cashier = PS.Cashier(6, line, exit_pool)
        clock = 7

        cashier.update(clock)
        self.assertEqual(cust.items, 1, "The customer should have the initial amount of items")
        clock = clock + 1
        cashier.update(clock)
        self.assertEqual(cust.items, 0, "The current customer should have items reduced")
        self.assertIs(cashier.customer, None, "The customer has been removed from the register")
        self.assertEqual(len(cashier.exit_pool), 1, "The exit pool should have the customer")
        self.assertIs(cashier.exit_pool[0], cust, "The customer should be in the exit pool")
コード例 #7
0
    def test16_update_Cashier_customer_is_none_then_it_takes_first_customer_from_line_and_calls_at_cashier(self):
        cust = PS.Customer(12, 1, 4)
        line = [cust]
        exit_pool = []

        cashier = PS.Cashier(6, line, exit_pool)
        clock = 5

        self.assertIs(cust.cashier_arrival, None, "The customer has not arrived at the cashier")
        self.assertIs(cust.line_exit, None, "The customer has not left the line")
        cashier.update(clock)

        # After the udpate the cashier should have a customer from the line.  The line should be empty now in this case.
        self.assertIs(cashier.customer, cust, "Customer from the list should now be the customer cashier.")
        self.assertIs(cust.cashier_arrival, clock, "The customer has not arrived at the cashier")
        self.assertIs(cust.line_exit, clock, "The customer has not left the line")
コード例 #8
0
 def test12_Cashier_string_with_customer(self):
     cashier = PS.Cashier(3, [], [])
     cust = PS.Customer(10, 12, 4)
     cashier.customer = cust
     result = str(cashier)
     self.assertEqual(result, "$(3) - C(10)", "String representation should be $() with the lane number in the parens")
コード例 #9
0
 def test11_Cashier_string_with_no_customer(self):
     cashier = PS.Cashier(2, [], [])
     result = str(cashier)
     self.assertEqual(result, "$(2)", "String representation should be $() with the lane number in the parens")