Skip to content

Commit

Permalink
Fixed failing test for gravity contribution
Browse files Browse the repository at this point in the history
Signed-off-by: Damian Jones <damianajones@yahoo.co.uk>
  • Loading branch information
Jonsey committed Nov 30, 2011
1 parent e52d5c3 commit 73e85eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
14 changes: 2 additions & 12 deletions Modules/BrewRoom.Modules.Core/Models/Recipe.cs
Expand Up @@ -69,21 +69,11 @@ public Volume GetBrewLength()
public decimal GetStartingGravity() public decimal GetStartingGravity()
{ {
var result = 0M; var result = 0M;
var gallons = _brewLength.ConvertTo(VolumeUnit.Gallons);
var extractionEfficiency = 1M;

Parallel.ForEach(_grains, (grain) => Parallel.ForEach(_grains, (grain) =>
{ {
var points = grain.GravityContributionInPoints; result += grain.GravityContributionInPoints;
var pounds = grain.Weight.ConvertTo(MassUnit.Pounds);
result += points * extractionEfficiency;
//result += points / pounds.GetValue();
}); });


var gravityUnits = result * gallons.GetValue();

return Math.Round(1M + result / 1000M, 3); return Math.Round(1M + result / 1000M, 3);
} }


Expand All @@ -109,7 +99,7 @@ private decimal GetHopIBUContribution(RecipeHop hop, decimal gravity)


public object GetGuBuRatio() public object GetGuBuRatio()
{ {
return GetStartingGravity() / GetIBU(); return Math.Round(GetStartingGravity() / GetIBU(), 2);
} }


public IList<RecipeGrain> GetFermentables() public IList<RecipeGrain> GetFermentables()
Expand Down
3 changes: 1 addition & 2 deletions Modules/BrewRoom.Modules.Core/Models/RecipeGrain.cs
Expand Up @@ -94,8 +94,7 @@ private decimal CalculateGravityContributionInPoints()
var pounds = _weight.ConvertTo(MassUnit.Pounds).GetValue(); var pounds = _weight.ConvertTo(MassUnit.Pounds).GetValue();
var gallons = _recipe.GetBrewLength().ConvertTo(VolumeUnit.Gallons).GetValue(); var gallons = _recipe.GetBrewLength().ConvertTo(VolumeUnit.Gallons).GetValue();


//var calculatedGravityContribution = ((pounds * points) / gallons); var calculatedGravityContribution = (pounds * points) / gallons;
var calculatedGravityContribution = points * (pounds / gallons);
return Math.Round(calculatedGravityContribution, 3); return Math.Round(calculatedGravityContribution, 3);
} }


Expand Down
18 changes: 9 additions & 9 deletions Modules/Brewroom.Modules.Core.Spec/AddingIngredients.cs
Expand Up @@ -79,12 +79,12 @@ public void ShouldCalculateStartingGravityWithMultipleGrains()
var grain3 = new Grain("Two-row"); var grain3 = new Grain("Two-row");


var recipe = new Recipe(); var recipe = new Recipe();
recipe.SetBrewLength(new Volume(5.5M, VolumeUnit.Gallons)); recipe.SetBrewLength(new Volume(3M, VolumeUnit.Gallons));
recipe.AddGrain(grain1, new Weight(1.87M, MassUnit.Pounds), 1.038M); recipe.AddGrain(grain1, new Weight(1M, MassUnit.Pounds), 1.045M);
recipe.AddGrain(grain2, new Weight(1.46M, MassUnit.Pounds), 1.033M); recipe.AddGrain(grain2, new Weight(1M, MassUnit.Pounds), 1.045M);
recipe.AddGrain(grain3, new Weight(5.92M, MassUnit.Pounds), 1.036M); recipe.AddGrain(grain3, new Weight(1M, MassUnit.Pounds), 1.046M);


Assert.AreEqual(1.049M, recipe.GetStartingGravity()); Assert.AreEqual(1.045M, recipe.GetStartingGravity());
} }


[Test] [Test]
Expand All @@ -98,7 +98,7 @@ public void ShouldBeAbleToClaculateTotalIBU()
{ {
var recipe = SimpleRecipe(); var recipe = SimpleRecipe();


Assert.AreEqual(31.2M, recipe.GetIBU()); Assert.AreEqual(66M, recipe.GetIBU());
} }


private static Recipe SimpleRecipe() private static Recipe SimpleRecipe()
Expand All @@ -107,9 +107,9 @@ private static Recipe SimpleRecipe()
var hop = new Hop("Saaz"); var hop = new Hop("Saaz");
var recipe = new Recipe(); var recipe = new Recipe();


recipe.SetBrewLength(6.Gallons()); recipe.SetBrewLength(1.Gallons());
recipe.AddGrain(grain1, 1.Pound(), 1.045M); 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; return recipe;
} }


Expand All @@ -118,7 +118,7 @@ public void ShouldCalculateBuGuRatio()
{ {
var recipe = SimpleRecipe(); var recipe = SimpleRecipe();


Assert.AreEqual(0.81M, recipe.GetGuBuRatio()); Assert.AreEqual(0.02M, recipe.GetGuBuRatio());
} }


[Test] [Test]
Expand Down

0 comments on commit 73e85eb

Please sign in to comment.