def test_insert_after(self): ll = pyskip.LinkedList() hello = pyskip.SingleNode(value='Hello') world = pyskip.SingleNode(value='world') there = pyskip.SingleNode(value='there') the_end = pyskip.SingleNode(value='the end') ll.insert_first(hello) self.assertEqual(ll.head.value, 'Hello') self.assertEqual(ll.head.next, None) self.assertEqual(len(ll), 1) ll.insert_after(hello, world) self.assertEqual(ll.head.value, 'Hello') self.assertEqual(ll.head.next, world) self.assertEqual(len(ll), 2) ll.insert_after(hello, there) self.assertEqual(ll.head.value, 'Hello') self.assertEqual(ll.head.next, there) self.assertEqual(ll.head.next.next, world) self.assertEqual(len(ll), 3) ll.insert_after(world, the_end) self.assertEqual(ll.head.value, 'Hello') self.assertEqual(ll.head.next, there) self.assertEqual(ll.head.next.next, world) self.assertEqual(ll.head.next.next.next, the_end) self.assertEqual(len(ll), 4)
def setUp(self): super(LinkedListTestCase, self).setUp() self.ll = pyskip.LinkedList() self.head = pyskip.SingleNode(value=0) self.first = pyskip.SingleNode(value=2) self.second = pyskip.SingleNode(value=5) self.third = pyskip.SingleNode(value=6) self.ll.insert_first(self.head) self.ll.insert_after(self.head, self.first) self.ll.insert_after(self.first, self.second) self.ll.insert_after(self.second, self.third)
def test_insert_first(self): ll = pyskip.LinkedList() self.assertEqual(ll.head, None) self.assertEqual(len(ll), 0) world = pyskip.SingleNode(value='world') ll.insert_first(world) self.assertEqual(ll.head.value, 'world') self.assertEqual(ll.head.next, None) self.assertEqual(len(ll), 1) hello = pyskip.SingleNode(value='Hello') ll.insert_first(hello) self.assertEqual(ll.head.value, 'Hello') self.assertEqual(ll.head.next, world) self.assertEqual(len(ll), 2)
def test_len(self): self.assertEqual(len(self.ll), 4) self.assertEqual(len(pyskip.LinkedList()), 0)
def test_init(self): ll = pyskip.LinkedList() self.assertEqual(ll.head, None)