def test_binary_search_even_left():
    arr = [4, 8, 15, 16, 23, 42]
    key = 15

    actual = binary_search(arr, key)
    expected = arr.index(key)
    assert actual == expected
def test_binary_search_out_of_bounds():
    arr = [4, 8, 15, 16, 23, 42, 50]
    key = 75

    actual = binary_search(arr, key)
    expected = -1
    assert actual == expected
def test_binary_search_odd_right():
    arr = [4, 8, 15, 16, 23, 42, 50]
    key = 42

    actual = binary_search(arr, key)
    expected = arr.index(key)
    assert actual == expected
Example #4
0
def test_binary_search_out():
    actual = binary_search([11, 22, 33, 44, 55, 66, 77], 90)
    expected = -1
    assert actual == expected
Example #5
0
def test_binary_search_in():
    actual = binary_search([4, 8, 15, 16, 23, 42, 64], 42)
    expected = 5
    assert actual == expected
Example #6
0
def test_binary_search():
    actual = binary_search([4, 8, 15, 16, 23, 42], 42)
    expected = 2
    assert actual == expected
def test_number_contained_inside_list():
    actual = binary_search([4,8,15,16,23,42], 15)
    expected = 2
    assert actual == expected
def test_number_not_contained_inside_list():
    actual = binary_search([11,22,33,44,55,66,77], 88)
    expected = -1
    assert actual == expected