Zero Division Error bug #40.
So yesterday I've started working on this bug. I've estimated it for about 1h.
It was fortunatelly a very realistic estimation. When making changes and creating Test-case for this issue, I've found myself thinking, is it really possible to use BMI health check for people who are less then 1m hight.
So I've looked at internet and VoilĂ ! Other calculators do that! So without struggle I've adapted my code to be able to put less height then 1m long.
I know it may sound like a trifle, but I've thought that people using this application will probably not lie to themselves and make a fake data.
What was wrong with my code?
My assuption is that height is setup in centimeters.
That's why I've fallen into situation where I need to change floating point number to adjust formula not to return zeros.
Test source code:
def test_height_less_hundred(self):
""" tests for height less then hundred if not raises ZeroDivisionError"""
self.user.height = 99
self.user.weight = 50
self.user.name = "under hundred height"
self.user.surname = "under fifty weight"
self.assertEquals(self.user.bmi(), 51.02)
BMI method source code:
As you can see by code below, I've decided to change all the parameters inside of bmi method into float's .
It's not best, because I could change them at the initialization part, but still - *Done is better then perfect!*
def bmi(self):
"""
Body Mass Index calculator simplified to number
"""
return round((float(self.weight) / (float(self.height)*float(self.height))) * 10000, 2)
Code commits done for this post:
- Refactors from pylint issues
- Fixes #40.
- Adds failing test for BMI ZeroDivisionError
- Feature/24 routes user have been based on gpx files (#42)
Acknowledgements
What's next
I'm going to continue my hunt for Python Milestone Issues
Thanks! See you soon!
Comments
comments powered by Disqus