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 CreateRules()
 {
     IRule ruleForA = new ItemRule('A', 50);
     IRule ruleForB = new ItemRule('B', 30);
     IRule ruleForC = new ItemRule('C', 20);
     IRule ruleForD = new ItemRule('D', 15);
     IRule ruleForThreeA = new MultipriceItemRule('A', 3, 130);
     IRule ruleForTwoB = new MultipriceItemRule('B', 2, 45);
     rules = new List<IRule>() { ruleForA, ruleForB, ruleForC, ruleForD, ruleForThreeA, ruleForTwoB };
 }
Example #3
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 #4
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 #5
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);
        }