From 626d399619472e81e38c4b6a782b871c05262bd5 Mon Sep 17 00:00:00 2001 From: hummusonrails Date: Fri, 8 May 2026 09:02:44 +0300 Subject: [PATCH] Implement list_accounts in bank --- __pycache__/bank.cpython-314.pyc | Bin 0 -> 7002 bytes __pycache__/test_bank.cpython-314.pyc | Bin 0 -> 2235 bytes bank.py | 375 +++++++++++++------------- test_bank.py | 47 ++++ 4 files changed, 238 insertions(+), 184 deletions(-) create mode 100644 __pycache__/bank.cpython-314.pyc create mode 100644 __pycache__/test_bank.cpython-314.pyc create mode 100644 test_bank.py diff --git a/__pycache__/bank.cpython-314.pyc b/__pycache__/bank.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a4f4e5b5fb7876c99b11731e00684c9324a340e3 GIT binary patch literal 7002 zcmb^$$!;9SwR)y!pCL!$PElM$fbv)i9mkHDK(-`9wu2;~<%TRei_~cLG{v@hx+m2& z6lfbTl^C!T$a0p0B?E?h6c0gwT#`dR!iEW(sgr}8aw9nbm>dG+z3OGUhcgl-yMTGD ze)X!}tE#sakM)%D1lqNC{%3wXNXS3&BWSYUX}$@aH8Mb^h(d;lB0ZDvMwo|704^Eg zBta(wE*0Vu0+$9{Cd4HLE(^F^h?AB4G^rHyKmz7?NbEo^?<<@s#$cY;6f#ZLrTL1?Wm~HmJge!t)3BM# zi;QZvtLe;iY?r4j2fiu^F1v=cMAI>|!yJ+TbXpeJg2 zeU=(^$DLIGDwB z8^0lMWJfj!hHl8W^GzTidbkbv!0n3TK-tzn5vB=EL3f>0k`#4__xO8LmmRBWP~MCD zP0dmlHA}N~!^P!hW@czXQ0vryO{xAQ-Y2AtBayI)OxDOhvPIehz1S6XlZlpray`)| zmfff=8q_~lPl&=5gM|{5g#-}{u0jV82+rY!111MQaT>Rvvj*yL9{#qsGI?EUBu z;^hhuGfHHwj3Wb~WPNrm;Zg?~+zV z^UYGGoZl{zvC3~VTRC!I>eHiN9hv+5$lPXmveg~A^W44DcTYDna;axK55(IzZHr`b z`Ty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F({VEBuwV7zE`T&9j?1Zj~27%wBPL$6a>G!T_6w8~#2^+5n&m4{|FvcsF= zF`|F?cFxnG(6InbXo={dq1sLaR_AFlnuz}h(YpHhYeNx2DTTNu3IIM56Dc}$6P9v4 zE?@T!+>vg+_1PomXnRYr{uL9VpXOz+YSmzxX}NqVCPgQb+aOI#vA;nx?xuX zA^2E~dE4k8;(UY91K3VEV?}yv^kvhACmwk0nZ$=E$|hg&i_WT-Ot$-(k+3LT3TCSK zkVP4viAmO#?hXhe-U;AssP~xA8EOM=zEbFJ<1P@;6$GmYgyZOL=oZo-xDG#e8h~%; z$!ahIBsihfeRB-G#_Q!9F^}*J|OmL5U zNbub|@aH&F89sydz>^K4#V}Cwv}x-OyoDFxv9}5@)UNJ8*@J6^=^P)_mks@@_grIG z<`r|%v`n_j4|#%h9Q+Hc5V?%#wd3LtP_oV6KnDVdbUu1jfWrpQv!v7WZ1CTS=$n6+ z6(m?8dMMt)B(g#%m68A(P71Xb25_O0c7A7d2a#%V+X;^b(x>?3rkv4P&w&sPk z0dY9(=)ZvwE>=2VFoP2x)qYp|^oRGWf4aJU^^3tDz|((W^YF~QOLs5bKmFHpU!9u& z{M7sxhhN421&sc^w@-L8Fk8GhFS8ZKdL2LCLx5&GUnzEXx$h$t9y|R2!S4}#grK|M zeHVujd;&lB2>`y|O{bpNIoPRoN~Zd^2msId;?#La1L4NKYD{En!jp?-Jrl%C)q5z; zp7I{CzZAdfZY|Tf?WW+Z%BjK1+e?{h;)3L0N9;7BK0>3 I03pTy0dujC`v3p{ literal 0 HcmV?d00001 diff --git a/__pycache__/test_bank.cpython-314.pyc b/__pycache__/test_bank.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..be9fa22c5b80aecea39cb1b2587361b0c3e33dcc GIT binary patch literal 2235 zcmbtV-ESL35a0Xs**V7~aY*ez;t~>SlGr7Qs)8a&h)`3}hH$DZ9+Ips_O&^2KAXLD zOQH%Q9%v+ZsKkqTB9G}CPy8R2fmlZ#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def __init__(self, name): - # Manages accounts, transactions, and loans. Generates unique account numbers. - self.name = name - self.accounts = [] - self.transactions = [] - self.loans = [] - - - def create_account(self, account_holder, initial_balance): - # Creates a new account with a unique number and initial balance, add it to accounts array and return account number - pass - - - def get_account(self, account_number): - # Retrieves an account by its number, returns None if not found. - pass - - - def list_accounts(self): - # Lists all accounts with their details like account number, holder, balance - pass - - - def close_account(self, account_number): - # Closes an account by removing it from the list. - pass - - - def transfer_funds(self, from_account, to_account, amount): - # Transfers funds between accounts if sufficient balance is available, return boolean values depending on - # transfer success - pass - - - def generate_account_statement(self, account_number): - # Generates a transaction history for a given account number, return None if no account number found - pass - - - - def calculate_total_assets(self): - # Calculates the total assets by summing all account balances. - pass - - - def process_loan_payments(self): - # Processes loan payments by deducting the installment amount from the balance. - pass - - -class Account: - # Represents a bank account with balance and transactions. Default balance is 0. - def __init__(self, account_number, account_holder, balance=0.0): - self.account_number = account_number - self.account_holder = account_holder - self.balance = balance - self.transactions = [] - - - def deposit(self, amount): - # Deposits a positive amount to the account and records the transaction. When adding transaction to array specift "Deposit" and amount - pass - - - def withdraw(self, amount): - # Withdraws an amount if sufficient balance is available. When adding into transactions array, specify Withdraw and amount - pass - - - def get_balance(self): - # Returns the current balance of the account. - pass - - - def get_transaction_history(self): - # Retrieves the transaction history of the account. - pass - - - def apply_interest(self, rate): - # Applies interest based on a given rate. - pass - - - def overdraft_protection(self, amount): - # Checks if a withdrawal amount is within available balance. - pass - - - def update_contact_information(self, new_contact_info): - # Updates the contact information of the account holder. - pass - - -class Transaction: - # Represents a transaction with an ID, type, amount, and timestamp. - def __init__(self, transaction_id, account_number, amount, transaction_type, timestamp): - self.transaction_id = transaction_id - self.account_number = account_number - self.amount = amount - self.transaction_type = transaction_type - self.timestamp = timestamp - - - def process_transaction(self): - # Processes a transaction if the amount is positive. - return self.amount > 0 - - - def validate_transaction(self): - # Validates the transaction before processing. - return self.amount > 0 - - - def reverse_transaction(self): - # Reverses a transaction by negating the amount. - pass - - -class BankEmployee: - # Represents a bank employee with an ID, name, and role. - def __init__(self, employee_id, name, role): - self.employee_id = employee_id - self.name = name - self.role = role - - - def approve_loan(self, account_number, amount): - # Approves a loan request if the amount is positive. - return amount > 0 - - - def view_account_details(self, account_number): - # Views account details given an account number by returning account number - pass - - - def suspend_account(self, account_number): - # Return suspension message as string - pass - - - def generate_financial_report(self): - # Return string "Financial Report Generated" - return "Financial Report Generated" - - -class Loan: - # Represents a loan with an ID, amount, interest rate, and tenure. - def __init__(self, loan_id, account_number, amount, interest_rate, tenure): - self.loan_id = loan_id - self.account_number = account_number - self.amount = amount - self.interest_rate = interest_rate - self.tenure = tenure - self.remaining_balance = amount - - - def make_payment(self, amount): - # Makes a loan payment if the amount is within the remaining balance. - pass - - - def get_remaining_balance(self): - # Returns the remaining balance of the loan. - pass - - - def calculate_interest(self): - # Calculates interest on the remaining balance. - pass - - - def check_loan_eligibility(self, account_number, income, credit_score): - # Checks if an applicant is eligible for a loan based on income(>50k) and credit score(>650). Return boolean - pass - - # Allows restructuring of the loan with new terms. - def restructure_loan(self, new_terms): - self.tenure = new_terms.get("tenure", self.tenure) - self.interest_rate = new_terms.get("interest_rate", self.interest_rate) - return True +class Bank: + + def __init__(self, name): + # Manages accounts, transactions, and loans. Generates unique account numbers. + self.name = name + self.accounts = [] + self.transactions = [] + self.loans = [] + + + def create_account(self, account_holder, initial_balance): + # Creates a new account with a unique number and initial balance, add it to accounts array and return account number + pass + + + def get_account(self, account_number): + # Retrieves an account by its number, returns None if not found. + pass + + + def list_accounts(self): + # Lists all accounts with their details like account number, holder, balance + return [ + { + "account_number": account.account_number, + "account_holder": account.account_holder, + "balance": account.balance, + } + for account in self.accounts + ] + + + def close_account(self, account_number): + # Closes an account by removing it from the list. + pass + + + def transfer_funds(self, from_account, to_account, amount): + # Transfers funds between accounts if sufficient balance is available, return boolean values depending on + # transfer success + pass + + + def generate_account_statement(self, account_number): + # Generates a transaction history for a given account number, return None if no account number found + pass + + + + def calculate_total_assets(self): + # Calculates the total assets by summing all account balances. + pass + + + def process_loan_payments(self): + # Processes loan payments by deducting the installment amount from the balance. + pass + + +class Account: + # Represents a bank account with balance and transactions. Default balance is 0. + def __init__(self, account_number, account_holder, balance=0.0): + self.account_number = account_number + self.account_holder = account_holder + self.balance = balance + self.transactions = [] + + + def deposit(self, amount): + # Deposits a positive amount to the account and records the transaction. When adding transaction to array specift "Deposit" and amount + pass + + + def withdraw(self, amount): + # Withdraws an amount if sufficient balance is available. When adding into transactions array, specify Withdraw and amount + pass + + + def get_balance(self): + # Returns the current balance of the account. + pass + + + def get_transaction_history(self): + # Retrieves the transaction history of the account. + pass + + + def apply_interest(self, rate): + # Applies interest based on a given rate. + pass + + + def overdraft_protection(self, amount): + # Checks if a withdrawal amount is within available balance. + pass + + + def update_contact_information(self, new_contact_info): + # Updates the contact information of the account holder. + pass + + +class Transaction: + # Represents a transaction with an ID, type, amount, and timestamp. + def __init__(self, transaction_id, account_number, amount, transaction_type, timestamp): + self.transaction_id = transaction_id + self.account_number = account_number + self.amount = amount + self.transaction_type = transaction_type + self.timestamp = timestamp + + + def process_transaction(self): + # Processes a transaction if the amount is positive. + return self.amount > 0 + + + def validate_transaction(self): + # Validates the transaction before processing. + return self.amount > 0 + + + def reverse_transaction(self): + # Reverses a transaction by negating the amount. + pass + + +class BankEmployee: + # Represents a bank employee with an ID, name, and role. + def __init__(self, employee_id, name, role): + self.employee_id = employee_id + self.name = name + self.role = role + + + def approve_loan(self, account_number, amount): + # Approves a loan request if the amount is positive. + return amount > 0 + + + def view_account_details(self, account_number): + # Views account details given an account number by returning account number + pass + + + def suspend_account(self, account_number): + # Return suspension message as string + pass + + + def generate_financial_report(self): + # Return string "Financial Report Generated" + return "Financial Report Generated" + + +class Loan: + # Represents a loan with an ID, amount, interest rate, and tenure. + def __init__(self, loan_id, account_number, amount, interest_rate, tenure): + self.loan_id = loan_id + self.account_number = account_number + self.amount = amount + self.interest_rate = interest_rate + self.tenure = tenure + self.remaining_balance = amount + + + def make_payment(self, amount): + # Makes a loan payment if the amount is within the remaining balance. + pass + + + def get_remaining_balance(self): + # Returns the remaining balance of the loan. + pass + + + def calculate_interest(self): + # Calculates interest on the remaining balance. + pass + + + def check_loan_eligibility(self, account_number, income, credit_score): + # Checks if an applicant is eligible for a loan based on income(>50k) and credit score(>650). Return boolean + pass + + # Allows restructuring of the loan with new terms. + def restructure_loan(self, new_terms): + self.tenure = new_terms.get("tenure", self.tenure) + self.interest_rate = new_terms.get("interest_rate", self.interest_rate) + return True diff --git a/test_bank.py b/test_bank.py new file mode 100644 index 0000000..45316ed --- /dev/null +++ b/test_bank.py @@ -0,0 +1,47 @@ +import unittest + +from bank import Account, Bank + + +class TestBankListAccounts(unittest.TestCase): + def test_list_accounts_returns_empty_list_when_no_accounts_exist(self): + bank = Bank("Test Bank") + + self.assertEqual(bank.list_accounts(), []) + + def test_list_accounts_returns_account_details(self): + bank = Bank("Test Bank") + bank.accounts = [ + Account("ACC001", "Ada Lovelace", 1250.75), + Account("ACC002", "Grace Hopper", 500.0), + ] + + self.assertEqual( + bank.list_accounts(), + [ + { + "account_number": "ACC001", + "account_holder": "Ada Lovelace", + "balance": 1250.75, + }, + { + "account_number": "ACC002", + "account_holder": "Grace Hopper", + "balance": 500.0, + }, + ], + ) + + def test_list_accounts_does_not_mutate_accounts(self): + bank = Bank("Test Bank") + account = Account("ACC001", "Ada Lovelace", 1250.75) + bank.accounts = [account] + + listed_accounts = bank.list_accounts() + listed_accounts[0]["balance"] = 0 + + self.assertEqual(account.balance, 1250.75) + + +if __name__ == "__main__": + unittest.main()