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 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)))
class Deque:

	def __init__(self):
		self.dq = UnorderedList()

	def add_rear(self,item):
		self.dq.add(item)

	def add_front(self,item):
		self.dq.append(item)

	def remove_rear(self):
		return self.dq.pop(0)

	def remove_front(self):
		return self.dq.pop()

	def size(self):
		return self.dq.size()

	def is_empty(self):
		return self.dq.is_empty()

	def show(self):
		print(self.dq)
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)
class Queue:

	def __init__(self):
		self.q = UnorderedList()

	def enque(self,items):
		self.q.add(items)

	def deque(self):
		return self.q.pop()

	def size(self):
		return self.q.size()

	def is_empty(self):
		return self.q.is_empty()

	def show(self):
		print(self.q)
Example #7
0
class Stack:
    def __init__(self):
        self.s = UnorderedList()

    def push(self, items):
        self.s.add(items)

    def pop_stack(self):
        return self.s.pop(0)

    def peek_stack(self):
        return self.s.head.get_data()

    def is_empty(self):
        return self.s.is_empty()

    def size(self):
        return self.s.size()

    def show(self):
        print(self.s)
Example #8
0
class Deque:
    def __init__(self):
        self.dq = UnorderedList()

    def add_rear(self, item):
        self.dq.add(item)

    def add_front(self, item):
        self.dq.append(item)

    def remove_rear(self):
        return self.dq.pop(0)

    def remove_front(self):
        return self.dq.pop()

    def size(self):
        return self.dq.size()

    def is_empty(self):
        return self.dq.is_empty()

    def show(self):
        print(self.dq)
Example #9
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 #10
0
 def test_size(self):
     L = UnorderedList()
     for i in range(10):
         L.add(i)
     self.assertEqual(L.size(), 10)
Example #11
0
 def test_is_empty(self):
     L = UnorderedList()
     self.assertTrue(L.is_empty())
     L.add(32)
     self.assertFalse(L.is_empty())