From 65e8809513ec1f45574cf346d72e3f1970aa0a36 Mon Sep 17 00:00:00 2001 From: hummusonrails Date: Wed, 6 May 2026 09:05:45 +0300 Subject: [PATCH] Implement overdraft protection --- __pycache__/bank.cpython-314.pyc | Bin 0 -> 6812 bytes __pycache__/test_bank.cpython-314.pyc | Bin 0 -> 1831 bytes bank.py | 370 +++++++++++++------------- test_bank.py | 25 ++ 4 files changed, 211 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..a12397e20b37475cce82f3e16359609087da91d3 GIT binary patch literal 6812 zcmb^#U2hy$_0I0>?(CP>j=w(=JF#NAO&X`Afe=M)T1qGqm~<3k1WktV?ARVWJG0!m zo8YDbw;)I=D^MXp%1e=Wi60OWFYq%`)hh0N3gU^kB#UIk6X)Fd*qQaNk4#qkmD+0l1f=`UU)7y8BiNVV zi2XDnO6xpyHppVXBhUy=kt@Urx;X?PZ#U*&Z%AH^h=8XXZSsH|Cdc_WEXsirB~5bq22rmebm&7{17{4L$q zmULTp4AaBq=H}*TQBWJygiUF|Bt9slOd^r6g-kZcKa>*fgI+>Ky=0>OK)IFb5X))S zmrNQQt1m=x#bl8L{X&8m23Mir6vXEoDI75SbCv{W4~c@^mTk+6IC=b#V3oiLK5b@^ zJw1sT9R-TSrpkuxdhLVtc_nZYFeSDz89u|d@5ZXKf25^l>ei!kD=;_eXZ5-;Z(I^o z9qL-x`m#y2<)%~f0$nGO(=fx!0oWjqvLs)AN^S2whKUu^F=@=iG>^eo-Ew=o=)K|VtOAjblYg!CA0FkOSr-yf^h^GgXj!`IRsS%ClSm8;KQ0wmt|-=W7Jw|GSdSV1Da;oaE3L@ zV1{YinzkkJatsO6@c1tX|E3sm1VEhkWdQ&AB^cOaIg=TC+@H#n9~U}68gM1VA=t&y zh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f!lx{$2h3`X64uSNrqY*4oD- z=iu?YxN~^!!>b=$z4!9pUi-ZKD#xSP#9^Z3x-ThwkLof&#a0QkWd zr!GJl2pacqW1?CUkz6e6rzCuj_utW#^Zp~?OB5NRWq4l!@Gvb&(r)T`sr-ll*j<%Q gU>Csdo6-n&0qnjoE}eWt0PLPUCJnU+03pTy0AYM^pa1{> 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..98f237f4e623097e077d6b43a6100cc2c7ac2004 GIT binary patch literal 1831 zcmcgt&2JM&6o30=FUF}M0%FssX#|v7Rj@z~R0OAvqE_WVh*oI?Qo}G=Z^FWQ*UXNg zaEdtaaq2b4NWG97H;(PU5E)@Ka6m!`aSH^AiW6`4!&E4xaG)dk&70Zx`Fn4kzx$#u z2e@{NH||{(;E6n>%Sf1w-;h~?Ghivlfy-SzuKcWWbqIFCFj(3ESo$1HXHvy?dsT~h zuFn~k@%<@)#twi%K5lN}n49s&n3$X#IVg+?&$XRrvCq@>#fbUKs!x?QCc_jt8io$zGpy~19YG2L zY4uQ8RfQfp-h#-|xCkM33w-mnI9h2j_Y&n!g*RK3d0C$;Bj=DhY@}(oD$HpGVZ}mf zQMXayh&7p~{)GdrD`Gf0QO^r5hlDnzF1hUTbFPmf9`$WU)IVID1OI6ui(!W2NS5GH ze`$ID%8}bYcKQ$9%sw{rzZY&5mb2Yrb*)&vGt(&^y=RU+c<=g`PI2tMd29nMz~-%R zHZuPCS|KhalZh}>k}XIUFV=G1Kj3tIYBee0*0_W}Q4cG*Rm#a1mXwJVkWcVt&Ux(Y z9^iBy>-}kXf5<|gbXrET3Eo|^xMmiY2fC%vwbJOFg-)q<-yCQCDE&V`tEaCc-SL%Z z@|C;??Nt0cVEs>qvuYC<2cxD-LGYbL%3XvoZeTI?F&+Ca$`Xl>1h3I4$-a!hTgCCX zMVN&6wCNBca)dO4M%$Boo{)=e>Lp(age 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. + 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. + if amount < 0: + return False + return amount <= self.balance + + + 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..21ec277 --- /dev/null +++ b/test_bank.py @@ -0,0 +1,25 @@ +import unittest + +from bank import Account + + +class TestAccountOverdraftProtection(unittest.TestCase): + def test_allows_amount_within_balance(self): + account = Account("ACC-1", "Alice", 100.0) + + self.assertTrue(account.overdraft_protection(75.0)) + self.assertTrue(account.overdraft_protection(100.0)) + + def test_rejects_amount_above_balance(self): + account = Account("ACC-1", "Alice", 100.0) + + self.assertFalse(account.overdraft_protection(100.01)) + + def test_rejects_negative_amount(self): + account = Account("ACC-1", "Alice", 100.0) + + self.assertFalse(account.overdraft_protection(-1.0)) + + +if __name__ == "__main__": + unittest.main()