Skip to content

Commit

Permalink
fix : check_ratio_limits updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sepandhaghighi committed Oct 5, 2024
1 parent a349836 commit 6cf1c8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions mycoffee/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def print_result(params):
params["coffee_ratio"],
params["water_ratio"],
params["info"]))
if check_ratio_limits(params):
if not check_ratio_limits(params):
ratio_lower_limit = METHODS_MAP[method]["ratio_lower_limit"]
ratio_upper_limit = METHODS_MAP[method]["ratio_upper_limit"]
print(RATIO_WARNING_MESSAGE.format(method, str(ratio_lower_limit), str(ratio_upper_limit)))
Expand Down Expand Up @@ -121,16 +121,16 @@ def check_ratio_limits(params):
:param params: parameters
:type params: dict
:return: result as bool (True --> the ratio is out of range)
:return: result as bool (False --> the ratio is out of range)
"""
method = params["method"]
if "ratio_lower_limit" in METHODS_MAP[method] and "ratio_upper_limit" in METHODS_MAP[method]:
ratio = params["coffee_ratio"] / params["water_ratio"]
ratio_lower_limit = METHODS_MAP[method]["ratio_lower_limit"]
ratio_upper_limit = METHODS_MAP[method]["ratio_upper_limit"]
if ratio < ratio_lower_limit or ratio > ratio_upper_limit:
return True
return False
return False
return True


def calc_coffee(params):
Expand Down
6 changes: 3 additions & 3 deletions test/functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<BLANKLINE>
>>> test_params = {"method":"v60", "cups":2, "coffee":30, "water":500, "coffee_ratio": 3, "water_ratio":50, "info":"", "digits":3}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == False
>>> check_ratio_limits(test_params) == True
True
>>> print_result(test_params)
__ __ _ _ ___ _____ ____ ____ ____ ____
Expand All @@ -50,7 +50,7 @@
<BLANKLINE>
>>> test_params = {"method":"v60", "cups":2, "coffee":3, "water":500, "coffee_ratio": 6, "water_ratio":1000, "info":"", "digits":3}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == True
>>> check_ratio_limits(test_params) == False
True
>>> print_result(test_params)
__ __ _ _ ___ _____ ____ ____ ____ ____
Expand All @@ -75,7 +75,7 @@
[Warning] The ratio is not within the standard range. For `v60`, the ratio can be anywhere between `1/18` and `1/14`
>>> test_params = {"method":"custom", "cups":2, "coffee":3, "water":500, "coffee_ratio": 6, "water_ratio":1000, "info":"", "digits":3}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == False
>>> check_ratio_limits(test_params) == True
True
>>> chemex_params = load_method_params("chemex")
>>> chemex_params == {'info': 'Chemex method', 'water': 240, 'cups': 1, 'coffee_ratio': 1, 'water_ratio': 15, 'digits': 3}
Expand Down

0 comments on commit 6cf1c8c

Please sign in to comment.