-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rspec test suite #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the file guest_macro_parser.rb
there are too many numbers and letters that define a decision and is extremely hard to follow.
I would suggest to extract those values into ruby constants and maybe even a module where you define common behaviors.
Other things:
- The age case can be extracted into a function.
- The weight rate case should be extracted into a function and the values "Maintain", "Lose" and "Gain" should be modified to be a Constants.
- Genders should be constants.
- the brm should be fetched via a function.
In other words, if you could create (within the possibility) the @calories
, @protein
, @fat
and @carbs
by just calling 4 functions inside the parse!
function, your code will be a lot cleaner and easier to read.
@@ -11,9 +11,9 @@ def parse! | |||
bmr, age, tdee_coef, weight_rate_factor = 0, 0, 0, 0 | |||
|
|||
if params[:gender] == "M" | |||
bmr = ((9.99 * params[:weight].to_f) + (6.25 * params[:height].to_f) - (4.92 * age.to_f) + 5).to_i | |||
bmr = ((9.99 * params[:weight].to_f) + (6.25 * params[:height].to_f) - (4.92 * params[:age].to_f) + 5).to_i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does these numbers mean? could you comment on that?
Also, the bmr calculation for Male and Female are only different by 1 field (the +5 and the -161), please merge this into 1 line instead where you setup that number as a variable. i.e:
class GuestMacroParser
FEMALE = "F"
MALE = "M"
....
def get_bmr
gender_constants = {FEMALE => -161, MALE => 5}
gender = gender_constants[@params[:gender]]
weight_coef = (9.99 * params[:weight].to_f)
height_coef = (6.25 * params[:height].to_f)
age_coef = (4.92 * params[:age].to_f)
return (weight + height - age + gender).to_i
end
Notice this is not tested so it's just as an example.
Now, getting the expected bmr coefficient is very easy to test, and you should do so.
ok! Separating the macro parsers into a couple functions and testing them individually would probably be a better idea long term. I'll get on that ASAP. |
👍 |
Wrote a test suite that covers the User model, user session management and nutrition calculations for users and guests.
Learned some Rspec along the way too :)