def test_binary_search(self): L = [[1, 0], [2, 1], [3, 2], [4, 3], [5, 4], [6, 5]] r = plot_gtex.binary_search(3, L) self.assertEqual(r, 2) r = plot_gtex.binary_search(10, L) self.assertEqual(r, -1)
def test_binary_search(self): """ This function tests the functionality of the binary search method """ L = [[1, 0], [2, 0], [3, 0], [4, 0], [5, 0]] for i in range(1, 6): r = plot_gtex.binary_search(i, L) self.assertEqual(r, 0) r = plot_gtex.binary_search(100, L) self.assertEqual(r, -1)
def test_binary_search(self): array = [['cat', 1], ['dog', 2]] found = plot_gtex.binary_search('cat', array) self.assertEqual(1, found) r = plot_gtex.linear_search('pigeon', array) self.assertEqual(r, -1)
def test_binary_search_random_list(self): for x in range(100): L = [] i = 0 for y in range(50): num = random.randint(5 * y, 5 * y + 4) L.append([num, i]) i += 1 location = random.randint(0, 49) key = L[location][0] self.assertEqual(pg.binary_search(key, L), location)
def test_binary_search(self): """test if binary search works""" for j in range(10): # including rand interation D = [] for i in range(10): D.append(['Thing %s' % i, i]) index = random.randint(0, len(D)-1) name = 'Thing ' + str(index) r = plot_gtex.binary_search(name, D) self.assertEqual(r, index)
def test_binary_search_when_not_in_list(self): """test if binary search returns -1 when entry not in lst""" for j in range(10): # including rand interation D = [] for i in range(10): D.append(['Thing %s' % i, i]) index = len(D) name = 'Thing ' + str(index) r = plot_gtex.binary_search(name, D) self.assertEqual(r, -1)
def test_binary_search_rand_not_in_list(self): for k in range(100): rand_int = random.randint(1, 1000) key = rand_int L = [] for i in range(100): rand_int_for_list = random.randint(1, 1000) if rand_int_for_list != rand_int: L.append(rand_int_for_list) else: continue L = list(dict.fromkeys(L)) L.sort() idx = 0 for j in L: if j == key or j > key: break else: idx += 1 r = plot_gtex.binary_search(key, L) self.assertEqual(r, -1)
def test_no_hit(self): self.assertEqual(pgtx.binary_search('aa', [1, 2, 3]), -1)
def test_binary_search_constant(self): L = [(1, 1), (2, 2), (3, 3)] r = plot_gtex.binary_search(3, L) self.assertEqual(r, 3) # the index where 3 occurs in L
def test_binary_search_key_mid(self): key = 'gouda' L = [['brie', 0], ['cheddar', 1], ['gouda', 2], ['provolone', 3]] r = plot_gtex.binary_search(key, L) self.assertEqual(r, 2)
def test_binary_not_found(self): L = [(1, 1), (2, 2), (3, 3)] r = plot_gtex.binary_search(10, L) self.assertEqual(r, -1)
def test_binary_search_empty(self): '''Test for binary search''' L = [] self.assertEqual(pg.binary_search('z', L), -1)
def test_binary_search_not_found(self): '''Test for binary search''' L = [['a', 1], ['b', 2], ['c', 3], ['d', 4]] self.assertEqual(pg.binary_search('z', L), -1)
def test_binary_search(self): L = [(1, 1), (2, 2), (3, 3)] r = plot_gtex.binary_search(3, L) self.assertEqual(r, 3)
def test_binary_missing(self): self.key = 100 self.data_list = list(zip(range(10), range(10))) self.assertEqual(binary_search(self.key, self.data_list), -1)
def test_binary_search_key_not_there(self): key = 'mozzarella' L = [['brie', 0], ['cheddar', 1], ['gouda', 2], ['provolone', 3]] r = plot_gtex.binary_search(key, L) self.assertEqual(r, -1)
def test_binary_search(self): # Successful search A = [['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5], ['f', 7]] BS = plot_gtex.binary_search('e', A) self.assertEqual(5, BS)
def test_binary_search_without_val(self): res = plot_gtex.binary_search(0, self.binary_data) self.assertEqual(res, -1)
def test_binary_search_easy_not_in_list(self): key = 'green' L = ['red', 'blue', 'orange', 'yellow'] L.sort() r = plot_gtex.binary_search(key, L) self.assertEqual(r, -1)
def test_binary_search_easy(self): key = 'blue' L = ['red', 'orange', 'blue', 'yellow'] L.sort() r = plot_gtex.binary_search(key, L) self.assertEqual(r, 0)
def test_binary_search_fail(self): # No hits in the list A = ['1', '2', '3', '4', '5', '6'] BS = plot_gtex.binary_search('7', A) self.assertEqual(-1, BS)
def test_binary_search_empty_list(self): res = plot_gtex.binary_search(0, []) self.assertEqual(res, -1)
def test_hit(self): self.assertEqual(pgtx.binary_search(1, [1, 2, 3]), 0)
def test_binary_exists(self): self.key = 5 self.data_list = list(zip(range(10), range(10))) self.assertEqual(binary_search(self.key, self.data_list), 5)
def test_binary_search_empty_list(self): self.assertEqual(pg.binary_search(1, []), -1)
def test_binary_empty(self): self.key = 5 self.data_list = [] self.assertEqual(binary_search(self.key, self.data_list), -1)
def test_binary_search_empty_list(self): key = 'cheddar' L = [] r = plot_gtex.binary_search(key, L) self.assertEqual(r, -1)