Example #1
0
        public void TestScanMultipleItems()
        {
            ItemRule ruleForA = new ItemRule('A', 50);
            CheckOut checkout = new CheckOut(new List<IRule>() { ruleForA });

            checkout.Scan('A');
            checkout.Scan('A');
            Assert.AreEqual(100, checkout.Total);
        }
Example #2
0
        public void TestScanDifferentlyPricedItems()
        {
            ItemRule ruleForA = new ItemRule('A', 50);
            ItemRule ruleForB = new ItemRule('B', 30);

            List<IRule> myRules = new List<IRule>() { ruleForA, ruleForB };
            CheckOut checkout = new CheckOut(myRules);

            checkout.Scan('A');
            checkout.Scan('B');
            Assert.AreEqual(80, checkout.Total);
        }
Example #3
0
        public void TestScanMultipleItemsMultiPriced()
        {
            IRule ruleForA = new ItemRule('A', 50);
            IRule ruleForThreeA = new MultipriceItemRule('A', 3, 130);
            IRule ruleForB = new ItemRule('B', 30);
            IRule ruleForTwoB = new MultipriceItemRule('B', 2, 45);

            List<IRule> myRules = new List<IRule>() { ruleForA, ruleForThreeA, ruleForB, ruleForTwoB };

            CheckOut checkout = new CheckOut(myRules);
            checkout.Scan('A');
            checkout.Scan('B');
            Assert.AreEqual(80, checkout.Total);
            checkout.Scan('A');
            checkout.Scan('A');
            Assert.AreEqual(160, checkout.Total);
            checkout.Scan('B');
            Assert.AreEqual(175, checkout.Total);
            checkout.Scan('B');
            Assert.AreEqual(205, checkout.Total);
            checkout.Scan('A');
            Assert.AreEqual(255, checkout.Total);
        }
Example #4
0
        public void TestScanMultipricedItem()
        {
            IRule ruleForA = new ItemRule('A', 50);
            IRule ruleForThreeA = new MultipriceItemRule('A', 3, 130);

            List<IRule> myRules = new List<IRule>() { ruleForA, ruleForThreeA };

            CheckOut checkout = new CheckOut(myRules);
            checkout.Scan('A');
            checkout.Scan('A');
            Assert.AreEqual(100, checkout.Total);
            checkout.Scan('A');
            Assert.AreEqual(130, checkout.Total);
        }
Example #5
0
 private int price(string goods)
 {
     CheckOut checkout = new CheckOut(rules);
     foreach (char item in goods)
     {
         checkout.Scan(item);
     }
     return checkout.Total;
 }