Example #1
0
 def test_search(self):
     L = UnorderedList()
     data = [randint(0, 100) for i in range(10)]
     for d in data:
         L.add(d)
     self.assertTrue(all([L.search(i) for i in data]))
     self.assertFalse(all([L.search(i) for i in range(100, 110)]))
Example #2
0
 def __init__(self, capacity=8):
     self._capacity = capacity
     self._table = []
     for index in range(self._capacity):
         self._table.append(UnorderedList())
     self._size = 0
     self._index = None
Example #3
0
 def test_add(self):
     data = [randint(0, 100) for i in range(10)]
     L = UnorderedList()
     for d in data:
         L.add(d)
     self.assertFalse(L.is_empty())
     self.assertEqual(sorted(data), sorted(self.get_data(L)))
Example #4
0
 def test_remove(self):
     L = UnorderedList()
     data = [1, 2, 3, 4, 5]
     for d in data:
         L.add(d)
     L.remove(3)
     self.assertNotIn(3, self.get_data(L))
     L.remove(5)
     self.assertNotIn(5, self.get_data(L))
	def put(self,key,value):
		hash_value = self.hash_function(key,len(self.slot))
		if self.slot[hash_value] == None: # if slot is empty and no list is created yet!
			l = UnorderedList() # Create a list then add the key:value pair
			self.slot[hash_value] = l
			l.add(key,value)
		else:
			l = self.slot[hash_value] # if list is already present for hash value 
			if l.search(key):
				i = l.index(key)
				l.getNode(i).set_value(value) #replace
			else:
				l.add(key,value)
Example #6
0
 def __init__(self):
     self.s = UnorderedList()
Example #7
0
 def test_remove_with_one_element(self):
     L = UnorderedList()
     L.add(3)
     L.remove(3)
     self.assertNotIn(3, self.get_data(L))
     self.assertEqual(L.size(), 0)
Example #8
0
 def test_size(self):
     L = UnorderedList()
     for i in range(10):
         L.add(i)
     self.assertEqual(L.size(), 10)
Example #9
0
 def test_is_empty(self):
     L = UnorderedList()
     self.assertTrue(L.is_empty())
     L.add(32)
     self.assertFalse(L.is_empty())