def test1(self): ll1 = LinkedList([7,1,6]) ll2 = LinkedList([5,9, 2]) h1 = ll1.head h2 = ll2.head sum = sum_lists(h1,h2) sum2 = sum while(sum != None): print(sum) sum = sum.next self.assertEqual(str(sum2),"Node(9)->Node(1)") self.assertEqual(str(sum2.next), "Node(1)->Node(2)") self.assertEqual(str(sum2.next.next), "Node(2)->None")
def test2(self): ll = LinkedList([1, 2, 3, 4, 5]) c = ll.head.next.next.next.next print(c) #Node(5) print(ll) delete_mid_node(c) print(ll) self.assertEqual(str(ll), "Node(1)->Node(2)->Node(3)->Node(4)")
def test1(self): ll = LinkedList([1, 2, 3, 4]) r = ll.head remove_dups(r) self.assertEqual(r.val, 1) self.assertEqual(r.next.val, 2) self.assertEqual(r.next.next.val, 3) self.assertEqual(r.next.next.next.val, 4)
def test2(self): ll = LinkedList([1, 1, 2, 3, 2, 1]) r = ll.head print(ll) print("**") remove_dups(r) print(ll) self.assertEqual(r.val, 1) self.assertEqual(r.next.val, 2) self.assertEqual(r.next.next.val, 3) self.assertEqual(r.next.next.next, None)
def testLinkedListCreation(self): ll = LinkedList([1, 2, 3, 4]) print(ll)
def test3(self): ll = LinkedList() r = ll.head remove_dups(r) print(r) self.assertEqual(r.val, None)