예제 #1
0
        public GroceryItemRule GetPricingRule(string ruleText)
        {
            GroceryItemRule rule;

            if (ruleText.Contains("get")) //covers get one for
                rule = new BuyOneGetOneRule(ruleText);
            else if (ruleText.Contains("for")) //covers for $2.00
                rule = new GroupRule(ruleText);
            else
                rule = new PercentOffRule(ruleText);

            return rule;
        }
예제 #2
0
        public void TestingPercentDiscount()
        {
            const string rule = "50% off";

            const int expected = 100;

            var gRule = new PercentOffRule(rule);
            var saved = gRule.ProcessAmountSaved(40, 5);

            Assert.AreEqual(expected, saved);
        }