diff --git a/Modules/BrewRoom.Modules.Core/Models/Recipe.cs b/Modules/BrewRoom.Modules.Core/Models/Recipe.cs index 9a7aeac..d7dd120 100644 --- a/Modules/BrewRoom.Modules.Core/Models/Recipe.cs +++ b/Modules/BrewRoom.Modules.Core/Models/Recipe.cs @@ -69,21 +69,11 @@ public Volume GetBrewLength() public decimal GetStartingGravity() { var result = 0M; - var gallons = _brewLength.ConvertTo(VolumeUnit.Gallons); - var extractionEfficiency = 1M; - Parallel.ForEach(_grains, (grain) => { - var points = grain.GravityContributionInPoints; - var pounds = grain.Weight.ConvertTo(MassUnit.Pounds); - - result += points * extractionEfficiency; - - //result += points / pounds.GetValue(); + result += grain.GravityContributionInPoints; }); - var gravityUnits = result * gallons.GetValue(); - return Math.Round(1M + result / 1000M, 3); } @@ -109,7 +99,7 @@ private decimal GetHopIBUContribution(RecipeHop hop, decimal gravity) public object GetGuBuRatio() { - return GetStartingGravity() / GetIBU(); + return Math.Round(GetStartingGravity() / GetIBU(), 2); } public IList GetFermentables() diff --git a/Modules/BrewRoom.Modules.Core/Models/RecipeGrain.cs b/Modules/BrewRoom.Modules.Core/Models/RecipeGrain.cs index a2ba827..afd1225 100644 --- a/Modules/BrewRoom.Modules.Core/Models/RecipeGrain.cs +++ b/Modules/BrewRoom.Modules.Core/Models/RecipeGrain.cs @@ -94,8 +94,7 @@ private decimal CalculateGravityContributionInPoints() var pounds = _weight.ConvertTo(MassUnit.Pounds).GetValue(); var gallons = _recipe.GetBrewLength().ConvertTo(VolumeUnit.Gallons).GetValue(); - //var calculatedGravityContribution = ((pounds * points) / gallons); - var calculatedGravityContribution = points * (pounds / gallons); + var calculatedGravityContribution = (pounds * points) / gallons; return Math.Round(calculatedGravityContribution, 3); } diff --git a/Modules/Brewroom.Modules.Core.Spec/AddingIngredients.cs b/Modules/Brewroom.Modules.Core.Spec/AddingIngredients.cs index e7809fa..4da0163 100644 --- a/Modules/Brewroom.Modules.Core.Spec/AddingIngredients.cs +++ b/Modules/Brewroom.Modules.Core.Spec/AddingIngredients.cs @@ -79,12 +79,12 @@ public void ShouldCalculateStartingGravityWithMultipleGrains() var grain3 = new Grain("Two-row"); var recipe = new Recipe(); - recipe.SetBrewLength(new Volume(5.5M, VolumeUnit.Gallons)); - recipe.AddGrain(grain1, new Weight(1.87M, MassUnit.Pounds), 1.038M); - recipe.AddGrain(grain2, new Weight(1.46M, MassUnit.Pounds), 1.033M); - recipe.AddGrain(grain3, new Weight(5.92M, MassUnit.Pounds), 1.036M); + recipe.SetBrewLength(new Volume(3M, VolumeUnit.Gallons)); + recipe.AddGrain(grain1, new Weight(1M, MassUnit.Pounds), 1.045M); + recipe.AddGrain(grain2, new Weight(1M, MassUnit.Pounds), 1.045M); + recipe.AddGrain(grain3, new Weight(1M, MassUnit.Pounds), 1.046M); - Assert.AreEqual(1.049M, recipe.GetStartingGravity()); + Assert.AreEqual(1.045M, recipe.GetStartingGravity()); } [Test] @@ -98,7 +98,7 @@ public void ShouldBeAbleToClaculateTotalIBU() { var recipe = SimpleRecipe(); - Assert.AreEqual(31.2M, recipe.GetIBU()); + Assert.AreEqual(66M, recipe.GetIBU()); } private static Recipe SimpleRecipe() @@ -107,9 +107,9 @@ private static Recipe SimpleRecipe() var hop = new Hop("Saaz"); var recipe = new Recipe(); - recipe.SetBrewLength(6.Gallons()); + recipe.SetBrewLength(1.Gallons()); recipe.AddGrain(grain1, 1.Pound(), 1.045M); - recipe.AddHop(hop, new Weight(1/16M, MassUnit.Pounds), 60, 12.5M); + recipe.AddHop(hop, new Weight(10M, MassUnit.Grams), 60, 12.5M); return recipe; } @@ -118,7 +118,7 @@ public void ShouldCalculateBuGuRatio() { var recipe = SimpleRecipe(); - Assert.AreEqual(0.81M, recipe.GetGuBuRatio()); + Assert.AreEqual(0.02M, recipe.GetGuBuRatio()); } [Test]