public void ShoppingCartAddApples() { const string rulesFile = "price-rules-apple.txt"; const string cartFile = "shoppingcart-5apples.txt"; const decimal expected = 27.50m; const bool compound = true; var cp = new CartProcessor(rulesFile, cartFile, compound); var cart = cartMapper.ReadShoppingList(cartFile); var rules = ruleMapper.ReadRules(rulesFile); Assert.AreEqual(expected, cp.CalculatePrice("apple", cart["apple"], rules["apple"])); }
public void TestBrokenSavingRule() { const string rulesFile = "brokenrules-saving.txt"; const string cartFile = "shoppingcart-5apples.txt"; const bool compound = true; var cp = new CartProcessor(rulesFile, cartFile, compound); var rules = ruleMapper.ReadRules(rulesFile); Assert.AreEqual(1, rules.Keys.Count); var cart = cartMapper.ReadShoppingList(cartFile); Assert.AreEqual(1, cart.Keys.Count); decimal saved; var total = cp.CalculateCartTotal(cart, rules, compound, out saved); Assert.AreEqual(5m, total); Assert.AreEqual(0m, saved); }
public void TestCalculateMultipleSavings() { const string rulesFile = "price-rules-many.txt"; const string cartFile = "shoppingcart-ApplesBananasOranges.txt"; const bool compound = true; var cp = new CartProcessor(rulesFile, cartFile, compound); var rules = ruleMapper.ReadRules(rulesFile); Assert.AreEqual(3, rules.Keys.Count); var cart = cartMapper.ReadShoppingList(cartFile); Assert.AreEqual(3, cart.Keys.Count); var savings = cp.CalculateAmountSaved(cart["apple"], rules["apple"], compound); Assert.AreEqual(10, savings); savings += cp.CalculateAmountSaved(cart["banana"], rules["banana"], compound); Assert.AreEqual(10.6m, savings); savings += cp.CalculateAmountSaved(cart["orange"], rules["orange"], compound); Assert.AreEqual(10.85m, savings); }
static void Main(string[] args) { Console.WriteLine("******************************************************"); Console.WriteLine("* _____ _____ *"); Console.WriteLine("* / ____| / ____| *"); Console.WriteLine("* | | __ _ __ ___ ___ ___ _ __ _ _| | ___ *"); Console.WriteLine("* | | |_ | '__/ _ \\ / __/ _ \\ '__| | | | | / _ \\ *"); Console.WriteLine("* | |__| | | | (_) | (_| __/ | | |_| | |___| (_) | *"); Console.WriteLine("* \\_____|_| \\___/ \\___\\___|_| \\__, |\\_____\\___/ *"); Console.WriteLine("* __/ | *"); Console.WriteLine("* |___/ *"); Console.WriteLine("******************************************************"); Console.WriteLine(); Console.WriteLine(); //read in file names Console.WriteLine("Please enter name of price rules text file (in AppData folder) or leave empty to use default:"); var ruleFile = Console.ReadLine(); Console.WriteLine("Please enter name of grocery list text file (in AppData folder) or leave empty to use default:"); var listFile = Console.ReadLine(); //or use default file names from the app.config if (string.IsNullOrWhiteSpace(ruleFile)) ruleFile = AppEnvironment.PriceRulesTextFile; if (string.IsNullOrWhiteSpace(listFile)) listFile = AppEnvironment.CartTextFile; //Process shopping cart and var cp = new CartProcessor(ruleFile, listFile, AppEnvironment.CompoundSavings); cp.CheckOut(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Console.WriteLine(); Console.WriteLine("Have a great day! Please come again!"); Thread.Sleep(2000); //Take 2 seconds to exit }
public void TestCalculateMultipleTotal() { const string rulesFile = "price-rules-many.txt"; const string cartFile = "shoppingcart-ApplesBananasOranges.txt"; const bool compound = true; var cp = new CartProcessor(rulesFile, cartFile, compound); var rules = ruleMapper.ReadRules(rulesFile); Assert.AreEqual(3, rules.Keys.Count); var cart = cartMapper.ReadShoppingList(cartFile); Assert.AreEqual(3, cart.Keys.Count); decimal saved; var total = cp.CalculateCartTotal(cart, rules, true, out saved); Assert.AreEqual(36m, total); Assert.AreEqual(10.85m, saved); }
public void TestTotalNonCompound() { const string rulesFile = "rules-compound.txt"; const string cartFile = "shoppingcart-ApplesBananasOranges.txt"; const bool compound = false; var cp = new CartProcessor(rulesFile, cartFile, compound); var rules = ruleMapper.ReadRules(rulesFile); Assert.AreEqual(3, rules.Keys.Count); var cart = cartMapper.ReadShoppingList(cartFile); Assert.AreEqual(3, cart.Keys.Count); decimal saved; var total = cp.CalculateCartTotal(cart, rules, compound, out saved); Assert.AreEqual(36m, total); Assert.AreEqual(13.25m, saved); }
public void TestSavingsNonCompoundRules() { const string rulesFile = "rules-compound.txt"; const string cartFile = "shoppingcart-ApplesBananasOranges.txt"; const bool compound = false; var cp = new CartProcessor(rulesFile, cartFile, false); var rules = ruleMapper.ReadRules(rulesFile); Assert.AreEqual(3, rules.Keys.Count); var cart = cartMapper.ReadShoppingList(cartFile); Assert.AreEqual(3, cart.Keys.Count); var savings = cp.CalculateAmountSaved(cart["apple"], rules["apple"], compound); Assert.AreEqual(10m, savings); savings += cp.CalculateAmountSaved(cart["banana"], rules["banana"], compound); Assert.AreEqual(13m, savings); savings += cp.CalculateAmountSaved(cart["orange"], rules["orange"], compound); Assert.AreEqual(13.25m, savings); }
public void TestCalculateSavings() { const string rulesFile = "price-rules-apple.txt"; const string cartFile = "shoppingcart-5apples.txt"; const decimal expected = 0m; const bool compound = true; var cp = new CartProcessor(rulesFile, cartFile, compound); var cart = cartMapper.ReadShoppingList(cartFile); var rules = ruleMapper.ReadRules(rulesFile); var savings = cp.CalculateAmountSaved(cart["apple"], rules["apple"], compound); Assert.AreEqual(expected, savings); }