コード例 #1
0
 def test_withdraw_no_balance(self):
     '''
     Checks that an error is raised if the balance attribute is not set
     '''
     with self.assertRaises(AttributeError):
         this_account = Customer("Lynn")
         this_account.withdraw(15)
コード例 #2
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)
コード例 #3
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
コード例 #4
0
 def test_init_modify(self):
     '''
     Checks that the name attribute can be modified
     '''
     customer_name1 = "Brad"
     customer_name2 = "Steven"
     sample_account = Customer(customer_name1)
     self.assertEqual(customer_name1, sample_account.name)
     sample_account.name = customer_name2
     self.assertEqual(customer_name2, sample_account.name)
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
 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)
コード例 #8
0
 def test_init_record_access(self):
     '''
     Checks that the __init__ method creates new Customer objects and stores the provided name
     '''
     customer_name = "Brad"
     sample_account = Customer(customer_name)
     self.assertEqual(customer_name, sample_account.name)
コード例 #9
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()
コード例 #10
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()
コード例 #11
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)
コード例 #12
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)
コード例 #13
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)
コード例 #14
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)
コード例 #15
0
 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)
コード例 #16
0
def createUser(balance, name):
    """Create a user with a given balance and name"""
    user = Customer(name)
    user.set_balance(balance)

    return user
コード例 #17
0
 def test_set_balance(self):
     customerTest = Customer("Testing Customer")
     customerTest.set_balance(6050)
コード例 #18
0
 def test_set_balance(self):
     Customer.set_balance(sample)
     self.assertEqual(sample.balance, 0.0)
コード例 #19
0
 def test_init_empty(self):
     '''
     Checks that the __init__ method raises an error when no name is provided
     '''
     with self.assertRaises(TypeError):
         Customer()
コード例 #20
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)