示例#1
0
def createBank(number=0):
    """Saves a bank with the specified number of accounts.
    Used during testing."""
    bank = Bank()
    for i in range(number):
        bank.add(SavingsAccount('Name' + str(i + 1), str(1000 + i), 100.00))
    bank.save("bank.dat")
示例#2
0
def createBank(number=0):
    """Saves a bank with the specified number of accounts.
    Used during testing."""
    bank = Bank()
    for i in xrange(number):
        bank.add(SavingsAccount("Name" + str(i), str(1000 + i), 100.00))
    bank.save("bank.dat")
示例#3
0
def main(number=0):
    """Instantiate a Bank and an ATM and run it."""
    bank = Bank()
    for i in range(number):
        bank.add(SavingsAccount('Name ' + str(i + 1), str(1000 + i), 100.00))
    atm = ATM(bank)
    atm.run()
    bank.save("bank.dat")
示例#4
0
def testBank(self,number = 0):
    '''Returns a bank with the specified number of accounts and/or
    the accounts loaded from the specified file name.'''
    bank = Bank()

    for i in xrange(number):
        bank.add(SavingsAccount('Name' + str(i + 1),str(1000 + i),100.00))
    return bank
示例#5
0
def main(number):
    bank = Bank()
    for i in range(number):
        bank.add(SavingsAccount('Name' + str(i + 1),
                                str(1000 + i),
                                100.00))

    """Instantiate a bank and use it in an ATM."""
    
    print("The bank has been loaded")
    
    atm = ATM(bank)
    print("Running the GUI")
    atm.mainloop()
    
    bank.save('bank.dat')
    bank.__init__("bank.dat")
    
    print("The bank has been updated")
示例#6
0
文件: run.py 项目: bps24/Retail_Bank
def createBank(num=5):
    """Returns a bank object with a given number of accounts"""
    bank = Bank()
    customers = []
    for i in range(num):
        #random account type
        acc = random.randrange(4)
        #random starting balance
        bal = random.randrange(10_000)
        #random name and random choice of student or not
        cust = Customer(getFirst(), getLast(), random.choice([True, False]))
        if acc == 0:
            bank.add(Advantage_Relationship_Account(cust, 1000 + i, bal))
        elif acc == 1:
            bank.add(Advantage_Savings_Account(cust, 1000 + i, bal))
        elif acc == 2:
            bank.add(Advantage_Safe_Account(cust, 1000 + i, bal))
        else:
            bank.add(Advantage_Plus_Account(cust, 1000 + i, bal))
    print(bank)
示例#7
0
文件: CH9P3.py 项目: ozmaws/Chapter-9
def main():
    bank = Bank()
    bank.add(Account("Alex", "1111", 1024.0))
    bank.add(Account("Carson", "2222", 2048.0))
    bank.add(Account("Chase", "3333", 2048.0))
    bank.add(Account("Silas", "4444", 1024.0))
    bank.add(Account("Ramiro", "5555", 512.0))
    bank.add(Account("Don", "6666", 2048.0))
    bank.add(Account("Carmen", "7777", 512.0))
    bank.add(Account("Ann", "8888", 32.0))
    bank.add(Account("Ryuji", "9999", 256.0))
    bank.add(Account("William", "0000", 64.0))
    bank.add(Account("Haru", "1212", 128.0))
    bank.add(Account("Lucy", "2323", 1024.0))
    bank.add(Account("Yusuke", "3434", 64.0))
    bank.add(Account("Gorokichi", "4545", 128.0))
    bank.add(Account("Akechi", "5656", 512.0))
    bank.add(Account("Loki", "6767", 256.0))
    bank.add(Account("Makoto", "7878", 128.0))
    bank.add(Account("Johanna", "8989", 64.0))
    bank.add(Account("Arsene", "9090", 256.0))
    print(TITLE)
    print(bank)
示例#8
0
class BankTest(unittest.TestCase):
    def setUp(self):
        self._bank = Bank()
        self._bank.addRate('CHF', 'USD', 2)
        self._five_dollars = Money.dollar(5)
        self._ten_dollars = Money.dollar(10)
        self._fifteen_dollars = Money.dollar(15)
        self._five_francs = Money.franc(5)
        self._ten_francs = Money.franc(10)
        self._thirty_francs = Money.franc(30)

    def test_identity_rate(self):
        assert_that(self._bank.rate('USD', 'USD'), is_(equal_to(1)))

    def test_custom_rate(self):
        assert_that(self._bank.rate('CHF', 'USD'), is_(equal_to(2)))

    def test_inverse_rate(self):
        assert_that(self._bank.rate('USD', 'CHF'), is_(equal_to(0.5)))

    def test_currency_conversion(self):
        assert_that(self._bank.convert(self._ten_francs, to='USD'),
                    is_(equal_to(self._five_dollars)))
        assert_that(self._bank.convert(self._five_dollars, to='CHF'),
                    is_(equal_to(self._ten_francs)))

    def test_simple_addition(self):
        assert_that(self._bank.add(self._five_dollars, self._five_dollars),
                    is_(equal_to(self._ten_dollars)))

    def test_mixed_addition(self):
        assert_that(
            self._bank.add(self._five_dollars, self._ten_francs, to='USD'),
            is_(equal_to(self._ten_dollars)))

    def test_multiple_addition(self):
        assert_that(
            self._bank.add(
                self._bank.add(self._five_dollars, self._five_dollars),
                self._five_dollars), is_(equal_to(self._fifteen_dollars)))

    def test_simple_multiplication(self):
        assert_that(self._bank.multiply(self._five_francs, by=2),
                    is_(equal_to(self._ten_francs)))

    def test_multiplication_of_sum(self):
        assert_that(
            self._bank.multiply(self._bank.add(self._five_francs,
                                               self._five_francs),
                                by=3), is_(equal_to(self._thirty_francs)))

    def test_subtraction(self):
        assert_that(self._bank.subtract(self._ten_dollars, self._five_dollars),
                    is_(equal_to(self._five_dollars)))

    def test_multi_currency_comparison(self):
        assert_that(
            self._bank.compare(self._ten_francs, to=self._five_dollars),
            is_(True))
        assert_that(
            self._bank.compare(self._five_francs, to=self._ten_dollars),
            is_(False))