Skip to content

Added more unit tests (and fixed division by zero edge case in calculator.py) #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion calculator.py
Expand Up @@ -15,7 +15,9 @@ def multiply(num1, num2):

# Function to divide two numbers
def divide(num1, num2):
return num1 / num2
if num2 != 0:
return num1 / num2
else: raise ZeroDivisionError

def run_calc():
print("Please select operation -\n" \
Expand Down
15 changes: 14 additions & 1 deletion test.py
Expand Up @@ -2,8 +2,21 @@

# import pytest

from calculator import add
from calculator import *

def test_add():
assert add(2, 2) == 4

def test_subtract():
assert subtract(5,3) == 2

def test_multiply():
assert multiply(3,4) == 12

def test_divide():
assert divide(6,2) == 3
try:
divide(6,0)
assert False
except ZeroDivisionError:
assert True