From 9acf045a12673b1d0074fe282ddaca1695877882 Mon Sep 17 00:00:00 2001 From: rvasikarla Date: Sat, 18 Oct 2025 13:59:40 -0500 Subject: [PATCH 1/3] Add comprehensive test coverage for maths.abs module - Added test_abs.py with pytest-compatible tests- Tests cover abs_val, abs_min, abs_max, and abs_max_sort functions- Includes edge cases, error conditions, and consistency checks - Follows existing test patterns in the repository- Improves test coverage for issue #9943 --- maths/test_abs.py | 143 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 maths/test_abs.py diff --git a/maths/test_abs.py b/maths/test_abs.py new file mode 100644 index 000000000000..84f24a883baf --- /dev/null +++ b/maths/test_abs.py @@ -0,0 +1,143 @@ +# /// script +# requires-python = ">=3.13" +# dependencies = [ +# "pytest", +# ] +# /// + +import pytest + +from maths.abs import abs_val, abs_min, abs_max, abs_max_sort + + +class TestAbsVal: + """Test cases for abs_val function.""" + + def test_positive_numbers(self): + """Test abs_val with positive numbers.""" + assert abs_val(5) == 5 + assert abs_val(10.5) == 10.5 + assert abs_val(0.1) == 0.1 + + def test_negative_numbers(self): + """Test abs_val with negative numbers.""" + assert abs_val(-5) == 5 + assert abs_val(-10.5) == 10.5 + assert abs_val(-0.1) == 0.1 + + def test_zero(self): + """Test abs_val with zero.""" + assert abs_val(0) == 0 + assert abs_val(0.0) == 0.0 + + def test_large_numbers(self): + """Test abs_val with large numbers.""" + assert abs_val(-100000000000) == 100000000000 + assert abs_val(100000000000) == 100000000000 + + +class TestAbsMin: + """Test cases for abs_min function.""" + + def test_positive_numbers(self): + """Test abs_min with positive numbers.""" + assert abs_min([1, 2, 3, 4, 5]) == 1 + assert abs_min([5, 1, 3, 4, 2]) == 1 + + def test_negative_numbers(self): + """Test abs_min with negative numbers.""" + assert abs_min([-5, -1, -3, -4, -2]) == -1 + assert abs_min([-10, -2, -8]) == -2 + + def test_mixed_numbers(self): + """Test abs_min with mixed positive and negative numbers.""" + assert abs_min([3, -10, -2]) == -2 + assert abs_min([0, 5, 1, 11]) == 0 + assert abs_min([-3, -1, 2, -11]) == -1 + + def test_single_element(self): + """Test abs_min with single element list.""" + assert abs_min([5]) == 5 + assert abs_min([-5]) == -5 + + def test_empty_list(self): + """Test abs_min with empty list.""" + with pytest.raises(ValueError, match="abs_min\\(\\) arg is an empty sequence"): + abs_min([]) + + +class TestAbsMax: + """Test cases for abs_max function.""" + + def test_positive_numbers(self): + """Test abs_max with positive numbers.""" + assert abs_max([1, 2, 3, 4, 5]) == 5 + assert abs_max([0, 5, 1, 11]) == 11 + + def test_negative_numbers(self): + """Test abs_max with negative numbers.""" + assert abs_max([-5, -1, -3, -4, -2]) == -5 + assert abs_max([-10, -2, -8]) == -10 + + def test_mixed_numbers(self): + """Test abs_max with mixed positive and negative numbers.""" + assert abs_max([3, -10, -2]) == -10 + assert abs_max([-3, -1, 2, -11]) == -11 + + def test_single_element(self): + """Test abs_max with single element list.""" + assert abs_max([5]) == 5 + assert abs_max([-5]) == -5 + + def test_empty_list(self): + """Test abs_max with empty list.""" + with pytest.raises(ValueError, match="abs_max\\(\\) arg is an empty sequence"): + abs_max([]) + + +class TestAbsMaxSort: + """Test cases for abs_max_sort function.""" + + def test_positive_numbers(self): + """Test abs_max_sort with positive numbers.""" + assert abs_max_sort([1, 2, 3, 4, 5]) == 5 + assert abs_max_sort([0, 5, 1, 11]) == 11 + + def test_negative_numbers(self): + """Test abs_max_sort with negative numbers.""" + assert abs_max_sort([-5, -1, -3, -4, -2]) == -5 + assert abs_max_sort([-10, -2, -8]) == -10 + + def test_mixed_numbers(self): + """Test abs_max_sort with mixed positive and negative numbers.""" + assert abs_max_sort([3, -10, -2]) == -10 + assert abs_max_sort([-3, -1, 2, -11]) == -11 + + def test_single_element(self): + """Test abs_max_sort with single element list.""" + assert abs_max_sort([5]) == 5 + assert abs_max_sort([-5]) == -5 + + def test_empty_list(self): + """Test abs_max_sort with empty list.""" + with pytest.raises(ValueError, match="abs_max_sort\\(\\) arg is an empty sequence"): + abs_max_sort([]) + + def test_consistency_with_abs_max(self): + """Test that abs_max_sort gives same results as abs_max.""" + test_cases = [ + [1, 2, 3, 4, 5], + [-5, -1, -3, -4, -2], + [3, -10, -2], + [0, 5, 1, 11], + [-3, -1, 2, -11], + [42], + [-42] + ] + + for test_case in test_cases: + assert abs_max_sort(test_case) == abs_max(test_case) + + +if __name__ == "__main__": + pytest.main(["-v", __file__]) From 9bfcd1ee0ea7887005f2afafd9210b08a6a50acd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Oct 2025 19:03:30 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/test_abs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/maths/test_abs.py b/maths/test_abs.py index 84f24a883baf..169314c45289 100644 --- a/maths/test_abs.py +++ b/maths/test_abs.py @@ -120,7 +120,9 @@ def test_single_element(self): def test_empty_list(self): """Test abs_max_sort with empty list.""" - with pytest.raises(ValueError, match="abs_max_sort\\(\\) arg is an empty sequence"): + with pytest.raises( + ValueError, match="abs_max_sort\\(\\) arg is an empty sequence" + ): abs_max_sort([]) def test_consistency_with_abs_max(self): @@ -132,7 +134,7 @@ def test_consistency_with_abs_max(self): [0, 5, 1, 11], [-3, -1, 2, -11], [42], - [-42] + [-42], ] for test_case in test_cases: From 700855842e288dced7b656a9db674abfe4901907 Mon Sep 17 00:00:00 2001 From: rvasikarla Date: Sat, 18 Oct 2025 14:11:37 -0500 Subject: [PATCH 3/3] Fix import formatting for ruff linter compliance --- maths/test_abs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/test_abs.py b/maths/test_abs.py index 169314c45289..cf07bce3819c 100644 --- a/maths/test_abs.py +++ b/maths/test_abs.py @@ -7,7 +7,7 @@ import pytest -from maths.abs import abs_val, abs_min, abs_max, abs_max_sort +from maths.abs import abs_max, abs_max_sort, abs_min, abs_val class TestAbsVal: