Possible Bug (Rounding Error) in Unit Test. Scientific Computing with Python Projects - Budget App

Tell us what’s happening:
The test_module.py module may have a bug. My budget.py module passed all the tests except one where the it’s supposed to construct a bar chart based on budget information.

Your code so far
From the test_module.py (lines 93 - 102) uses the following test information:
food = Category(“Food”)
entertainment = Category(“Entertainment”)
business = Category(“Business”)
food.deposit(900, “deposit”)
entertainment.deposit(900, “deposit”)
business.deposit(900, “deposit”)
food.withdraw(105.55)
entertainment.withdraw(33.40)
business.withdraw(10.99)

The percentage of business withdrawals based on the above budget data is approx.: 7.3296 and this rounds to 10 (nearest 10) but it seems test_module.py rounds this to 0. And this may have thrown the assertion error below:

Traceback (most recent call last):
File “/home/runner/boilerplate-budget-app-1/test_module.py”, line 102, in test_create_spend_chart
self.assertEqual(actual, expected, ‘Expected different chart representation. Check that all spacing is exact.’)
AssertionError: 'Perc[170 chars] 10| o o o \n 0| o o o \n ----------[180 chars] t ’ != 'Perc[170 chars] 10| o o \n 0| o o o \n ----------[204 chars] t ’

I might be wrong about this and any help concerning this will be very much appreciated.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0

Challenge: Scientific Computing with Python Projects - Budget App

Link to the challenge:

Hi, don’t just work based on this set of questions but decide if a transfer is a withdraw in general case so any data passed through would work. Construct your solution based on the correct concept, it will work.

In the case I shared, which is from test_module.py, there was no transfer, only withdrawals and deposits and it seems that the estimate of the percentage of withdrawals was rounded wrongly by the test. Also please note that my code passed all the tests except this case I shared.

Then read the question again about how the answer should be formatted.

I was able to resolve this issue by adjusting my code for the special case where the percentage of the withdrawals is 0.0733 (7.33%) and instead of rounding it to 10%, I rounded it to 0% (so that I can pass the one test my code keeps failing). Outside this case, I applied the standard rule for rounding to the nearest 10.

You need to check the spec because rounding to the nearest 10 is not what is required, so the other case is not a special case.

Hi Jeremy,

Please see the copied part of the spec below. I highlighted to the part of the spec where it is required for the height of the bars in the chart to be rounded to the nearest 10.

“The chart should show the percentage spent in each category passed in to the function. The percentage spent should be calculated only with withdrawals and not with deposits. Down the left side of the chart should be labels 0 - 100. The “bars” in the bar chart should be made out of the “o” character. THE HEIGHT OF EACH BAR SHOULD BE ROUNDED TO THE NEAREST 10.”

The project page says:

The height of each bar should be rounded down to the nearest 10.

Emphasis is mine.