/test_fixtures_bank_account.py Secret
Created
June 2, 2023 16:40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InsufficientFund(Exception): | |
pass | |
class BankAccount: | |
def __init__(self, balance: float) -> None: | |
if balance < 0: | |
raise ValueError('balance cannot be negative') | |
self._balance = balance | |
@property | |
def balance(self) -> float: | |
return self._balance | |
def deposit(self, amount: float) -> None: | |
if amount <= 0: | |
raise ValueError('The amount must be positive') | |
self._balance += amount | |
def withdraw(self, amount: float) -> None: | |
if amount <= 0: | |
raise ValueError('The withdrawal amount must be more than 0') | |
if amount > self._balance: | |
raise InsufficientFund('Insufficient ammount for withdrawal') | |
self._balance -= amount |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment