Exemple #1
0
        // Remove Brew from storage
        public bool Remove(Brew remBrew, int remQty)
        {
            int idx = brewBag.FindIndex(
                delegate(Brew brew)
            {
                return(brew.nm == remBrew.nm &&
                       brew.basePx == remBrew.basePx);
            }
                );

            // If some is present and there is enough qty
            if ((idx != -1) && (brewQty[idx] >= remQty))
            {
                // remove remQty
                brewQty[idx] -= remQty;

                // remove entries if new qty is zero
                if (brewQty[idx] == 0)
                {
                    brewBag.RemoveAt(idx);
                    brewQty.RemoveAt(idx);
                }

                // return true
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
 // Add a brew to the vessel
 // OUTPUT = true if added, false if not.
 public bool Add(Brew inBrew, int inQty, int inTime)
 {
     // Is the vessel empty?
     if (isEmpty())
     {
         // Is the space adequate?
         if (maxSpace >= inQty)
         {
             // Add the brew to the vessel
             storedBrew    = inBrew;
             timeRemaining = inTime;
             return(true);
         }
         else
         {
             // not enough space
             return(false);
         }
     }
     else
     {
         // not empty
         return(false);
     }
 }
Exemple #3
0
        // Add Brew to storage
        public bool Add(Brew addBrew, int addQty)
        {
            // Check if some of the ingredient is already present
            int idx = brewBag.FindIndex(
                delegate(Brew brew)
            {
                return(brew.nm == addBrew.nm &&
                       brew.basePx == addBrew.basePx);
            }
                );

            if (idx == -1)
            {
                // add new element
                brewBag.Add(addBrew);
                brewQty.Add(addQty);
            }
            else
            {
                // add to existing element
                brewQty[idx] += addQty;
            }

            return(true);
        }
Exemple #4
0
        // 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;
            }
        }
Exemple #5
0
 // 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;
 }
Exemple #6
0
 // 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;
 }
        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 TestRemoveBrew()
        {
            Brewery testBrewery = new Brewery("Casey");
            Brew testBrew = new Brew("test", 1);
            bool success;

            // Start with 10
            testBrewery.Add(testBrew, 10);

            // Remove 5
            success = testBrewery.Remove(new Brew("test", 1), 5);
            Assert.IsTrue(success);
            Assert.AreEqual(5, testBrewery.brewQty[0]);

            // Try to remove another 10
            success = testBrewery.Remove(new Brew("test", 1), 10);
            Assert.IsFalse(success);
            Assert.AreEqual(5, testBrewery.brewQty[0]);

            // Remove the final 5 and the entry is deleted
            success = testBrewery.Remove(new Brew("test", 1), 5);
            Assert.IsTrue(success);
            Assert.AreEqual(0, testBrewery.brewBag.Count);
        }
Exemple #9
0
        // 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;
            }
        }
Exemple #10
0
 // 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;
 }
Exemple #11
0
 // 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;
 }
Exemple #12
0
 // Add a brew to the vessel
 // OUTPUT = true if added, false if not.
 public bool Add(Brew inBrew, int inQty, int inTime)
 {
     // Is the vessel empty?
     if (isEmpty())
     {
         // Is the space adequate?
         if (maxSpace >= inQty)
         {
             // Add the brew to the vessel
             storedBrew = inBrew;
             timeRemaining = inTime;
             return true;
         }
         else
         {
             // not enough space
             return false;
         }
     }
     else
     {
         // not empty
         return false;
     }
 }
Exemple #13
0
        // Remove Brew from storage
        public bool Remove(Brew remBrew, int remQty)
        {
            int idx = brewBag.FindIndex(
                delegate(Brew brew)
                {
                    return (brew.nm == remBrew.nm &&
                        brew.basePx == remBrew.basePx);
                }
            );

            // If some is present and there is enough qty
            if ((idx != -1) && (brewQty[idx] >= remQty))
            {
                // remove remQty
                brewQty[idx] -= remQty;

                // remove entries if new qty is zero
                if (brewQty[idx] == 0)
                {
                    brewBag.RemoveAt(idx);
                    brewQty.RemoveAt(idx);
                }

                // return true
                return true;
            }
            else
            {
                return false;
            }
        }
Exemple #14
0
        // Add Brew to storage
        public bool Add(Brew addBrew, int addQty)
        {
            // Check if some of the ingredient is already present
            int idx = brewBag.FindIndex(
                delegate(Brew brew)
                {
                    return (brew.nm == addBrew.nm &&
                        brew.basePx == addBrew.basePx);
                }
            );

            if (idx == -1)
            {
                // add new element
                brewBag.Add(addBrew);
                brewQty.Add(addQty);
            }
            else
            {
                // add to existing element
                brewQty[idx] += addQty;
            }

            return true;
        }