Python Unittest Problem, Project: Budget App

Hi ! Guys thanks in advance for the help. I’m having problems with this test (test_check_funds) I’m cracking my head and i think something is wrong with the logic in that test.

In bold the problem, this is the snippet of the function:

def test_check_funds(self):
        self.food.deposit(10, "deposit")
        actual = self.food.check_funds(20)
        expected = False
        **#self.assertEqual(actual, expected, 'Expected `check_funds` method to be False')**
        actual = self.food.check_funds(10)
        expected = True
        self.assertEqual(actual, expected, 'Expected `check_funds` method to be True')

I had to comment that line and all tests were ok, I verify my function (check_funds) and it working as expected, because withdrawn function depend on it. Sorry if my English is not good is my second language. It will be welcome if you guys give me a feedback about it, because i would love to avance to the next project without worries.

Hi @widolite-hezz :grinning: Can u please share your function?
I think there is no problem with the testcase because it should return False to withdraw 20 when balance is only 10 and it is returning as expected.

Have a good day :smiley:

Hi @Ganesh_27 thanks for you reply :smiley:, sure this is my function:

def check_funds(self, amount):
        """ this method is used by withdraw and transfer """
        if amount < sum([item['amount'] for item in self.ledger]):
            return False
        return True

I have a problem with the test_create_spend_chart test. The original code is here:
https://repl.it/@freeCodeCamp/fcc-budget-app#test_module.py

And my code here: https://repl.it/@Ihmemies/fcc-budget-app#budget.py

I printed out the unit test’s ledgers:

***********Business***********
deposit                 900.00
                        -10.99
Total: 889.01
*************Food*************
deposit                 900.00
                       -105.55
Total: 794.45
********Entertainment*********
deposit                 900.00
                        -33.40
Total: 866.6

So 0-10% of the budget is used. It should produce a chart like this:

Percentage spent by category
100|          
 90|          
 80|          
 70|          
 60|          
 50|          
 40|          
 30|          
 20|          
 10|    o     
  0| o  o  o  
    ----------
     B  F  E  
     u  o  n  
     s  o  t  
     i  d  e  
     n     r  
     e     t  
     s     a  
     s     i  
           n  
           m  
           e  
           n  
           t  

Instead the unit test expects the chart to look like this, a lot higher bars:

100|          
 90|          
 80|          
 70|    o     
 60|    o     
 50|    o     
 40|    o     
 30|    o     
 20|    o  o  
 10|    o  o  
  0| o  o  o  
    ----------
     B  F  E  
     u  o  n  
     s  o  t  
     i  d  e  
     n     r  
     e     t  
     s     a  
     s     i  
           n  
           m  
           e  
           n  
           t  

type or paste code here

I do not understand why :woozy_face:

Only explanation I have figured out that the readme wants me to do it the other way. I thought it should display what % of each budget was used.

Instead apparently it wants me to display what categories I have spent the money for. I do not understand why it wants to display it like that, for me it does not make sense but if it is what is wanted then it is so. Sorry for wasting your time…

Hi @widolite-hezz.

The condition should be greater than because when available balance is less than the withdrawal amount then it should return False :grin: otherwise you should be able to withdraw so it returns true.

Feel free to ask me if any confusion in my explanation :blush:

def check_funds(self, amount):
“”" this method is used by withdraw and transfer “”"
if amount > sum([item[‘amount’] for item in self.ledger]):
return False
return True

Hi @Ganesh_27

My readme.md sound like this:

A check_funds method that accepts an amount as an argument. It returns False if the amount is less than the balance of the budget category and returns True otherwise. This method should be used by both the withdraw method and transfer method.

That why I put that if statement :sweat_smile:
Maybe it is an error on the Readme.md file ?

Let me try that, Thanks .

Hi @Ganesh_27 I proved it and it is working as expected, thanks for your help, maybe i misinterpret the check_found function explanation in the readme.md file. :smile: , now i can move forward to the next project, thanks a lot.

Happy that it helped you out :blush: