Skip to content

Commit 63f84d4

Browse files
committed
added main ideom to binarySearch and added two tests
for main idiom see: https://docs.python.org/3/library/__main__.html#idiomatic-usage
1 parent 4410bd5 commit 63f84d4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

binarySearch.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ def userInput():
2828
else:
2929
print("The element was found at index ", result)
3030

31-
userInput()
31+
# Tests ('pip install pytest'; run with 'pytest binarySearch.py')
32+
def test_find_element_in_list():
33+
arr = [11, 12, 22, 25, 34, 64, 90, 91]
34+
result = binarySearch(arr, 25)
35+
assert result == 3
36+
37+
def test_elem_missing():
38+
arr = [11, 12, 22, 25, 34, 64, 90, 91]
39+
result = binarySearch(arr, 16)
40+
assert result == -1
41+
42+
if __name__ == "__main__":
43+
userInput()

0 commit comments

Comments
 (0)