-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from bmm21002/feature-unittests
Adding tests
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |