Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculator test #175

Open
wants to merge 7 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def sum(a: int, b: int) -> int:
return a + b

def diff(a: int, b: int)-> int:
return a-b

def mul(a: int, b: int)-> int:
return a*b

def div(a: int, b:int)-> int:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mi sembra tutto ok, una piccola nota è che potresti aggiungere in questa funzione un controllo per assicurarti che b non sia zero e in quel caso ritornare magari None :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il return type è errato.

return a/b

if __name__=="__main__":
a= int(input ("Enter the first number: "))
b= int(input ("Enter the second number: "))

s= sum(a,b)
df= diff(a,b)
m= mul(a,b)

print (f"The sum is {s} ")
print (f"The difference is {df} ")
print (f"The multiplication is {m} ")

if b==0: print("The division is not possible")
else:
dv= div(a,b)
print(f"The division is {dv} ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il controllo se il secondo termine è 0 devi farlo dentro la funzione div, così facendo puoi scrivere un test che verifichi pure quello scenario.

19 changes: 19 additions & 0 deletions calculator_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from calculator import sum,diff,mul,div

def test_sum()-> None:
assert sum(2,5)== 7
assert sum(2,1.5)==3.5

def test_diff()->None:
assert diff(8,2)==6
assert diff(2,4)==-2

def test_mul()->None:
assert mul(2,0)==0
assert mul(3,4)==12

def test_div()->None:
assert div(5,10)==0.5
assert div(10,5)==2
assert div(3,1)==3

Loading