def test_withdraw(self):
     customerTest = Customer("Testing Customer")
     customerTest.set_balance(2000)
     self.assertEqual(customerTest.withdraw(1000), 1000)
     self.assertEqual(customerTest.withdraw(100), 900)
     self.assertEqual(customerTest.withdraw(25), 875)
     self.assertEqual(customerTest.withdraw(175), 700)
Ejemplo n.º 2
0
 def test_set_balance_empty(self):
     '''
     Checks that the set_balance method sets a value of 0.0 when left empty
     '''
     sample_account = Customer("Spencer")  # Creates new customer
     sample_account.set_balance()  # Sets balance with no amount set
     self.assertEqual(sample_account.balance,
                      0.0)  # Checks that the stored balance is equal to 0.0
Ejemplo n.º 3
0
 def test_deposit_empty(self):
     '''
     Checks that deposit raises an error when no amount is provided
     '''
     with self.assertRaises(TypeError):
         my_account = Customer("Spencer")
         my_account.set_balance()
         my_account.deposit()
Ejemplo n.º 4
0
 def test_set_balance_record_access(self):
     '''
     Checks that we can set and access a balance using the set_balance method
     '''
     sample_account = Customer("Steven")
     this_balance = 15.0
     sample_account.set_balance(this_balance)
     self.assertEqual(sample_account.balance, this_balance)
Ejemplo n.º 5
0
 def test_withdraw_empty(self):
     '''
     Checks that withdraw raises an error when no amount is provided
     '''
     with self.assertRaises(TypeError):
         this_account = Customer("James")
         this_account.set_balance()
         this_account.withdraw()
Ejemplo n.º 6
0
 def test_withdraw_insufficient_funds(self):
     '''
     Checks that the withdraw method will raise an exception when given a value less than the current balance
     '''
     this_balance = 250.53
     withdrawal = 999.99
     sample_account = Customer("Taylor")
     sample_account.set_balance(this_balance)
     with self.assertRaises(RuntimeError):
         sample_account.withdraw(withdrawal)
Ejemplo n.º 7
0
 def test_set_balance_modify(self):
     '''
     Checks that the set_balance method will reset/allow for modification of the balance attribute
     '''
     balance1 = 12.5
     balance2 = 14.7
     sample_account = Customer("Sarah")
     sample_account.set_balance(balance1)
     self.assertEqual(sample_account.balance, balance1)
     sample_account.set_balance(balance2)
     self.assertEqual(sample_account.balance, balance2)
Ejemplo n.º 8
0
 def test_withdraw(self):
     '''
     Checks that withdraw, when given a proper amount value, functions correctly
     Checks both the modified balance within class and the returned value by withdraw
     '''
     this_balance = 13.7
     withdrawal = 8.5
     sample_account = Customer("Jessie")
     sample_account.set_balance(this_balance)
     self.assertEqual(sample_account.withdraw(withdrawal),
                      this_balance - withdrawal)
     self.assertEqual(sample_account.balance, this_balance - withdrawal)
Ejemplo n.º 9
0
 def test_deposit_function(self):
     '''
     Checks that deposit, when given a proper amount value, functions correctly
     Checks both the modified balance within class and the returned value by deposit
     '''
     this_balance = 19.53
     this_deposit = 3.2
     sample_account = Customer("Michael")
     sample_account.set_balance(this_balance)
     self.assertEqual(sample_account.deposit(this_deposit),
                      this_balance + this_deposit)
     self.assertEqual(sample_account.balance, this_balance + this_deposit)
Ejemplo n.º 10
0
    def test_deposit(self):
        #set the testing initial balance to 10 dollars.
        Customer.set_balance(sample, balance=10.0)
        prev_balance = sample.balance

        #deposits nothing, the balance should stays the same.
        Customer.deposit(sample, 0)
        self.assertEqual(sample.balance, prev_balance)

        #deposit $10.50 and should be equal to 10.50 + previous balance.
        prev_balance = sample.balance
        Customer.deposit(sample, 10.50)
        self.assertEqual(sample.balance, prev_balance + 10.50)
Ejemplo n.º 11
0
    def test_withdraw(self):
        #set the testing initial balance to 10 dollars.
        Customer.set_balance(sample, balance=10.0)

        #draw 5 dollars out of the balance
        Customer.withdraw(sample, 5.0)
        self.assertEqual(sample.balance, 5.0)

        #draw 4.50 dollars out of the balance
        Customer.withdraw(sample, 4.50)
        self.assertEqual(sample.balance, 0.50)

        #try to draw balance over than the previous balance and make sure
        #the error display is correct too.
        with self.assertRaises(Exception) as content:
            Customer.withdraw(sample, 1.00)

        #it has to be same display as the given error in sample_account.py
        self.assertTrue(
            'Amount greater than available balance.' in content.exception)
 def test_set_balance(self):
     customerTest = Customer("Testing Customer")
     customerTest.set_balance(6050)
 def test_deposit(self):
     customerTest = Customer("Testing Customer")
     customerTest.set_balance(4000)
     self.assertEqual(customerTest.deposit(200), 4200)
     self.assertEqual(customerTest.deposit(10), 4210)
     self.assertEqual(customerTest.deposit(400), 4610)
def createUser(balance, name):
    """Create a user with a given balance and name"""
    user = Customer(name)
    user.set_balance(balance)

    return user
Ejemplo n.º 15
0
 def test_set_balance(self):
     Customer.set_balance(sample)
     self.assertEqual(sample.balance, 0.0)
Ejemplo n.º 16
0
#made by Wookjin Jang
#Edited: 12/19/2017

from sample_account import Customer
import unittest

#initalize the value for sample.
sample = Customer("Alex")
Customer.set_balance(sample)


#start the test_case.
class MyTest(unittest.TestCase):

    #test the __init__ function, already used the __init__ above.
    def test_init(self):
        #print "testing the __init__ with customer name Alex"
        self.assertEqual(sample.name, "Alex")

    #test the set_balance function.
    def test_set_balance(self):
        Customer.set_balance(sample)
        self.assertEqual(sample.balance, 0.0)

    #test the withdraw function.
    def test_withdraw(self):
        #set the testing initial balance to 10 dollars.
        Customer.set_balance(sample, balance=10.0)

        #draw 5 dollars out of the balance
        Customer.withdraw(sample, 5.0)