diff --git a/brew/constants.py b/brew/constants.py index 84ec489..9a2f6d9 100644 --- a/brew/constants.py +++ b/brew/constants.py @@ -117,6 +117,15 @@ #: Moisture correction factor MOISTURE_CORRECTION = 0.0 +# Commonly used PPG numbers exist for DME and LME but they should be considered +# as guidelines. +#: Common PPG for DME +PPG_DME = 44.0 +#: Common PPG for LME +PPG_LME = 36.0 +#: Common PPG for Cereal +PPG_CEREAL = 30.0 + # Sucrose is considered 100% extractable in water, so the maximum PPG and # Plato are listed here #: Maximum Plato for 100% sugar dissolved in water diff --git a/brew/grains.py b/brew/grains.py index 4a9da72..2d0df12 100644 --- a/brew/grains.py +++ b/brew/grains.py @@ -6,25 +6,20 @@ from .constants import GRAIN_TYPE_CEREAL from .constants import GRAIN_TYPE_DME from .constants import GRAIN_TYPE_LME -from .constants import GRAIN_TYPE_SPECIALTY from .constants import IMPERIAL_TYPES from .constants import IMPERIAL_UNITS from .constants import KG_PER_POUND from .constants import POUND_PER_KG +from .constants import PPG_CEREAL +from .constants import PPG_DME +from .constants import PPG_LME from .constants import SI_TYPES from .constants import SI_UNITS from .constants import WEIGHT_TOLERANCE from .exceptions import GrainException -from .utilities.malt import dry_malt_to_grain_weight -from .utilities.malt import dry_to_liquid_malt_weight -from .utilities.malt import grain_to_dry_malt_weight -from .utilities.malt import grain_to_liquid_malt_weight from .utilities.malt import hwe_to_basis from .utilities.malt import hwe_to_ppg -from .utilities.malt import liquid_malt_to_grain_weight -from .utilities.malt import liquid_to_dry_malt_weight from .utilities.malt import ppg_to_hwe -from .utilities.malt import specialty_grain_to_liquid_malt_weight from .validators import validate_optional_fields from .validators import validate_percentage from .validators import validate_required_fields @@ -133,11 +128,16 @@ def get_working_yield(self, brew_house_yield): return (hwe_to_basis(self.hwe) * brew_house_yield) - def convert_to_lme(self): - return Grain(self.name, color=self.color, ppg=36.0) + def convert_to_cereal(self, ppg=None): + if not ppg: + raise GrainException(u'Must provide PPG to convert to cereal') + return Grain(self.name, color=self.color, ppg=ppg) - def convert_to_dme(self): - return Grain(self.name, color=self.color, ppg=44.0) + def convert_to_lme(self, ppg=PPG_LME): + return Grain(self.name, color=self.color, ppg=ppg) + + def convert_to_dme(self, ppg=PPG_DME): + return Grain(self.name, color=self.color, ppg=ppg) class GrainAddition(object): @@ -226,21 +226,15 @@ def __eq__(self, other): def __ne__(self, other): return not self.__eq__(other) - def get_cereal_weight(self): + def get_cereal_weight(self, ppg=PPG_CEREAL): """ Get the weight of the addition in cereal weight + :param float ppg: The potential points per gallon :return: Cereal weight :rtype: float """ - if self.grain_type == GRAIN_TYPE_CEREAL: - return self.weight - elif self.grain_type == GRAIN_TYPE_DME: - return self.weight * (self.grain.ppg / 44.0) - elif self.grain_type == GRAIN_TYPE_LME: - return self.weight * (self.grain.ppg / 36.0) - elif self.grain_type == GRAIN_TYPE_SPECIALTY: - return self.weight + return self.convert_to_cereal(ppg=ppg).weight def get_lme_weight(self): """ @@ -249,14 +243,7 @@ def get_lme_weight(self): :return: LME weight :rtype: float """ - if self.grain_type == GRAIN_TYPE_CEREAL: - return grain_to_liquid_malt_weight(self.weight) - elif self.grain_type == GRAIN_TYPE_DME: - return dry_to_liquid_malt_weight(self.weight) - elif self.grain_type == GRAIN_TYPE_LME: - return self.weight - elif self.grain_type == GRAIN_TYPE_SPECIALTY: - return specialty_grain_to_liquid_malt_weight(self.weight) + return self.convert_to_lme().weight def get_dme_weight(self): """ @@ -265,15 +252,7 @@ def get_dme_weight(self): :return: Dry weight :rtype: float """ - if self.grain_type == GRAIN_TYPE_CEREAL: - return grain_to_dry_malt_weight(self.weight) - elif self.grain_type == GRAIN_TYPE_DME: - return self.weight - elif self.grain_type == GRAIN_TYPE_LME: - return liquid_to_dry_malt_weight(self.weight) - elif self.grain_type == GRAIN_TYPE_SPECIALTY: - lme = specialty_grain_to_liquid_malt_weight(self.weight) - return liquid_to_dry_malt_weight(lme) + return self.convert_to_dme().weight def get_weight_map(self): """ @@ -288,37 +267,49 @@ def get_weight_map(self): u'dry_weight': round(self.get_dme_weight(), 2), } - def convert_to_cereal(self, brew_house_yield=1.0): + def convert_to_cereal(self, ppg=None, brew_house_yield=1.0): """ Convert Grain Addition to GRAIN_TYPE_CEREAL + :param float ppg: The potential points per gallon :param float brew_house_yield: The brew house yield as a percentage - :return: GrainAddition of type GRAIN_TYPE_CEREAL :rtype: GrainAddition """ - validate_percentage(brew_house_yield) if self.grain_type == GRAIN_TYPE_CEREAL: - brew_house_yield = 1.0 + return self + if not ppg: + raise GrainException('Must provide PPG to convert to cereal') + + validate_percentage(brew_house_yield) + new_grain = self.grain.convert_to_cereal(ppg=ppg) + ppg_factor = self.grain.ppg / new_grain.ppg + + # When converting away from cereal BHY works in reverse + weight = self.weight * ppg_factor / brew_house_yield return GrainAddition( - self.grain, - weight=self.get_cereal_weight() / brew_house_yield, + new_grain, + weight=weight, grain_type=GRAIN_TYPE_CEREAL, units=self.units) - def convert_to_lme(self, brew_house_yield=1.0): + def convert_to_lme(self, ppg=PPG_LME, brew_house_yield=1.0): """ Convert Grain Addition to GRAIN_TYPE_LME + :param float ppg: The potential points per gallon :param float brew_house_yield: The brew house yield as a percentage - :return: GrainAddition of type GRAIN_TYPE_LME :rtype: GrainAddition """ + if self.grain_type == GRAIN_TYPE_LME: + return self + + # BHY applies to cereal grains validate_percentage(brew_house_yield) - if self.grain_type in [GRAIN_TYPE_DME, GRAIN_TYPE_LME]: + if self.grain_type == GRAIN_TYPE_DME: brew_house_yield = 1.0 - new_grain = self.grain.convert_to_lme() + new_grain = self.grain.convert_to_lme(ppg=ppg) ppg_factor = self.grain.ppg / new_grain.ppg weight = self.weight * ppg_factor * brew_house_yield return GrainAddition( @@ -327,19 +318,23 @@ def convert_to_lme(self, brew_house_yield=1.0): grain_type=GRAIN_TYPE_LME, units=self.units) - def convert_to_dme(self, brew_house_yield=1.0): + def convert_to_dme(self, ppg=PPG_DME, brew_house_yield=1.0): """ Convert Grain Addition to GRAIN_TYPE_DME + :param float ppg: The potential points per gallon :param float brew_house_yield: The brew house yield as a percentage - :return: GrainAddition of type GRAIN_TYPE_DME :rtype: GrainAddition """ + if self.grain_type == GRAIN_TYPE_DME: + return self + + # BHY applies to cereal grains validate_percentage(brew_house_yield) - if self.grain_type in [GRAIN_TYPE_DME, GRAIN_TYPE_LME]: + if self.grain_type == GRAIN_TYPE_LME: brew_house_yield = 1.0 - new_grain = self.grain.convert_to_dme() + new_grain = self.grain.convert_to_dme(ppg=ppg) ppg_factor = self.grain.ppg / new_grain.ppg weight = self.weight * ppg_factor * brew_house_yield return GrainAddition( diff --git a/brew/recipes.py b/brew/recipes.py index e5d43fc..76fc00d 100644 --- a/brew/recipes.py +++ b/brew/recipes.py @@ -14,6 +14,7 @@ from .constants import IMPERIAL_TYPES from .constants import IMPERIAL_UNITS from .constants import LITER_PER_GAL +from .constants import PPG_CEREAL from .constants import SI_TYPES from .constants import SI_UNITS from .constants import WATER_WEIGHT_IMPERIAL @@ -340,8 +341,7 @@ def get_grain_add_dry_weight(self, grain_add): the brew house yield will decrease the size of the DME accordingly. """ - return grain_add.convert_to_dme( - brew_house_yield=self.brew_house_yield).weight + return grain_add.get_dme_weight() def get_total_dry_weight(self): """ @@ -355,7 +355,7 @@ def get_total_dry_weight(self): weights.append(self.get_grain_add_dry_weight(grain_add)) return sum(weights) - def get_grain_add_cereal_weight(self, grain_add): + def get_grain_add_cereal_weight(self, grain_add, ppg=PPG_CEREAL): """ Get Grain Addition as Cereal @@ -368,10 +368,7 @@ def get_grain_add_cereal_weight(self, grain_add): the brew house yield will increase the size of the grain accordingly. """ - if grain_add.grain_type in [GRAIN_TYPE_DME, GRAIN_TYPE_LME]: - return grain_add.get_cereal_weight() / self.brew_house_yield # noqa - else: - return grain_add.get_cereal_weight() + return grain_add.get_cereal_weight(ppg=ppg) def get_total_grain_weight(self): """ @@ -422,20 +419,6 @@ def get_bu_to_gu(self): """ return self.get_total_ibu() / self.get_boil_gravity_units() - def get_mash_water_volume(self, liquor_to_grist_ratio): - """ - Get the Mash Water Volume - - :param float liquor_to_grist_ratio: The Liquor to Grist Ratio - :return: The mash water volume - :rtype: float - """ - water_weight = WATER_WEIGHT_IMPERIAL - if self.units == SI_UNITS: - water_weight = WATER_WEIGHT_SI - return (self.get_total_dry_weight() * liquor_to_grist_ratio / - water_weight) - @property def abv(self): return alcohol_by_volume_standard(self.og, self.fg) diff --git a/tests/fixtures.py b/tests/fixtures.py index b538d13..d3a7552 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -11,15 +11,17 @@ BHY = 0.70 # Define Grains +ppg_pale = 37.0 pale = Grain(u'pale 2-row', color=2.0, - ppg=37.0) + ppg=ppg_pale) pale_lme = pale.convert_to_lme() pale_dme = pale.convert_to_dme() +ppg_crystal = 35.0 crystal = Grain(u'crystal C20', color=20.0, - ppg=35.0) + ppg=ppg_crystal) grain_list = [pale, crystal] pale_add = GrainAddition(pale, diff --git a/tests/test_grains.py b/tests/test_grains.py index 022b29b..05a142d 100644 --- a/tests/test_grains.py +++ b/tests/test_grains.py @@ -8,6 +8,8 @@ from brew.constants import GRAIN_TYPE_LME from brew.constants import GRAIN_TYPE_SPECIALTY from brew.constants import IMPERIAL_UNITS +from brew.constants import PPG_DME +from brew.constants import PPG_LME from brew.constants import SI_UNITS from brew.exceptions import GrainException from brew.grains import Grain @@ -18,6 +20,7 @@ from fixtures import pale_dme from fixtures import pale_lme from fixtures import pale_add +from fixtures import ppg_pale class TestGrains(unittest.TestCase): @@ -32,7 +35,7 @@ def test_str(self): def test_unicode(self): grain = Grain(u'château pilsen 2rs', color=3.0, - ppg=37.0) + ppg=ppg_pale) out = str(grain) if sys.version_info[0] >= 3: self.assertEquals(out, u'château pilsen 2rs') @@ -67,7 +70,7 @@ def test_grain_hwe(self): def test_grain_no_color_raises(self): with self.assertRaises(GrainException) as ctx: Grain(u'pale 2-row', - ppg=37.0) + ppg=ppg_pale) self.assertEquals(str(ctx.exception), u'pale 2-row: Must provide color value') @@ -82,7 +85,7 @@ def test_grain_ppg_hwe_raises(self): with self.assertRaises(GrainException) as ctx: Grain(u'pale 2-row', color=2.0, - ppg=37.0, + ppg=ppg_pale, hwe=308.0) self.assertEquals(str(ctx.exception), u'pale 2-row: Cannot provide both ppg and hwe') @@ -90,34 +93,34 @@ def test_grain_ppg_hwe_raises(self): def test_eq(self): grain1 = Grain(u'pale 2-row', color=2.0, - ppg=37.0) + ppg=ppg_pale) grain2 = Grain(u'pale 2-row', color=2.0, - ppg=37.0) + ppg=ppg_pale) self.assertEquals(grain1, grain2) def test_ne_name(self): grain1 = Grain(u'pale 2-row', color=2.0, - ppg=37.0) + ppg=ppg_pale) grain2 = Grain(u'pale row', color=2.0, - ppg=37.0) + ppg=ppg_pale) self.assertTrue(grain1 != grain2) def test_ne_color(self): grain1 = Grain(u'pale 2-row', color=2.0, - ppg=37.0) + ppg=ppg_pale) grain2 = Grain(u'pale 2-row', color=4.0, - ppg=37.0) + ppg=ppg_pale) self.assertTrue(grain1 != grain2) def test_ne_ppg(self): grain1 = Grain(u'pale 2-row', color=2.0, - ppg=37.0) + ppg=ppg_pale) grain2 = Grain(u'pale 2-row', color=2.0, ppg=35.0) @@ -130,7 +133,7 @@ def test_to_dict(self): out = self.grain.to_dict() expected = {u'name': u'pale 2-row', u'color': 2.0, - u'ppg': 37.0, + u'ppg': ppg_pale, u'hwe': 308.78, } self.assertEquals(out, expected) @@ -140,13 +143,24 @@ def test_to_json(self): expected = u'{"color": 2.0, "hwe": 308.78, "name": "pale 2-row", "ppg": 37.0}' # noqa self.assertEquals(out, expected) + def test_convert_to_cereal(self): + ppg = ppg_pale + ga_cereal = pale_lme.convert_to_cereal(ppg=ppg) + self.assertEquals(ga_cereal.ppg, ppg) + + def test_convert_to_cereal_raises(self): + with self.assertRaises(GrainException) as ctx: + pale_lme.convert_to_cereal() + self.assertEquals(str(ctx.exception), + u'Must provide PPG to convert to cereal') + def test_convert_to_lme(self): - ga_lme = self.grain.convert_to_lme() - self.assertEquals(ga_lme.ppg, 36) + ga_lme = self.grain.convert_to_lme(ppg=PPG_LME) + self.assertEquals(ga_lme.ppg, PPG_LME) def test_convert_to_dme(self): - ga_dme = self.grain.convert_to_dme() - self.assertEquals(ga_dme.ppg, 44) + ga_dme = self.grain.convert_to_dme(ppg=PPG_DME) + self.assertEquals(ga_dme.ppg, PPG_DME) class TestGrainAdditions(unittest.TestCase): @@ -161,7 +175,7 @@ def test_str(self): def test_unicode(self): grain = Grain(u'château pilsen 2rs', color=3.0, - ppg=37.0) + ppg=ppg_pale) grain_add = GrainAddition(grain, weight=0.78) out = str(grain_add) @@ -178,52 +192,52 @@ def test_get_weight_cereal(self): grain_add = GrainAddition(pale, weight=13.96, grain_type=GRAIN_TYPE_CEREAL) self.assertEquals(grain_add.grain_type, GRAIN_TYPE_CEREAL) - out = grain_add.get_cereal_weight() + out = grain_add.get_cereal_weight(ppg=ppg_pale) self.assertEqual(round(out, 2), 13.96) out = grain_add.get_lme_weight() - self.assertEqual(round(out, 2), 10.47) + self.assertEqual(round(out, 2), 14.35) out = grain_add.get_dme_weight() - self.assertEqual(round(out, 2), 8.38) + self.assertEqual(round(out, 2), 11.74) def test_get_weight_lme(self): - grain_add = GrainAddition(pale, weight=10.47, + grain_add = GrainAddition(pale_lme, weight=14.35, grain_type=GRAIN_TYPE_LME) self.assertEquals(grain_add.grain_type, GRAIN_TYPE_LME) - out = grain_add.get_cereal_weight() - self.assertEqual(round(out, 2), 10.76) + out = grain_add.get_cereal_weight(ppg=ppg_pale) + self.assertEqual(round(out, 2), 13.96) out = grain_add.get_lme_weight() - self.assertEqual(round(out, 2), 10.47) + self.assertEqual(round(out, 2), 14.35) out = grain_add.get_dme_weight() - self.assertEqual(round(out, 2), 8.38) + self.assertEqual(round(out, 2), 11.74) - def test_get_weight_dry(self): - grain_add = GrainAddition(pale, weight=8.38, + def test_get_weight_dme(self): + grain_add = GrainAddition(pale_dme, weight=11.74, grain_type=GRAIN_TYPE_DME) self.assertEquals(grain_add.grain_type, GRAIN_TYPE_DME) - out = grain_add.get_cereal_weight() - self.assertEqual(round(out, 2), 7.05) + out = grain_add.get_cereal_weight(ppg=ppg_pale) + self.assertEqual(round(out, 2), 13.96) out = grain_add.get_lme_weight() - self.assertEqual(round(out, 2), 10.48) + self.assertEqual(round(out, 2), 14.35) out = grain_add.get_dme_weight() - self.assertEqual(round(out, 2), 8.38) + self.assertEqual(round(out, 2), 11.74) def test_get_weight_specialty(self): grain_add = GrainAddition(pale, weight=13.96, grain_type=GRAIN_TYPE_SPECIALTY) self.assertEquals(grain_add.grain_type, GRAIN_TYPE_SPECIALTY) - out = grain_add.get_cereal_weight() + out = grain_add.get_cereal_weight(ppg=ppg_pale) self.assertEqual(round(out, 2), 13.96) out = grain_add.get_lme_weight() - self.assertEqual(round(out, 2), 12.42) + self.assertEqual(round(out, 2), 14.35) out = grain_add.get_dme_weight() - self.assertEqual(round(out, 2), 9.94) + self.assertEqual(round(out, 2), 11.74) def test_get_weight_map(self): out = self.grain_add.get_weight_map() expected = { u'grain_weight': 13.96, - u'lme_weight': 10.47, - u'dry_weight': 8.38, + u'lme_weight': 14.35, + u'dry_weight': 11.74, } self.assertEquals(out, expected) @@ -231,43 +245,49 @@ def test_convert_to_cereal(self): grain_add = GrainAddition(pale, weight=1.0, grain_type=GRAIN_TYPE_CEREAL) - ga_cereal = grain_add.convert_to_cereal(brew_house_yield=BHY) - ga_lme = grain_add.convert_to_lme(brew_house_yield=BHY) - ga_dme = grain_add.convert_to_dme(brew_house_yield=BHY) + ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, + brew_house_yield=BHY) + ga_lme = grain_add.convert_to_lme(ppg=PPG_LME, brew_house_yield=BHY) + ga_dme = grain_add.convert_to_dme(ppg=PPG_DME, brew_house_yield=BHY) self.assertEquals(ga_cereal.weight, 1.0) self.assertEquals(round(ga_lme.weight, 2), 0.72) self.assertEquals(round(ga_dme.weight, 2), 0.59) - self.assertEquals(ga_lme.grain.ppg, 36) - self.assertEquals(ga_dme.grain.ppg, 44) + + def test_convert_to_cereal_raises(self): + grain_add = GrainAddition(pale_lme, + weight=1.0, + grain_type=GRAIN_TYPE_LME) + with self.assertRaises(GrainException) as ctx: + grain_add.convert_to_cereal(brew_house_yield=BHY) + self.assertEquals(str(ctx.exception), + u'Must provide PPG to convert to cereal') def test_convert_to_lme(self): grain_add = GrainAddition(pale_lme, weight=1.0, grain_type=GRAIN_TYPE_LME) - ga_cereal = grain_add.convert_to_cereal(brew_house_yield=BHY) - ga_lme = grain_add.convert_to_lme(brew_house_yield=BHY) - ga_dme = grain_add.convert_to_dme(brew_house_yield=BHY) + ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, + brew_house_yield=BHY) + ga_lme = grain_add.convert_to_lme(ppg=PPG_LME, brew_house_yield=BHY) + ga_dme = grain_add.convert_to_dme(ppg=PPG_DME, brew_house_yield=BHY) - self.assertEquals(round(ga_cereal.weight, 2), 1.43) + self.assertEquals(round(ga_cereal.weight, 2), 1.39) self.assertEquals(ga_lme.weight, 1.0) self.assertEquals(round(ga_dme.weight, 2), 0.82) - self.assertEquals(ga_lme.grain.ppg, 36) - self.assertEquals(ga_dme.grain.ppg, 44) def test_convert_to_dme(self): grain_add = GrainAddition(pale_dme, weight=1.0, grain_type=GRAIN_TYPE_DME) - ga_cereal = grain_add.convert_to_cereal(brew_house_yield=BHY) - ga_lme = grain_add.convert_to_lme(brew_house_yield=BHY) - ga_dme = grain_add.convert_to_dme(brew_house_yield=BHY) + ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, + brew_house_yield=BHY) + ga_lme = grain_add.convert_to_lme(ppg=PPG_LME, brew_house_yield=BHY) + ga_dme = grain_add.convert_to_dme(ppg=PPG_DME, brew_house_yield=BHY) - self.assertEquals(round(ga_cereal.weight, 2), 1.43) + self.assertEquals(round(ga_cereal.weight, 2), 1.7) self.assertEquals(round(ga_lme.weight, 2), 1.22) self.assertEquals(ga_dme.weight, 1.0) - self.assertEquals(ga_lme.grain.ppg, 36) - self.assertEquals(ga_dme.grain.ppg, 44) def test_eq(self): grain_add1 = GrainAddition(pale, weight=13.96) @@ -314,7 +334,7 @@ def test_to_dict(self): expected = {u'name': u'pale 2-row', u'data': { u'color': 2.0, - u'ppg': 37.0, + u'ppg': ppg_pale, u'hwe': 308.78, }, u'grain_type': u'cereal', diff --git a/tests/test_recipes_imperial.py b/tests/test_recipes_imperial.py index 7d95817..4b5c322 100644 --- a/tests/test_recipes_imperial.py +++ b/tests/test_recipes_imperial.py @@ -14,7 +14,10 @@ from fixtures import grain_additions from fixtures import grain_list from fixtures import hop_additions -from fixtures import pale +from fixtures import pale_dme +from fixtures import pale_lme +from fixtures import ppg_crystal +from fixtures import ppg_pale from fixtures import recipe from fixtures import yeast @@ -49,32 +52,32 @@ def test_get_total_points(self): self.assertEquals(round(out, 2), 380.67) def test_get_total_points_lme(self): - pale_lme = GrainAddition(pale, - weight=10.47, - grain_type=GRAIN_TYPE_LME, - units=IMPERIAL_UNITS) + pale_lme_add = GrainAddition(pale_lme, + weight=14.35, + grain_type=GRAIN_TYPE_LME, + units=IMPERIAL_UNITS) recipe = Recipe(u'lme', - grain_additions=[pale_lme], + grain_additions=[pale_lme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=IMPERIAL_UNITS) out = recipe.get_total_points() - self.assertEquals(round(out, 2), 387.39) + self.assertEquals(round(out, 1), 516.6) def test_get_total_points_dme(self): - pale_dme = GrainAddition(pale, - weight=8.38, - grain_type=GRAIN_TYPE_DME, - units=IMPERIAL_UNITS) + pale_dme_add = GrainAddition(pale_dme, + weight=11.74, + grain_type=GRAIN_TYPE_DME, + units=IMPERIAL_UNITS) recipe = Recipe(u'dme', - grain_additions=[pale_dme], + grain_additions=[pale_dme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=IMPERIAL_UNITS) out = recipe.get_total_points() - self.assertEquals(round(out, 2), 310.06) + self.assertEquals(round(out, 1), 516.6) def test_get_original_gravity_units(self): out = self.recipe.get_original_gravity_units() @@ -137,75 +140,79 @@ def test_get_percent_malt_bill(self): def test_get_grain_add_dry_weight(self): out = self.recipe.get_grain_add_dry_weight(self.grain_additions[0]) - self.assertEquals(round(out, 2), 8.22) + self.assertEquals(round(out, 2), 11.74) out = self.recipe.get_grain_add_dry_weight(self.grain_additions[1]) - self.assertEquals(round(out, 2), 0.43) + self.assertEquals(round(out, 2), 0.62) def test_get_grain_add_dry_weight_lme(self): - pale_lme = GrainAddition(pale, - weight=10.47, - grain_type=GRAIN_TYPE_LME, - units=IMPERIAL_UNITS) + pale_lme_add = GrainAddition(pale_lme, + weight=14.35, + grain_type=GRAIN_TYPE_LME, + units=IMPERIAL_UNITS) recipe = Recipe(u'lme', - grain_additions=[pale_lme], + grain_additions=[pale_lme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=IMPERIAL_UNITS) - out = recipe.get_grain_add_dry_weight(pale_lme) - self.assertEquals(round(out, 2), 8.8) + out = recipe.get_grain_add_dry_weight(pale_lme_add) + self.assertEquals(round(out, 2), 11.74) def test_get_grain_add_dry_weight_dme(self): - pale_dme = GrainAddition(pale, - weight=8.38, - grain_type=GRAIN_TYPE_DME, - units=IMPERIAL_UNITS) + pale_dme_add = GrainAddition(pale_dme, + weight=11.74, + grain_type=GRAIN_TYPE_DME, + units=IMPERIAL_UNITS) recipe = Recipe(u'dme', - grain_additions=[pale_dme], + grain_additions=[pale_dme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=IMPERIAL_UNITS) - out = recipe.get_grain_add_dry_weight(pale_dme) - self.assertEquals(round(out, 2), 7.05) + out = recipe.get_grain_add_dry_weight(pale_dme_add) + self.assertEquals(round(out, 2), 11.74) def test_get_total_dry_weight(self): out = self.recipe.get_total_dry_weight() - self.assertEquals(round(out, 2), 8.65) + self.assertEquals(round(out, 2), 12.36) def test_get_grain_add_cereal_weight(self): - out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[0]) + out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[0], + ppg=ppg_pale) self.assertEquals(round(out, 2), 13.96) - out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[1]) + out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[1], + ppg=ppg_crystal) self.assertEquals(round(out, 2), 0.78) def test_get_grain_add_cereal_weight_lme(self): - pale_lme = GrainAddition(pale, - weight=10.47, - grain_type=GRAIN_TYPE_LME, - units=IMPERIAL_UNITS) + pale_lme_add = GrainAddition(pale_lme, + weight=14.35, + grain_type=GRAIN_TYPE_LME, + units=IMPERIAL_UNITS) recipe = Recipe(u'lme', - grain_additions=[pale_lme], + grain_additions=[pale_lme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=IMPERIAL_UNITS) - out = recipe.get_grain_add_cereal_weight(pale_lme) - self.assertEquals(round(out, 2), 15.37) + out = recipe.get_grain_add_cereal_weight(pale_lme_add, + ppg=ppg_pale) + self.assertEquals(round(out, 2), 13.96) def test_get_grain_add_cereal_weight_dme(self): - pale_dme = GrainAddition(pale, - weight=8.38, - grain_type=GRAIN_TYPE_DME, - units=IMPERIAL_UNITS) + pale_dme_add = GrainAddition(pale_dme, + weight=11.74, + grain_type=GRAIN_TYPE_DME, + units=IMPERIAL_UNITS) recipe = Recipe(u'dme', - grain_additions=[pale_dme], + grain_additions=[pale_dme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=IMPERIAL_UNITS) - out = recipe.get_grain_add_cereal_weight(pale_dme) - self.assertEquals(round(out, 2), 10.07) + out = recipe.get_grain_add_cereal_weight(pale_dme_add, + ppg=ppg_pale) + self.assertEquals(round(out, 2), 13.96) def test_get_total_grain_weight(self): total_grain_weight = self.recipe.get_total_grain_weight() @@ -230,10 +237,6 @@ def test_ibu(self): def test_bu_to_gu(self): self.assertEqual(round(self.recipe.get_bu_to_gu(), 2), 0.61) - def test_get_mash_water_volume(self): - mash_water_vol = self.recipe.get_mash_water_volume(3.0 / 1.0) - self.assertEquals(round(mash_water_vol, 2), 3.12) - def test_abv(self): abv = self.recipe.abv self.assertEqual(round(abv, 4), 0.0749) diff --git a/tests/test_recipes_si.py b/tests/test_recipes_si.py index 8bc1a1b..2f6ece3 100644 --- a/tests/test_recipes_si.py +++ b/tests/test_recipes_si.py @@ -15,7 +15,10 @@ from fixtures import grain_additions from fixtures import grain_list from fixtures import hop_additions -from fixtures import pale +from fixtures import pale_dme +from fixtures import pale_lme +from fixtures import ppg_crystal +from fixtures import ppg_pale from fixtures import recipe from fixtures import yeast @@ -60,32 +63,32 @@ def test_get_total_points(self): self.assertEquals(round(out, 2), 1441.01) def test_get_total_points_lme(self): - pale_lme = GrainAddition(pale, - weight=4.75, - grain_type=GRAIN_TYPE_LME, - units=SI_UNITS) + pale_lme_add = GrainAddition(pale_lme, + weight=6.51, + grain_type=GRAIN_TYPE_LME, + units=SI_UNITS) recipe = Recipe(u'lme', - grain_additions=[pale_lme], + grain_additions=[pale_lme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=SI_UNITS) out = recipe.get_total_points() - self.assertEquals(round(out, 2), 1466.71) + self.assertEquals(round(out, 1), 1955.8) def test_get_total_points_dme(self): - pale_dme = GrainAddition(pale, - weight=3.80, - grain_type=GRAIN_TYPE_DME, - units=SI_UNITS) + pale_dme_add = GrainAddition(pale_dme, + weight=5.33, + grain_type=GRAIN_TYPE_DME, + units=SI_UNITS) recipe = Recipe(u'dme', - grain_additions=[pale_dme], + grain_additions=[pale_dme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=SI_UNITS) out = recipe.get_total_points() - self.assertEquals(round(out, 2), 1173.36) + self.assertEquals(round(out, 1), 1957.2) def test_get_original_gravity_units(self): out = self.recipe.get_original_gravity_units() @@ -148,75 +151,79 @@ def test_get_percent_malt_bill(self): def test_get_grain_add_dry_weight(self): out = self.recipe.get_grain_add_dry_weight(self.grain_additions[0]) - self.assertEquals(round(out, 2), 3.73) + self.assertEquals(round(out, 2), 5.32) out = self.recipe.get_grain_add_dry_weight(self.grain_additions[1]) - self.assertEquals(round(out, 2), 0.2) + self.assertEquals(round(out, 2), 0.28) def test_get_grain_add_dry_weight_lme(self): - pale_lme = GrainAddition(pale, - weight=4.75, - grain_type=GRAIN_TYPE_LME, - units=SI_UNITS) + pale_lme_add = GrainAddition(pale_lme, + weight=6.51, + grain_type=GRAIN_TYPE_LME, + units=SI_UNITS) recipe = Recipe(u'lme', - grain_additions=[pale_lme], + grain_additions=[pale_lme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=SI_UNITS) - out = recipe.get_grain_add_dry_weight(pale_lme) - self.assertEquals(round(out, 2), 3.99) + out = recipe.get_grain_add_dry_weight(pale_lme_add) + self.assertEquals(round(out, 2), 5.33) def test_get_grain_add_dry_weight_dme(self): - pale_dme = GrainAddition(pale, - weight=3.80, - grain_type=GRAIN_TYPE_DME, - units=SI_UNITS) + pale_dme_add = GrainAddition(pale_dme, + weight=5.33, + grain_type=GRAIN_TYPE_DME, + units=SI_UNITS) recipe = Recipe(u'dme', - grain_additions=[pale_dme], + grain_additions=[pale_dme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=SI_UNITS) - out = recipe.get_grain_add_dry_weight(pale_dme) - self.assertEquals(round(out, 2), 3.2) + out = recipe.get_grain_add_dry_weight(pale_dme_add) + self.assertEquals(round(out, 2), 5.33) def test_get_total_dry_weight(self): out = self.recipe.get_total_dry_weight() - self.assertEquals(round(out, 2), 3.92) + self.assertEquals(round(out, 2), 5.61) def test_get_grain_add_cereal_weight(self): - out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[0]) + out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[0], + ppg=ppg_pale) self.assertEquals(round(out, 2), 6.33) - out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[1]) + out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[1], + ppg=ppg_crystal) self.assertEquals(round(out, 2), 0.35) def test_get_grain_add_cereal_weight_lme(self): - pale_lme = GrainAddition(pale, - weight=4.75, - grain_type=GRAIN_TYPE_LME, - units=SI_UNITS) + pale_lme_add = GrainAddition(pale_lme, + weight=6.51, + grain_type=GRAIN_TYPE_LME, + units=SI_UNITS) recipe = Recipe(u'lme', - grain_additions=[pale_lme], + grain_additions=[pale_lme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=SI_UNITS) - out = recipe.get_grain_add_cereal_weight(pale_lme) - self.assertEquals(round(out, 2), 6.97) + out = recipe.get_grain_add_cereal_weight(pale_lme_add, + ppg=ppg_pale) + self.assertEquals(round(out, 2), 6.33) def test_get_grain_add_cereal_weight_dme(self): - pale_dme = GrainAddition(pale, - weight=3.80, - grain_type=GRAIN_TYPE_DME, - units=SI_UNITS) + pale_dme_add = GrainAddition(pale_dme, + weight=5.33, + grain_type=GRAIN_TYPE_DME, + units=SI_UNITS) recipe = Recipe(u'dme', - grain_additions=[pale_dme], + grain_additions=[pale_dme_add], hop_additions=self.hop_additions, yeast=self.yeast, units=SI_UNITS) - out = recipe.get_grain_add_cereal_weight(pale_dme) - self.assertEquals(round(out, 2), 4.56) + out = recipe.get_grain_add_cereal_weight(pale_dme_add, + ppg=ppg_pale) + self.assertEquals(round(out, 2), 6.34) def test_get_total_grain_weight(self): total_grain_weight = self.recipe.get_total_grain_weight() @@ -241,10 +248,6 @@ def test_ibu(self): def test_bu_to_gu(self): self.assertEqual(round(self.recipe.get_bu_to_gu(), 2), 0.61) - def test_get_mash_water_volume(self): - mash_water_vol = self.recipe.get_mash_water_volume(3.0 / 1.0) - self.assertEquals(round(mash_water_vol, 2), 11.77) - def test_abv(self): abv = self.recipe.abv self.assertEqual(round(abv, 4), 0.0749) @@ -377,14 +380,14 @@ def test_get_grain_additions(self): expected = [ga.change_units() for ga in grain_additions] self.assertEquals(out[0], expected[0]) - def test_get_grain_additions_raises_sum_invalid(self): + def test_get_grain_additions_raises_percent_sum_invalid(self): percent_list = [0.90, 0.05] with self.assertRaises(RecipeException) as ctx: self.builder.get_grain_additions(percent_list) self.assertEquals(str(ctx.exception), u"Percentages must sum to 1.0") - def test_get_grain_additions_raises_length_mismatch(self): + def test_get_grain_additions_raises_percent_length_mismatch(self): percent_list = [0.90, 0.05, 0.05] with self.assertRaises(RecipeException) as ctx: self.builder.get_grain_additions(percent_list)