From de3a611b70b8439bbfb8ada6944b87475dd5f08e Mon Sep 17 00:00:00 2001 From: "Hiroshi (Wes) Nishio" Date: Fri, 20 Mar 2026 07:56:58 -0700 Subject: [PATCH 1/4] Initial empty commit to create PR [skip ci] From dc15f54a3bd71398f4cdf2e236790af9406ef99d Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 20 Mar 2026 14:58:16 +0000 Subject: [PATCH 2/4] Create test_calculator.py [skip ci] Co-Authored-By: Hiroshi (Wes) Nishio --- test_calculator.py | 109 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 test_calculator.py diff --git a/test_calculator.py b/test_calculator.py new file mode 100644 index 0000000..5b996a7 --- /dev/null +++ b/test_calculator.py @@ -0,0 +1,109 @@ +from unittest.mock import patch + +from calculator import add, divide, main, multiply, subtract + +import pytest + + +class TestAdd: + def test_positive_numbers(self): + assert add(2, 3) == 5 + + def test_negative_numbers(self): + assert add(-1, -2) == -3 + + def test_mixed_signs(self): + assert add(-1, 3) == 2 + + def test_zeros(self): + assert add(0, 0) == 0 + + def test_floats(self): + assert add(1.5, 2.5) == 4.0 + + +class TestSubtract: + def test_positive_numbers(self): + assert subtract(5, 3) == 2 + + def test_negative_result(self): + assert subtract(3, 5) == -2 + + def test_zeros(self): + assert subtract(0, 0) == 0 + + def test_floats(self): + assert subtract(5.5, 2.5) == 3.0 + + +class TestMultiply: + def test_positive_numbers(self): + assert multiply(3, 4) == 12 + + def test_by_zero(self): + assert multiply(5, 0) == 0 + + def test_negative_numbers(self): + assert multiply(-2, -3) == 6 + + def test_mixed_signs(self): + assert multiply(-2, 3) == -6 + + def test_floats(self): + assert multiply(2.5, 4) == 10.0 + + +class TestDivide: + def test_even_division(self): + assert divide(10, 2) == 5.0 + + def test_fractional_result(self): + assert divide(7, 2) == 3.5 + + def test_divide_by_zero(self): + with pytest.raises(ValueError, match="Cannot divide by zero"): + divide(10, 0) + + def test_negative_divisor(self): + assert divide(10, -2) == -5.0 + + def test_zero_numerator(self): + assert divide(0, 5) == 0.0 + + +class TestMain: + @patch("builtins.print") + @patch("builtins.input", side_effect=["5", "+", "3"]) + def test_addition_operation(self, _mock_input, mock_print): + main() + mock_print.assert_any_call("5.0 + 3.0 = 8.0") + + @patch("builtins.print") + @patch("builtins.input", side_effect=["10", "-", "4"]) + def test_subtraction_operation(self, _mock_input, mock_print): + main() + mock_print.assert_any_call("10.0 - 4.0 = 6.0") + + @patch("builtins.print") + @patch("builtins.input", side_effect=["3", "*", "7"]) + def test_multiplication_operation(self, _mock_input, mock_print): + main() + mock_print.assert_any_call("3.0 * 7.0 = 21.0") + + @patch("builtins.print") + @patch("builtins.input", side_effect=["20", "/", "4"]) + def test_division_operation(self, _mock_input, mock_print): + main() + mock_print.assert_any_call("20.0 / 4.0 = 5.0") + + @patch("builtins.print") + @patch("builtins.input", side_effect=["5", "%", "3"]) + def test_unknown_operation(self, _mock_input, mock_print): + main() + mock_print.assert_any_call("Unknown operation: %") + + @patch("builtins.print") + @patch("builtins.input", side_effect=["10", "/", "0"]) + def test_divide_by_zero_in_main(self, _mock_input, _mock_print): + with pytest.raises(ValueError, match="Cannot divide by zero"): + main() From f390f1a4092a98b5b622e656b4a899fc2f3e8e4f Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 20 Mar 2026 15:00:12 +0000 Subject: [PATCH 3/4] Disable unnecessary lint rules for test_calculator.py [skip ci] Co-Authored-By: Hiroshi (Wes) Nishio --- test_calculator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_calculator.py b/test_calculator.py index 5b996a7..05602bc 100644 --- a/test_calculator.py +++ b/test_calculator.py @@ -1,3 +1,4 @@ +# pylint: disable=redefined-outer-name, unused-argument from unittest.mock import patch from calculator import add, divide, main, multiply, subtract From d396716ccad3fac194f054eb9fa36198d2e2d913 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 20 Mar 2026 15:00:13 +0000 Subject: [PATCH 4/4] Empty commit to trigger final tests