diff --git a/bad_code.py b/bad_code.py new file mode 100644 index 0000000..28c5854 --- /dev/null +++ b/bad_code.py @@ -0,0 +1,10 @@ +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/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_bad_code.py b/tests/test_bad_code.py new file mode 100644 index 0000000..4e8f5a6 --- /dev/null +++ b/tests/test_bad_code.py @@ -0,0 +1,5 @@ +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 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)