-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_binary_search.py
49 lines (25 loc) · 1.15 KB
/
test_binary_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from .binary_search import binary_search
def test_binary_search_empty_array():
assert binary_search([], 0) == -1
def test_binary_search_find_single_array():
assert binary_search([3], 3) == 0
def test_binary_search_not_found_single_array():
assert binary_search([1], 0) == -1
def test_binary_search_not_found_in_short_array():
assert binary_search([1, 2, 3], 0) == -1
def test_binary_search_found_at_begining():
assert binary_search([0, 1, 2, 3, 4, 5], 0) == 0
def test_binary_search_found_at_end():
assert binary_search([0, 1, 3, 4, 5], 5) == 4
def test_binary_search_found_at_middle_even():
assert binary_search([0, 1, 3, 5], 3) == 2
def test_binary_search_found_at_middle_odd():
assert binary_search([1, 3, 5], 3) == 1
def test_binary_search_high_value():
assert binary_search([1, 3, 5], 3) == 1
def test_binary_search_large_array_low():
assert binary_search(list(range(0xFFFFFF)), 0xFF) == 0xFF
def test_binary_search_large_array_high():
assert binary_search(list(range(0xFFFFFF)), 0xFFFFF) == 0xFFFFF
def test_binary_search_large_array_not_found():
assert binary_search(list(range(0xFFFFFF)), -4) == -1