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

added verify and relative test #174

Open
wants to merge 8 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
10 changes: 10 additions & 0 deletions src/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
array = [2,4,6,8,10,12,14,16,18,20]
GiuseppeBnn marked this conversation as resolved.
Show resolved Hide resolved
def is_element_in_list(number : int) -> bool:
if number in array:
print("Numero presente")
return True
print("Numero non presente")
return False
if __name__ == "__main__":
n = int(input("Inserisci numero: "))
is_element_in_list(n)
16 changes: 16 additions & 0 deletions tests/test_verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

##Write a software that verifies if a number is present in a pre-defined array.
##Output example:
##Insert number 3
##The number 3 is [not] present in the array.
##
success_test_array = [2,4,6,8,10,12,14,16,18,20]
fail_test_array = range(35,100)
import src.verify as verify

def test_verify():

Choose a reason for hiding this comment

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

Rinomina la funzione, leggendo la firma del metodo non è chiaro cosa stai testando.

for i in success_test_array:
assert verify.is_element_in_list(i) == True

Choose a reason for hiding this comment

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

== True è superfluo.
Puoi usare

assert verify.is_element_in_list(i)
assert not verify.is_element_in_list(i)

for i in fail_test_array:
if i not in success_test_array:
assert verify.is_element_in_list(i) == False

Choose a reason for hiding this comment

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

Cosa te ne pare di definire due funzioni separate? Una che testa solo i casi positivi e una solo i casi negativi.
Poi nel tuo metodo principale chiami entrambi.

Loading