Skip to content
Browse files

Fixed failing test for gravity contribution

Signed-off-by: Damian Jones <damianajones@yahoo.co.uk>
  • Loading branch information...
1 parent e52d5c3 commit 73e85ebe4d47f1e3ecb718f70520826bd26c1f4f @Jonsey committed Nov 30, 2011
View
14 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<RecipeGrain> GetFermentables()
View
3 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);
}
View
18 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]

0 comments on commit 73e85eb

Please sign in to comment.
Something went wrong with that request. Please try again.