-
Notifications
You must be signed in to change notification settings - Fork 79
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
base: main
Are you sure you want to change the base?
Calculator test #175
Changes from all commits
b378a9d
06e943e
3361fdc
6645da4
d015cee
281105a
a6a0f3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il controllo se il secondo termine è 0 devi farlo dentro la funzione |
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 | ||
|
There was a problem hiding this comment.
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 :)