Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tutorial/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ def test_calculate_area(length, width, unit, function_to_test):
assert expected == result, "Incorrect area calculation or formatting"


@pytest.mark.parametrize(
"length,width,unit",
[
(2.0, 3.0, "km"), # Invalid unit
(2.0, 3.0, ""), # Empty unit
(2.0, 3.0, "CM"), # Case sensitive check
(2.0, 3.0, "inches"), # Another invalid unit
],
)
def test_calculate_area_invalid_units(length, width, unit, function_to_test):
"""Test that the function properly handles invalid units."""
validate_area_signature(function_to_test)
result = function_to_test(length, width, unit)
expected = f"Invalid unit: {unit}"
assert isinstance(
result, str
), "Result should be a string like 'Invalid unit: <unit>'"
assert (
result == expected
), f"Expected '{expected}' for invalid unit '{unit}', got '{result}'"


#
# Exercise 3: summing anything
#
Expand Down