From cee18996e8719843bb433b83d03bf9275f832650 Mon Sep 17 00:00:00 2001 From: Bappadala Rohith Kumar Naidu <198095685+rohitkumarnaidu@users.noreply.github.com> Date: Mon, 27 Jul 2026 21:06:19 +0530 Subject: [PATCH 1/2] feat: add proper pytest unit tests for utils --- requirements-dev.txt | 1 + tests/test_utils.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 requirements-dev.txt create mode 100644 tests/test_utils.py diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..c75731e --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1 @@ +pytest==8.2.2 diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..059ec67 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,29 @@ +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="invalid integer"): + parse_int_list("1, a, 3") From bae4d4df3a561d66dda66d5612b03c1e285630da Mon Sep 17 00:00:00 2001 From: Bappadala Rohith Kumar Naidu <198095685+rohitkumarnaidu@users.noreply.github.com> Date: Mon, 27 Jul 2026 22:35:02 +0530 Subject: [PATCH 2/2] fix: resolve new CodeRabbit review feedback for unit tests --- __pycache__/utils.cpython-314.pyc | Bin 2032 -> 2051 bytes requirements-dev.txt | 2 +- tests/test_utils.py | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/__pycache__/utils.cpython-314.pyc b/__pycache__/utils.cpython-314.pyc index eef8ec81b5dce662b1d67a0a579e70c4cb9b82e2..2e9186ae213d7170fdce5be0b19064f3e8c57916 100644 GIT binary patch delta 55 zcmeys-z>nR&Bx2d00d6r=~)|jDj8)oT&!aJ3sUnGg7Zs@l2c<`b4rWzlVgff3-Sv# J_c1210RWAf5QG2# delta 36 qcmZn`_`uJj&Bx2d00f8cJ;~h2Q_09F>S7fWlv=8.0.0 diff --git a/tests/test_utils.py b/tests/test_utils.py index 059ec67..13eb99f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -25,5 +25,7 @@ def test_parse_int_list(): 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")