public void TestAdd() { Brewery testBrewery = new Brewery("Casey"); Ingredient testIngredient = new Ingredient("test", 1); Brew testBrew = new Brew("american lager"); FermVessel testFermVessel = new FermVessel(); // Empty test Assert.AreEqual(0, testBrewery.ingBag.Count); Assert.AreEqual(0, testBrewery.brewBag.Count); Assert.AreEqual(0, testBrewery.fvBag.Count); // Add ingredient testBrewery.Add(testIngredient, 20); Assert.AreEqual(1, testBrewery.ingBag.Count); Assert.AreEqual(20, testBrewery.ingQty[0]); testBrewery.Add(new Ingredient("test", 1), 20); Assert.AreEqual(1, testBrewery.ingBag.Count); Assert.AreEqual(40, testBrewery.ingQty[0]); testBrewery.Add(new Ingredient("water", 1), 20); Assert.AreEqual(2, testBrewery.ingBag.Count); Assert.AreEqual(40, testBrewery.ingQty[0]); Assert.AreEqual(20, testBrewery.ingQty[1]); // Add brew testBrewery.Add(testBrew, 20); Assert.AreEqual(1, testBrewery.brewBag.Count); Assert.AreEqual(20, testBrewery.brewQty[0]); testBrewery.Add(new Brew("american lager"), 20); Assert.AreEqual(1, testBrewery.brewBag.Count); Assert.AreEqual(40, testBrewery.brewQty[0]); Brew brew2 = new Brew("test", 1); testBrewery.Add(brew2, 20); Assert.AreEqual(2, testBrewery.brewBag.Count); Assert.AreEqual(40, testBrewery.brewQty[0]); Assert.AreEqual(20, testBrewery.brewQty[1]); // Add fermentation vessel testBrewery.Add(testFermVessel); Assert.AreEqual(1, testBrewery.fvBag.Count); testBrewery.Add(new FermVessel()); Assert.AreEqual(2, testBrewery.fvBag.Count); }
public void TestRemoveIngredient() { Brewery testBrewery = new Brewery("Casey"); Ingredient testIngredient = new Ingredient("test", 1); bool success; // Start with 10 testBrewery.Add(testIngredient, 10); // Remove 5 success = testBrewery.Remove(new Ingredient("test", 1), 5); Assert.IsTrue(success); Assert.AreEqual(5, testBrewery.ingQty[0]); // Try to remove another 10 success = testBrewery.Remove(new Ingredient("test", 1), 10); Assert.IsFalse(success); Assert.AreEqual(5, testBrewery.ingQty[0]); // Remove the final 5 and the entry is deleted success = testBrewery.Remove(new Ingredient("test", 1), 5); Assert.IsTrue(success); Assert.AreEqual(0, testBrewery.ingBag.Count); }
// Brew name constructor public Recipe(string recipe) { switch (recipe) { case "american lager": nm = recipe; ingredients = new Ingredient[4]; ingredients[0] = new Ingredient("water"); ingredients[1] = new Ingredient("malt: us barley"); ingredients[2] = new Ingredient("hops: cascade"); ingredients[3] = new Ingredient("yeast: american lager"); quantities = new int[4] { 20, 10, 2, 1 }; time = 10; output = new Brew("american lager"); brewQty = 15; break; default: Console.WriteLine("Error in Recipe({0}).", recipe); break; } }
// Detailed constructor public Recipe(string inNm, Ingredient[] inIngredients, int[] inQuantities, int inTime, Brew inOutput, int inBrewQty) { nm = inNm; ingredients = inIngredients; quantities = inQuantities; time = inTime; output = inOutput; brewQty = inBrewQty; }
// Empty constructor public Recipe() { nm = "EMPTY"; ingredients = new Ingredient[1]; ingredients[0] = new Ingredient(); quantities = new int[] { 1 }; time = 10; output = new Brew(); brewQty = 1; }
//Remove Ingredient from storage public bool Remove(Ingredient remIngredient, int remQty) { int idx = ingBag.FindIndex( delegate(Ingredient ing) { return (ing.nm == remIngredient.nm && ing.basePx == remIngredient.basePx); } ); // If some is present and there is enough qty if ((idx != -1) && (ingQty[idx] >= remQty)) { // remove remQty ingQty[idx] -= remQty; // remove entries if new qty is zero if (ingQty[idx] == 0) { ingBag.RemoveAt(idx); ingQty.RemoveAt(idx); } // return true return true; } else { return false; } }
// Add Ingredient to storage public bool Add(Ingredient addIngredient, int addQty) { // Check if some of the ingredient is already present int idx = ingBag.FindIndex( delegate(Ingredient ing) { return (ing.nm == addIngredient.nm && ing.basePx == addIngredient.basePx); } ); if (idx == -1) { // add new element ingBag.Add(addIngredient); ingQty.Add(addQty); } else { // add to existing element ingQty[idx] += addQty; } return true; }