Exemplo n.º 1
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 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)
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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)
Exemplo n.º 12
0
 def test_binary_search_empty(self):
     '''Test for binary search'''
     L = []
     self.assertEqual(pg.binary_search('z', L), -1)
Exemplo n.º 13
0
 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) 
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
    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)
Exemplo n.º 18
0
 def test_binary_search_without_val(self):
     res = plot_gtex.binary_search(0, self.binary_data)
     self.assertEqual(res, -1)
Exemplo n.º 19
0
 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)
Exemplo n.º 20
0
 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)
Exemplo n.º 22
0
 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)
Exemplo n.º 24
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)
Exemplo n.º 25
0
 def test_binary_search_empty_list(self):
     self.assertEqual(pg.binary_search(1, []), -1)
Exemplo n.º 26
0
 def test_binary_empty(self):
     self.key = 5
     self.data_list = []
     self.assertEqual(binary_search(self.key, self.data_list), -1)
Exemplo n.º 27
0
    def test_binary_search_empty_list(self):
        key = 'cheddar'
        L = []

        r = plot_gtex.binary_search(key, L)
        self.assertEqual(r, -1)