From b552ba848a2e340e85e36165f9c2b209cc3607a7 Mon Sep 17 00:00:00 2001 From: victorsand0val Date: Wed, 13 May 2026 16:09:55 -0400 Subject: [PATCH 1/3] Add calculator functions with tests --- calculator.py | 13 +++++++++++++ tests/test_calculator.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 calculator.py create mode 100644 tests/test_calculator.py diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000..2db6275 --- /dev/null +++ b/calculator.py @@ -0,0 +1,13 @@ +def add(a, b): + """Add two numbers together.""" + return a + b + +def multiply(a, b): + """Multiply two numbers.""" + return a * b + +def divide(a, b): + """Divide two numbers.""" + if b == 0: + raise ValueError("Cannot divide by zero") + return a / b diff --git a/tests/test_calculator.py b/tests/test_calculator.py new file mode 100644 index 0000000..5e39b62 --- /dev/null +++ b/tests/test_calculator.py @@ -0,0 +1,15 @@ +import pytest +from calculator import add, multiply, divide + +def test_add(): + assert add(2, 3) == 5 + assert add(-1, 1) == 0 + +def test_multiply(): + assert multiply(3, 4) == 12 + assert multiply(0, 5) == 0 + +def test_divide(): + assert divide(10, 2) == 5 + with pytest.raises(ValueError): + divide(10, 0) From ac3d6e4782c4c031a2133a660195ec4888b6f1b8 Mon Sep 17 00:00:00 2001 From: victorsand0val Date: Wed, 13 May 2026 16:18:08 -0400 Subject: [PATCH 2/3] Add poorly formatted code with failing tests --- bad_code.py | 8 ++++++++ tests/test_bad_code.py | 5 +++++ 2 files changed, 13 insertions(+) create mode 100644 bad_code.py create mode 100644 tests/test_bad_code.py diff --git a/bad_code.py b/bad_code.py new file mode 100644 index 0000000..07b9696 --- /dev/null +++ b/bad_code.py @@ -0,0 +1,8 @@ +def poorly_formatted(x,y): + if x>y:return x + else: + return y + +def another_function( a, b ): + result=a+b + return result diff --git a/tests/test_bad_code.py b/tests/test_bad_code.py new file mode 100644 index 0000000..4b8e723 --- /dev/null +++ b/tests/test_bad_code.py @@ -0,0 +1,5 @@ +from bad_code import poorly_formatted + +def test_poorly_formatted(): + # This test will fail intentionally + assert poorly_formatted(5, 3) == 3 # Wrong! Should be 5 From d8e3ce1cab5639e17d05fee3079bb87d4c5a3012 Mon Sep 17 00:00:00 2001 From: victorsand0val Date: Wed, 13 May 2026 16:23:55 -0400 Subject: [PATCH 3/3] Fix code formatting and test assertion --- bad_code.py | 12 +++++++----- tests/test_bad_code.py | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bad_code.py b/bad_code.py index 07b9696..28c5854 100644 --- a/bad_code.py +++ b/bad_code.py @@ -1,8 +1,10 @@ -def poorly_formatted(x,y): - if x>y:return x +def poorly_formatted(x, y): + if x > y: + return x else: - return y + return y -def another_function( a, b ): - result=a+b + +def another_function(a, b): + result = a + b return result diff --git a/tests/test_bad_code.py b/tests/test_bad_code.py index 4b8e723..4e8f5a6 100644 --- a/tests/test_bad_code.py +++ b/tests/test_bad_code.py @@ -1,5 +1,5 @@ from bad_code import poorly_formatted def test_poorly_formatted(): - # This test will fail intentionally - assert poorly_formatted(5, 3) == 3 # Wrong! Should be 5 + # Fixed test - should pass now + assert poorly_formatted(5, 3) == 5 # Correct!