Пример #1
0
 def test_search(self):
     array = [3, 5, 2, 1, 7, 6]
     expected = 2
     result = linear_search.search(array, 2)
     self.assertEqual(expected, result)
     expected = -1
     result = linear_search.search(array, 0)
     self.assertEqual(expected, result)
 def add_item(self, x):
     #hint: use linear_search
     try:
         self.d[x//10]
     except:
         self.d[x//10] = [x]
     else:
         result = search(self.d[x//10],x)
         found = result[0]
         pos = result[1]
         self.d[x//10].insert(pos,x)
 def delete_item(self, x):
     #hint: use linear_search.#
     try:
         self.d[x//10]
     except:
         return False
     else:
         result = search(self.d[x//10],x)
         found = result[0]
         pos = result[1]
         if found == True:
             del self.d[x//10][pos]
             return True
         else:
             return False
Пример #4
0
	def test_linear_search_should_find_element(self):
		for d, idxs in self.data:
			self.assertIn(linear_search.search(d, self.search_for), idxs)
Пример #5
0
	def test_linear_search_should_not_find_invalid_data(self):
		for search_for in self.notdata:
			for d, idx in self.data:
				self.assertIsNone(linear_search.search(d, search_for))
 def test_search(self):
     self.assertTrue(linear_search.search([1, 3, 5], 5))
     self.assertFalse(linear_search.search([1, 3, 5], 7))
Пример #7
0
 def test_linear_search_should_not_find_invalid_data(self):
     for search_for in self.notdata:
         for d, idx in self.data:
             self.assertIsNone(linear_search.search(d, search_for))
Пример #8
0
 def test_linear_search_should_find_element(self):
     for d, idx in self.data:
         self.assertEqual(linear_search.search(d, self.search_for), idx)