0% found this document useful (0 votes)
16 views2 pages

Training 1

Uploaded by

speedychamp05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Training 1

Uploaded by

speedychamp05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import json import unittest

import pickle import pythonChallenge


class Bank:
accounts = {} class test(unittest.TestCase):
file = open('data.txt','rb') def test_1createAccount(self):
def __init__(self): pythonChallenge.Bank.createAccount(pythonChallenge.
d = self.file.read() Bank, 'Shubhendu', 1001)
self.accounts = pickle.loads(d) self.assertTrue(pythonChallenge.Bank.accounts.__contai
pass ns__(1001))
def writeToFile(self,acc):
self.file = open('data.txt','wb+') pythonChallenge.Bank.createAccount(pythonChallenge.
pickle.dump(acc,self.file) Bank, 'Ashok', 1002)
# self.file.write(str(acc)) self.assertTrue(pythonChallenge.Bank.accounts.__contai
# self.file.write(pickle.dumps(acc)) ns__(1001))

def createAccount(self,name,accNumber): def test_2deposit(self):


self.name = name pythonChallenge.Bank.deposit(pythonChallenge.Bank,10
self.accounts[accNumber] = 01,5000)
{'name':self.name, 'balance': 0, 'transaction':[]} self.assertDictEqual(pythonChallenge.Bank.accounts[100
self.writeToFile(self.accounts) 1],{'name': 'Shubhendu', 'balance': 5000, 'transaction':
[5000]})

def deposit(self,accNumber,amount): pythonChallenge.Bank.deposit(pythonChallenge.Bank,10


self.accounts[accNumber]['balance'] += 02,7000)
amount self.assertDictEqual(pythonChallenge.Bank.accounts[100
self.accounts[accNumber]['transaction'].appe 2],{'name': 'Ashok', 'balance': 7000, 'transaction': [7000]})
nd(amount)
self.writeToFile(self.accounts) def test_3transfer(self):
pythonChallenge.Bank.transfer(pythonChallenge.Bank,1
def withdrawal(self,accNumber,amount): 002,1001,1500)
if self.accounts[accNumber]['balance'] self.assertDictEqual(pythonChallenge.Bank.accounts[100
>=amount: 1],{'name': 'Shubhendu', 'balance': 6500, 'transaction': [5000,
self.accounts[accNumber]['balance'] -= 1500]})
amount self.assertDictEqual(pythonChallenge.Bank.accounts[100
self.accounts[accNumber]['transaction'].ap 2],{'name': 'Ashok', 'balance': 5500, 'transaction': [7000,-
pend(-amount) 1500]})
self.writeToFile(self.accounts)
def transfer(self, accFrom, accToo, amount): def test_4withdrawal(self):
if self.accounts[accFrom]['balance'] pythonChallenge.Bank.withdrawal(pythonChallenge.Ban
>=amount: k,1001,2000)
self.accounts[accFrom]['balance'] -= self.assertDictEqual(pythonChallenge.Bank.accounts[100
amount 1],{'name': 'Shubhendu', 'balance': 4500, 'transaction': [5000,
self.accounts[accToo]['balance'] += amount 1500, -2000]})
self.accounts[accFrom]['transaction'].appen
d(-amount) def test_5showRegister(self):
self.accounts[accToo]['transaction'].append print(pythonChallenge.Bank.accounts)
(amount) self.assertDictEqual(pythonChallenge.Bank.accounts,{10
self.writeToFile(self.accounts) 01: {'name': 'Shubhendu', 'balance': 4500, 'transaction':
def showRegister(self): [5000, 1500, -2000]}, 1002:{'name': 'Ashok', 'balance': 5500,
for key, value in self.accounts.items(): 'transaction': [7000,-1500]}}
print('Account Number :' + str(key))
for key, value in value.items():
print(key + ' : '+ str(value))
print('______________________________
__________')

Internal to Wipro
Internal to Wipro

You might also like