Skip to content

Commit

Permalink
Add methods to test individual style matches
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgilmerproj committed Oct 12, 2016
1 parent 452ec7f commit 790cf54
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 5 deletions.
60 changes: 55 additions & 5 deletions brew/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,56 @@ def __eq__(self, other):
def __ne__(self, other):
return not self.__eq__(other)

def og_matches(self, og):
"""
Determine if og matches the style
:param float og: Original Gravity
:return: True if matches style, otherwise False
:rtyle: bool
"""
return (self.og[0] <= og <= self.og[1])

def fg_matches(self, fg):
"""
Determine if fg matches the style
:param float fg: Final Gravity
:return: True if matches style, otherwise False
:rtyle: bool
"""
return (self.fg[0] <= fg <= self.fg[1])

def abv_matches(self, abv):
"""
Determine if abv matches the style
:param float abv: Alcohol by Volume
:return: True if matches style, otherwise False
:rtyle: bool
"""
return (self.abv[0] <= abv <= self.abv[1])

def ibu_matches(self, ibu):
"""
Determine if ibu matches the style
:param float ibu: IBU
:return: True if matches style, otherwise False
:rtyle: bool
"""
return (self.ibu[0] <= ibu <= self.ibu[1])

def color_matches(self, color):
"""
Determine if color matches the style
:param float color: Color in SRM
:return: True if matches style, otherwise False
:rtyle: bool
"""
return (self.color[0] <= color <= self.color[1])

def recipe_matches(self, recipe):
"""
Determine if a recipe matches the style
Expand All @@ -104,11 +154,11 @@ def recipe_matches(self, recipe):
recipe_abv = alcohol_by_volume_standard(recipe_og, recipe_fg)
recipe_ibu = recipe.get_total_ibu()
recipe_color = recipe.get_total_wort_color()
if (self.og[0] <= recipe_og <= self.og[1]) and \
(self.fg[0] <= recipe_fg <= self.fg[1]) and \
(self.abv[0] <= recipe_abv <= self.abv[1]) and \
(self.ibu[0] <= recipe_ibu <= self.ibu[1]) and \
(self.color[0] <= recipe_color <= self.color[1]):
if self.og_matches(recipe_og) and \
self.fg_matches(recipe_fg) and \
self.abv_matches(recipe_abv) and \
self.ibu_matches(recipe_ibu) and \
self.color_matches(recipe_color):
return True
return False

Expand Down
45 changes: 45 additions & 0 deletions docs/source/tutorial/matching_styles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ In order to match the recipe we use a method on the class:
>>> style.recipe_matches(recipe)
False
>>> recipe_og = recipe.get_original_gravity()
>>> style.og_matches(recipe_og)
False
>>> recipe_fg = recipe.get_final_gravity()
>>> style._matches(recipe_fg)
False
>>> recipe_abv = alcohol_by_volume_standard(recipe_og, recipe_fg)
>>> style.abv_matches(recipe_abv)
False
>>> recipe_ibu = recipe.get_total_ibu()
>>> style.ibu_matches(recipe_ibu)
True
>>> recipe_color = recipe.get_total_wort_color()
>>> style.color_matches(recipe_color)
False
Interestingly the recipe used in the examples does not match the BJCP style!
The only feature that matches the style is the IBUs, but the remaining values
Expand Down Expand Up @@ -104,6 +119,21 @@ crystal 20L has come down from 0.78 lbs to 0.51 lbs. Let's try this again.
>>> style.recipe_matches(recipe)
False
>>> recipe_og = recipe.get_original_gravity()
>>> style.og_matches(recipe_og)
True
>>> recipe_fg = recipe.get_final_gravity()
>>> style._matches(recipe_fg)
True
>>> recipe_abv = alcohol_by_volume_standard(recipe_og, recipe_fg)
>>> style.abv_matches(recipe_abv)
True
>>> recipe_ibu = recipe.get_total_ibu()
>>> style.ibu_matches(recipe_ibu)
True
>>> recipe_color = recipe.get_total_wort_color()
>>> style.color_matches(recipe_color)
False
It turns out the recipe still doesn't match. Why? It appears that our color
is off.
Expand Down Expand Up @@ -145,6 +175,21 @@ recipe and check the style:
>>> style.recipe_matches(recipe)
True
>>> recipe_og = recipe.get_original_gravity()
>>> style.og_matches(recipe_og)
True
>>> recipe_fg = recipe.get_final_gravity()
>>> style._matches(recipe_fg)
True
>>> recipe_abv = alcohol_by_volume_standard(recipe_og, recipe_fg)
>>> style.abv_matches(recipe_abv)
True
>>> recipe_ibu = recipe.get_total_ibu()
>>> style.ibu_matches(recipe_ibu)
True
>>> recipe_color = recipe.get_total_wort_color()
>>> style.color_matches(recipe_color)
True
Nice job, now your have a beer recipe that matches the style of an American
Pale Ale.
Expand Down
20 changes: 20 additions & 0 deletions tests/test_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ def test_ne_color(self):
def test_ne_style_class(self):
self.assertTrue(self.style != recipe)

def test_og_matches(self):
out = self.style.og_matches(1.050)
self.assertTrue(out)

def test_fg_matches(self):
out = self.style.fg_matches(1.012)
self.assertTrue(out)

def test_abv_matches(self):
out = self.style.abv_matches(0.050)
self.assertTrue(out)

def test_ibu_matches(self):
out = self.style.ibu_matches(33.0)
self.assertTrue(out)

def test_color_matches(self):
out = self.style.color_matches(7.5)
self.assertTrue(out)

def test_recipe_matches(self):
pale_add = GrainAddition(pale,
weight=8.69)
Expand Down

0 comments on commit 790cf54

Please sign in to comment.