From 5e49b11629afe634b2a3ccf0abbb0ac728f829b2 Mon Sep 17 00:00:00 2001 From: hummusonrails Date: Thu, 7 May 2026 09:02:15 +0300 Subject: [PATCH] Implement close account --- __pycache__/bank.cpython-314.pyc | Bin 0 -> 6959 bytes .../test_bank_close_account.cpython-314.pyc | Bin 0 -> 1882 bytes bank.py | 372 +++++++++--------- test_bank_close_account.py | 30 ++ 4 files changed, 218 insertions(+), 184 deletions(-) create mode 100644 __pycache__/bank.cpython-314.pyc create mode 100644 __pycache__/test_bank_close_account.cpython-314.pyc create mode 100644 test_bank_close_account.py diff --git a/__pycache__/bank.cpython-314.pyc b/__pycache__/bank.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4ae44cacb5f15d232e97a64c318e12afddb741ab GIT binary patch literal 6959 zcmb^$O>Y~=b(Y_sB5jHKwj^7z68cMNYBzRkq;Zhg0TL+6!jMw5&Ste-$y+a%%qaVTncb$9~YA|)1;i$JPGix`ol;Z$XGH_*SISDW$12>kH(*SdFhUFIs>yxvot2;1}LjWWp)Ynajd?|Q;K3(22&KC$E_XnK2bD#AAmLT<-qW*baQz0M(kF; zIX-bCwvifXmWFP`Zf9CBfoT3V-~+cSjss;|14Wo7G!ET$QjSv8A>QZiO}SVzD>~%` zfRX)g_&}$La`?UD25@K~YE$z#tV`LLfN%7Y>-6IZJ}Gjg#En=1s%)IoW)#U=_j% zK5b^cJ^_sw{KV1!96D>Dd-L$OvlYqN7YM0G79#V(weGY9>Et_vtN@j9@&?#>cN+6} z)*Wpja@^hcB$*V~o+cAub6_=*^Jn4ildyme1KZV>8i$e7u)@Y;S|g7WB%OakMW#cz-th*`@r|zNmQDlKqu30-s=CGaq^rff zCX|8L(gp=) z-R7f$ch|AwA=Yr+LT}TEMUO^P0OraC^qc6Z!Ea_1rCO^rOzh_r<^6_gx+4WeSvIK6 zOvBQxnxfDgQs_r8f&kqsJ%Hdj1cwnEL+}j%yrhWhGBibHj2cS~rrW?`kD_QMoMFY# zn5LViqO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*`2NTisA5R!qXMa_Xp(!Pl{)BD3Is9%vHhEmM55QHK@+_K#fO*!k)F_ zCGTET{|KlCob-?J^E!a;Q9X~_^c~0VaUR|UI1cfUa$Z&#)`3ImQ~kL5>Ff6@pIutN^u^$}p`M>@?wk3;h2LGc z_uap|`tbDJ{nK+_?0X9f{G)#>^b2nWX4_7|g|U7FV=H*l5+WVf;R zYXo-@^!B@JIE>&E_}N$&bNy~2{@mu?(6dQ+;H^wFKJbVDaGWnLor5$GZrpi|iEK@H zazWNHcFa_r8fogZQ@neLB16;+`xJmjQAv`vA}6H$V*+5SE|swhVCx-e5W4`jUKo*% RJSG6PP9Bg3S_FWQ;(x?fh#>#~ literal 0 HcmV?d00001 diff --git a/__pycache__/test_bank_close_account.cpython-314.pyc b/__pycache__/test_bank_close_account.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..319ecdf7cbab2d1b725399f1121601395e74b091 GIT binary patch literal 1882 zcmb7E&rcgi6rTOb#<63zfNi1#gB+zXDYnu&Y7S8aL{xA{f>y|BrNC%eFRwz>MS68Uf?# ztQ~yj^mMH8T+5O4_N=vPoS(Zge#g-VfLmmWsPL}*2_BunldyDs-wWJ|HsV~g@2SCGq6 zAd4Vkl%>Uij@Bzzq~j=R87-dcwRQBe+TD>wu;cs*JETSRgjJ;=m7?fSZVhUozfM?g zy=K{7Wn7e)Ycsy*xGy`-pH6dSwzj$+&ZcYA_wqUsxI`SD8+NBTlqVcfPaMs8%%;>O zY>6~ne!ip6ecrHrsJu#De~qiFVW>5aP{wuYI<=s}b>h;7&!{N>)o~bnzE~&TBb&KJ zR;?FT1reT1ZGd#iRMn{$31m)--TaFT8i@rm?n|dof5NYaw!URd+-mKSOL5g^&W0DP zAE$r&ZFUsS;4KFziqK_Pw*K@}jVO2ivO#4RA=?dqc- ziHqd~h%V1Qwtb*p5>~)-P*_c2HQdJ@Wzb{-ZxNz`!-8UDL>Ok!4=CeN3SfNUbWAw~)H@=r2O#=rGjy?aqqV-(Xb(*_js4MyR;-^Wvu*R;kSGy3 zQoF|Z+f>PH$DSJ>kPKk|1l2RRfpK70U5t4Q<7%za@P!`7SX|M_lEgT?oW2*hK@DS) z0(Wu=1RueeGMjl0wizSdY6GeV{w9W72Y0>VIm~f=ALG2l6FrOICLYh}u;xS;ctVJe zil+SY6wdyad`^4+@06jH4iShj>u{UMx@vm?z`_X{fyYGC!sdpLQTQxzV+j`T*ua1g zKMSy26>ek<)DBwMa^rUA;2)7mFo?Y9O%R8QBuT%Z 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 + pass + + + def close_account(self, account_number): + # Closes an account by removing it from the list. + for account in self.accounts: + if account.account_number == account_number: + self.accounts.remove(account) + return True + return False + + + 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 \ No newline at end of file diff --git a/test_bank_close_account.py b/test_bank_close_account.py new file mode 100644 index 0000000..6692977 --- /dev/null +++ b/test_bank_close_account.py @@ -0,0 +1,30 @@ +import unittest + +from bank import Account, Bank + + +class CloseAccountTest(unittest.TestCase): + def test_close_account_removes_matching_account(self): + bank = Bank("RepoRaid Bank") + first = Account(1, "Alice", 100.0) + second = Account(2, "Bob", 250.0) + bank.accounts = [first, second] + + result = bank.close_account(1) + + self.assertTrue(result) + self.assertEqual(bank.accounts, [second]) + + def test_close_account_returns_false_when_account_is_missing(self): + bank = Bank("RepoRaid Bank") + existing = Account(1, "Alice", 100.0) + bank.accounts = [existing] + + result = bank.close_account(99) + + self.assertFalse(result) + self.assertEqual(bank.accounts, [existing]) + + +if __name__ == "__main__": + unittest.main()