From f558bdd76b72e4526f086224c153f481e61b25f5 Mon Sep 17 00:00:00 2001 From: Conner Klingensmith Date: Wed, 13 May 2026 16:13:19 -0400 Subject: [PATCH] Add calculator functions with tests --- .github/workflows/calculator.py | 13 +++++++++++++ tests/test_calculator.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 .github/workflows/calculator.py create mode 100644 tests/test_calculator.py diff --git a/.github/workflows/calculator.py b/.github/workflows/calculator.py new file mode 100644 index 0000000..cce09d4 --- /dev/null +++ b/.github/workflows/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