def test_getLength(self): list = Double_Linked_List() list.insertBeginning(5) list.insertLocation(1, 7) self.assertEqual(2, list.getLength()) list.retrieve(1) self.assertEqual(1, list.getLength())
def test_insertEnd(self): list = Double_Linked_List() list.insertEnd(7) self.assertEqual(7, list.retrieve(0)[0]) list.insertEnd(9) self.assertEqual(7, list.retrieve(0)[0]) self.assertEqual(9, list.retrieve(1)[0])
def createHashMap(self, length, collisiontype): """ Create a new hashmap. :param length: The length of the table. :param collisiontype: The way to solve a collision. :return: True if the creation was succesfull, false otherwise. """ #Input validation if 0 > collisiontype > 2: print("Invalid collisiontype!!") return False if length <= 0: print("Invalid length!") return False #Creating map self.lijst = [] for i in range(length): self.lijst.append("") #If linked lists are used, fill every position with an empty link if collisiontype == 2: for i in range(length): new_link = Double_Linked_List() self.lijst[i] = new_link return True
def test_searchNode(self): list = Double_Linked_List() list.insertBeginning(5) list.insertEnd(8) list.insertEnd(9) self.assertEqual(9, list.searchNode(2).item) self.assertEqual(8, list.searchNode(1).item) self.assertEqual(8, list.retrieve(1)[0]) self.assertEqual(5, list.retrieve(0)[0])
def __init__(self, type): """ Creates empty lists for the products: honey, marshmallows, chili pepper and chocolate shots (white, brown and milk chocolate). PRE : Type is a circular linked list (CLL) or a double linked list (DLL). Type decides the kind of implemen- tation of the stocks. POST : The stock now contains six empty lists. """ if "dll" == type or type == "DLL": self.type = "dll" self.honeyList = Double_Linked_List() self.marshmallowList = Double_Linked_List() self.chilipepperList = Double_Linked_List() self.whiteChocolateList = Double_Linked_List() self.brownChocolateList = Double_Linked_List() self.milkChocolateList = Double_Linked_List() elif "cll" == type or type == "CLL": self.type = "cll" self.honeyList = CircularLinkedList() self.marshmallowList = CircularLinkedList() self.chilipepperList = CircularLinkedList() self.whiteChocolateList = CircularLinkedList() self.brownChocolateList = CircularLinkedList() self.milkChocolateList = CircularLinkedList()
def test_retrieve(self): list = Double_Linked_List() list.insertBeginning(5) list.insertBeginning(8) self.assertEqual(5, list.retrieve(1)[0])
def test_delete(self): list = Double_Linked_List() list.insertBeginning(7) list.insertEnd(8) list.insertEnd(9) list.insertBeginning(6) list.delete(2) self.assertEqual(9, list.retrieve(2)[0])
def test_destroyList(self): list = Double_Linked_List() list.insertBeginning(5) list.insertLocation(1, 7) list.destroyList() self.assertTrue(list.isEmpty())
def test_insertBeginning(self): list = Double_Linked_List() list.insertBeginning(7) list.insertBeginning(8) self.assertEqual(8, list.retrieve(0)[0])
def test_insertLocation(self): list = Double_Linked_List() list.insertLocation(0, 8) list.insertLocation(0, 7) self.assertEqual(7, list.retrieve(0)[0])
def test_isEmpty(self): list = Double_Linked_List() self.assertTrue(list.isEmpty()) list.insertBeginning(5) self.assertFalse(list.isEmpty())