def test_binary_search(self): array = [1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 6] self.assertEqual(10, binary_search(array, 5)) self.assertEqual(11, binary_search(array, 6)) self.assertEqual(None, binary_search(array, 7)) self.assertEqual(None, binary_search(array, -1)) # Test binary_search_recur self.assertEqual(10, binary_search_recur(array, 0, 11, 5)) self.assertEqual(11, binary_search_recur(array, 0, 11, 6)) self.assertEqual(-1, binary_search_recur(array, 0, 11, 7)) self.assertEqual(-1, binary_search_recur(array, 0, 11, -1))
from algorithms.search import binary_search, binary_search_recur import random alist = [random.randint(1, 5) for i in range(100)] print(alist) print(binary_search(alist, 4)) blist = [random.randint(1, 5) for i in range(100)] print(binary_search_recur(blist, 40, 80, 5))