-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinarySearch_test.py
76 lines (40 loc) · 1.17 KB
/
binarySearch_test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from binsearch import binary_search
import numpy as np
from pytest import raises
input = list(range(10))
def test1():
assert binary_search(input, 5) == 5
def test2():
assert binary_search(input, 4.5) == -1
def test3():
assert binary_search([5], 5) == 0
def test4():
assert binary_search([5], 4) == -1
def test5():
binary_search([], 4) == -1
def test6():
binary_search(input, 11) == -1
def test_alist():
with raises(TypeError):
binary_search('a', 1)
def test_missing_args():
with raises(TypeError):
binary_search([1, 2])
def test_not_numeric():
assert binary_search(['a', 'b'], 'b') == 1
def test_other():
assert binary_search(['hello', 'there', 'you', 'abc'], 'abc') == -1
def test_nan():
assert binary_search([np.nan, 0, 2, 3, 4], np.nan) == 2
def test_n1():
assert binary_search(input, 5, 2, 2) == -1
def test_n2():
assert binary_search(input, 2, 2, 2) == 2
def test_n3():
assert binary_search(input, 2, 1,3) == 2
def test_n4():
assert binary_search(input, 2, 3, 1) == -1
def test_n5():
assert binary_search(input, 9) == 9
def test_both():
assert binary_search([5], 7) == -1