Skip to content

Commit

Permalink
Bug fix (#85)
Browse files Browse the repository at this point in the history
* fix : check_ratio_limits function updated

* fix : tests updated

* doc : CHANGELOG.md updated
  • Loading branch information
sepandhaghighi authored Jan 16, 2025
1 parent 95d8938 commit 86de1b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Changed
- `README.md` updated
- `check_ratio_limits` function bug fixed
## [1.2] - 2025-01-13
### Added
- 2 new water units
Expand Down
4 changes: 2 additions & 2 deletions mycoffee/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def check_ratio_limits(params):
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"]
ratio_lower_limit = float(METHODS_MAP[method]["ratio_lower_limit"])
ratio_upper_limit = float(METHODS_MAP[method]["ratio_upper_limit"])
if ratio < ratio_lower_limit or ratio > ratio_upper_limit:
return False
return True
Expand Down
17 changes: 13 additions & 4 deletions test/functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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":"v60", "cups":2, "coffee":27.7, "water":500, "coffee_ratio": 1, "water_ratio":18, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "g", "grind": 1400}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == False
>>> check_ratio_limits(test_params) == True
True
>>> check_grind_limits(test_params) == False
True
Expand All @@ -151,11 +151,10 @@
<BLANKLINE>
Info: Nothing :)
<BLANKLINE>
[Warning] The ratio is not within the standard range. For `v60`, the ratio can be anywhere between `1/18` and `1/14`
[Warning] The grind size is not within the standard range. For `v60`, the grind size can be anywhere between `400 um` and `700 um`
>>> test_params = {"method":"v60", "cups":2, "coffee":27.7, "water":500, "coffee_ratio": 1, "water_ratio":18, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "g", "grind": 20}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == False
>>> check_ratio_limits(test_params) == True
True
>>> check_grind_limits(test_params) == False
True
Expand All @@ -181,14 +180,24 @@
<BLANKLINE>
Info: Nothing :)
<BLANKLINE>
[Warning] The ratio is not within the standard range. For `v60`, the ratio can be anywhere between `1/18` and `1/14`
[Warning] The grind size is not within the standard range. For `v60`, the grind size can be anywhere between `400 um` and `700 um`
>>> test_params = {"method":"custom", "cups":2, "coffee":6.0, "water":500, "coffee_ratio": 6, "water_ratio":1000, "info":"", "digits":3, "coffee_unit": "g"}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == True
True
>>> check_grind_limits(test_params) == True
True
>>> test_params = {"method":"v60", "cups":2, "coffee":27.7, "water":500, "coffee_ratio": 1.2, "water_ratio":18.4, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "g", "grind": 20}
>>> test_params = filter_params(test_params)
>>> check_ratio_limits(test_params) == True
True
>>> check_grind_limits(test_params) == False
True
>>> test_params = {"method":"v60", "cups":2, "coffee":27.7, "water":500, "coffee_ratio": 1.2, "water_ratio":50.1, "info":"", "digits":3, "coffee_unit": "g", "water_unit": "g", "grind": 20}
>>> check_ratio_limits(test_params) == False
True
>>> check_grind_limits(test_params) == False
True
>>> chemex_params = load_method_params("chemex")
>>> chemex_params == {'info': 'Chemex method', 'water': 240, 'cups': 1, 'coffee_ratio': 1, 'water_ratio': 15, 'digits': 3, 'coffee_unit': 'g', 'water_unit': 'g', 'grind': 670}
True
Expand Down

0 comments on commit 86de1b0

Please sign in to comment.