Skip to content
Open
Show file tree
Hide file tree
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
Binary file modified __pycache__/utils.cpython-314.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest>=8.0.0
31 changes: 31 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
from utils import calculate_average, find_max, normalize, parse_int_list

def test_calculate_average():
assert calculate_average([1, 2, 3]) == 2.0
assert calculate_average([10, 20]) == 15.0
with pytest.raises(ValueError, match="Cannot calculate average of an empty list"):
calculate_average([])

def test_find_max():
assert find_max([1, 5, 3]) == 5
assert find_max([-10, -5, -20]) == -5
with pytest.raises(ValueError, match="Cannot find max of an empty list"):
find_max([])

def test_normalize():
assert normalize([0, 5, 10]) == [0.0, 0.5, 1.0]
with pytest.raises(ValueError, match="Cannot normalize an empty list"):
normalize([])
with pytest.raises(ValueError, match="Cannot normalize a constant list"):
normalize([5, 5, 5])

def test_parse_int_list():
assert parse_int_list("1, 2, 3") == [1, 2, 3]
assert parse_int_list("10") == [10]
with pytest.raises(ValueError, match="Input string is empty"):
parse_int_list("")
with pytest.raises(ValueError, match="Input string is empty"):
parse_int_list(" ")
with pytest.raises(ValueError, match="invalid integer"):
parse_int_list("1, a, 3")