From 23801fe1a1ed9240471269a49214413fdbafbe2e Mon Sep 17 00:00:00 2001 From: Srushti Date: Wed, 6 May 2026 11:28:56 -0400 Subject: [PATCH 1/3] Add calculator functions with tests --- calculator.py | 15 +++++++++++++++ tests/test_calculator.py | 15 +++++++++++++++ 2 files changed, 30 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..7e6c3b1 --- /dev/null +++ b/calculator.py @@ -0,0 +1,15 @@ +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 39cb9895b99e94256987a8a5cba477d8b0f35119 Mon Sep 17 00:00:00 2001 From: Srushti Date: Wed, 6 May 2026 11:34:04 -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..d875910 --- /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 78e4163d94ffb7af3a74aac43daff041319604af Mon Sep 17 00:00:00 2001 From: Srushti Date: Wed, 6 May 2026 11:47:59 -0400 Subject: [PATCH 3/3] Fix code formatting and test assertion --- bad_code.py | 14 ++++++++------ tests/test_bad_code.py | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bad_code.py b/bad_code.py index d875910..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 - return result + +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!