Skip to content

Commit 340beaa

Browse files
committed
Raise an exception if coin_flip_count is invalid
Check both type and value, allowing only int values greater than zero
1 parent fb33c15 commit 340beaa

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/flip_coins.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def flip_coins(coin_flip_count: int, chosen_side: str) -> dict:
8989
}
9090
"""
9191
# Validate input parameters
92-
assert coin_flip_count > 0
92+
if not isinstance(coin_flip_count, int):
93+
raise TypeError('The number of coins must be an integer')
94+
if coin_flip_count < 1:
95+
raise ValueError('The number of coins must be an positive, non-zero integer')
9396

9497
# Perform the coin flips
9598
flip_dataframes = [] # List of dataframes from single flips

src/tests/test_flip_coins_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_multiple_coin_flips(coin_flip_count: int) -> None:
3030

3131
def test_multiple_coin_flip_zero_times() -> None:
3232
"""Test the exception handling of flip_coins when asked to flip 0 coins"""
33-
with pytest.raises(AssertionError):
33+
with pytest.raises(ValueError):
3434
src.flip_coins.flip_coins(
3535
coin_flip_count=0,
3636
chosen_side="tails"

0 commit comments

Comments
 (0)