def test_4(self): """ test push(node) """ l = LinkedList() n1 = Node(5) n2 = Node(3) l.append(n1) l.push(n2) self.assertEqual(l.head._value, 3)
def test_3(self): """ test that append(node) adds to end """ l = LinkedList() n1 = Node(5) n2 = Node(3) l.append(n1) l.append(n2) self.assertEqual(l.head._next._value, 3)
def test_5(self): """ test pop() """ l = LinkedList() n1 = Node(5) n2 = Node(3) l.append(n1) l.append(n2) n = l.pop() self.assertEqual(n._value, 5)
def test_8(self): """ test len(list) """ l = LinkedList() n1 = Node(1) n2 = Node(2) n3 = Node(3) l.append(n1) l.append(n2) l.append(n3) self.assertEqual(len(l), 3)
def test_6(self): """ test remove(node) for no matching node """ l = LinkedList() n1 = Node(1) n2 = Node(2) n3 = Node(3) l.append(n1) l.append(n2) l.append(n3) self.assertEqual(l.remove(7), "Error: Node does not exist!")
def test_can_successfully_add_a_node_to_the_end_of_the_linked_list(): x = LinkedList() x.insert("a") x.insert("b") x.insert("c") x.insert("d") x.insert("e") x.append("g") actual = x.contains() expected = ["e","d","c","b","a","g"] assert actual == expected
def test_7(self): """ test remove(node) """ l = LinkedList() n1 = Node(1) n2 = Node(2) n3 = Node(3) l.append(n1) l.append(n2) l.append(n3) l.remove(2) self.assertEqual(n1._next._value, 3)
def test_can_successfully_add_multiple_nodes_to_the_end_of_a_linked_list(): x = LinkedList() x.insert("a") x.insert("b") x.insert("c") x.insert("d") x.insert("e") x.append("test one") x.append("test two") actual = x.contains() expected = ["e","d","c","b","a", "test one", "test two"] assert actual == expected
from linked import LinkedList from linked import Node if __name__ == '__main__': llist = LinkedList() llist.head = Node(1) second = Node(2) third = Node(3) llist.head.next = second second.next = third llist.printList() llist.push(4) llist.push(5) llist.printList() llist.append(10) llist.append(20) llist.printList() llist.delete(20) llist.printList() print(llist.getC()) llist.push(30) llist.printList() print(llist.getCentre()) llist.reverse() llist.printList() llist.rev() llist.printList()
def test_2(self): """ test that append adds a node """ l = LinkedList() n1 = Node(5) l.append(n1) self.assertEqual(l.head._value, 5)