示例#1
0
        public void TestAChoosingShortestLine()
        {
            var c1 = new Cashier(1);

            c1.EnqueueCustomer(new CustomerA(1, 10));
            c1.EnqueueCustomer(new CustomerB(2, 100));
            c1.EnqueueCustomer(new CustomerA(3, 8));

            var c2 = new Cashier(2);

            c2.EnqueueCustomer(new CustomerB(2, 10));
            c2.EnqueueCustomer(new CustomerB(2, 15));

            var c3 = new CashierTrainee(3);

            c3.EnqueueCustomer(new CustomerA(1, 9999));

            var cashiers = new HashSet <ICashier> {
                c1, c2, c3
            };

            var c             = new CustomerA(3, 1);
            var chosenCashier = c.ChooseCashier(cashiers);

            Assert.AreEqual(c3, chosenCashier);
        }
示例#2
0
        public void TestNullCashiers()
        {
            var noCashiers = new HashSet <ICashier>();

            var custA   = new CustomerA(1, 10);
            var chosenA = custA.ChooseCashier(noCashiers);

            Assert.IsNull(chosenA);

            var custB   = new CustomerA(1, 10);
            var chosenB = custB.ChooseCashier(noCashiers);

            Assert.IsNull(chosenB);
        }
示例#3
0
        public static Customer CreateCustomer(string customerLine)
        {
            if (string.IsNullOrWhiteSpace(customerLine))
            {
                return(null);
            }
            string[] tokens = customerLine.Split(SplitChars);
            if (tokens.Length < 3)
            {
                return(null);
            }
            int arrivalTime;

            if (!int.TryParse(tokens[1], out arrivalTime))
            {
                return(null);
            }
            int cartCount;

            if (!int.TryParse(tokens[2], out cartCount))
            {
                return(null);
            }

            Customer customer;

            if (tokens[0] == "A")
            {
                customer = new CustomerA(arrivalTime, cartCount);
            }
            else if (tokens[0] == "B")
            {
                customer = new CustomerB(arrivalTime, cartCount);
            }
            else
            {
                return(null);
            }

            return(customer);
        }
示例#4
0
        public static Customer CreateCustomer(string customerLine)
        {
            if (string.IsNullOrWhiteSpace(customerLine)) return null;
            string[] tokens = customerLine.Split(SplitChars);
            if (tokens.Length < 3) return null;
            int arrivalTime;
            if (!int.TryParse(tokens[1], out arrivalTime)) return null;
            int cartCount;
            if (!int.TryParse(tokens[2], out cartCount)) return null;

            Customer customer;
            if (tokens[0] == "A")
            {
                customer = new CustomerA(arrivalTime, cartCount);
            }
            else if (tokens[0] == "B")
            {
                customer = new CustomerB(arrivalTime, cartCount);
            }
            else return null;

            return customer;
        }