Skip to content

Commit

Permalink
Clase 14: Uso de doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
lcmartinezdev committed Aug 29, 2024
1 parent 751d814 commit 336a33c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/calculator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
def sum(a, b):
"""
>>> sum(5, 7)
12
>>> sum(4, -4)
0
"""
return a + b


Expand All @@ -11,6 +18,12 @@ def multiply(a, b):


def divide(a, b):
"""
>>> divide(10, 0)
Traceback (most recent call last):
ValueError: La división por cero no está permitida
"""

if b == 0:
raise ValueError("La división por cero no está permitida")
return a / b
14 changes: 14 additions & 0 deletions tests/test_bank_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ def test_withdraw_disallow_after_bussines_hours(self, mock_datetime):
mock_datetime.now.return_value.hour = 18
with self.assertRaises(WithdrawalTimeRestrictionError):
self.account.withdraw(100)


def test_deposit_multiple_ammounts(self):

test_cases = [
{"ammount": 100, "expected": 1100},
{"ammount": 3000, "expected": 4000},
{"ammount": 4500, "expected": 5500},
]
for case in test_cases:
with self.subTest(case=case):
self.account = BankAccount(balance=1000, log_file="transactions.txt")
new_balance = self.account.deposit(case["ammount"])
self.assertEqual(new_balance, case["expected"])

0 comments on commit 336a33c

Please sign in to comment.