From e6a8267134f839a8c5577f5f5baf59cc3b450d0a Mon Sep 17 00:00:00 2001 From: AlexKanj Date: Wed, 6 May 2026 12:57:33 -0400 Subject: [PATCH 1/4] 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..cce09d4 --- /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 \ No newline at end of file diff --git a/tests/test_calculator.py b/tests/test_calculator.py new file mode 100644 index 0000000..1b2dad8 --- /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) \ No newline at end of file From 5f0621b206d8687ada36b8112f749d5aeca4f742 Mon Sep 17 00:00:00 2001 From: AlexKanj Date: Wed, 6 May 2026 13:01:32 -0400 Subject: [PATCH 2/4] 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..d4a863e --- /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 \ No newline at end of file diff --git a/tests/test_bad_code.py b/tests/test_bad_code.py new file mode 100644 index 0000000..2183b14 --- /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 \ No newline at end of file From be4236ea2dfdd76673cb84e5ec5eafed2c559aa2 Mon Sep 17 00:00:00 2001 From: AlexKanj Date: Wed, 6 May 2026 13:14:53 -0400 Subject: [PATCH 3/4] 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 d4a863e..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 \ No newline at end of file + +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 2183b14..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 \ No newline at end of file + # Fixed test - should pass now + assert poorly_formatted(5, 3) == 5 # Correct! From 0f664c0aa5b7a232a289cded751417517e062a10 Mon Sep 17 00:00:00 2001 From: AlexKanj Date: Wed, 6 May 2026 13:18:25 -0400 Subject: [PATCH 4/4] fixed formatting --- calculator.py | 4 +++- tests/test_bad_code.py | 1 + tests/test_calculator.py | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/calculator.py b/calculator.py index cce09d4..d0b34fd 100644 --- a/calculator.py +++ b/calculator.py @@ -2,12 +2,14 @@ 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 \ No newline at end of file + return a / b diff --git a/tests/test_bad_code.py b/tests/test_bad_code.py index 4e8f5a6..3c58eed 100644 --- a/tests/test_bad_code.py +++ b/tests/test_bad_code.py @@ -1,5 +1,6 @@ from bad_code import poorly_formatted + def test_poorly_formatted(): # Fixed test - should pass now assert poorly_formatted(5, 3) == 5 # Correct! diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 1b2dad8..c61f070 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -1,15 +1,18 @@ 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) \ No newline at end of file + divide(10, 0)