Skip to content

Commit

Permalink
Merge pull request #6 from bmm21002/feature-unittests
Browse files Browse the repository at this point in the history
Adding tests
  • Loading branch information
bmm21002 committed Feb 21, 2025
2 parents 5eba22a + 3e88e0c commit 8c15f01
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/calc_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from main import add, sub, mult, div # Import functions from main.py

# Test cases for addition
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
assert add(1.5, 2.5) == 4.0
assert add(-3, -7) == -10

# Test cases for subtraction
def test_sub():
assert sub(5, 3) == 2
assert sub(10, 10) == 0
assert sub(0, 5) == -5
assert sub(3.5, 1.2) == 2.3

# Test cases for multiplication
def test_mult():
assert mult(3, 4) == 12
assert mult(0, 100) == 0
assert mult(-2, 5) == -10
assert mult(1.5, 2) == 3.0

# Test cases for division
def test_div():
assert div(10, 2) == 5
assert div(5, 1) == 5
assert div(9, 3) == 3
assert div(7.5, 2.5) == 3.0

with pytest.raises(ZeroDivisionError):
div(5, 0)

0 comments on commit 8c15f01

Please sign in to comment.