def test_LinkedListWithTwoNode(): linkedList = LinkedList() linkedList.append(1) linkedList.append(2) assert linkedList.head.value == 1 assert linkedList.tail.value == 2
class Vertex: def __init__(self, value): if value == None: raise AttributeError('Problem with value: value is empty') self.value = value self.edges = LinkedList() def addEdge(self, edge): self.edges.append(edge) return self
def test_reverseLinkedList(): linkedList = LinkedList() linkedList.append(1) linkedList.append(2) linkedList.append(3) linkedList.reverse() counter = 3 for node in linkedList: assert node.value == counter counter -= 1
def test_searchValueLinkedList(): linkedList = LinkedList() linkedList.append(1) linkedList.append(2) assert linkedList.search(1).value == 1 assert linkedList.search(2).value == 2 assert linkedList.search(1).next.value == 2 assert linkedList.search(3) == None
class Stack: def __init__(self): self.stack = LinkedList() def isEmpty(self): return self.stack.head == None def push(self, value): self.stack.prepend(value) def pop(self): removedItem = self.stack.deleteHead() if removedItem == None: return None return removedItem.value def peek(self): if self.isEmpty(): return None return self.stack.head.value
def test_LinkedListRemoveSecondValue(): linkedList = LinkedList() linkedList.append(1) linkedList.append(2) linkedList.remove(2) assert linkedList.head.value == 1 assert linkedList.head.value == linkedList.tail.value
def test_iteration(): linkedList = LinkedList() linkedList.append(1) linkedList.append(2) linkedList.append(3) counter = 1 for node in linkedList: assert node.value == counter counter += 1
def __init__(self, value): if value == None: raise AttributeError('Problem with value: value is empty') self.value = value self.edges = LinkedList()
def __init__(self): self.stack = LinkedList()
def test_searchInEmptyLinkedList(): linkedList = LinkedList() assert linkedList.search(2) == None
def test_LinkedListWithTwoValues(): linkedList = LinkedList() linkedList.append(1) linkedList.append(2) assert linkedList.size() == 2
def test_emptyLinkedList(): linkedList = LinkedList() assert linkedList.size() == 0
def test_linkedListWithOneNode(): linkedList = LinkedList() linkedList.append(1) assert linkedList.head.value == 1
def test_LinkedListRemoveFirstNode(): linkedList = LinkedList() linkedList.append(1) assert linkedList.head.value == 1 linkedList.remove(1) assert linkedList.head == None