示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
 def test_len(self):
     self.assertEqual(len(self.ll), 4)
     self.assertEqual(len(pyskip.LinkedList()), 0)
示例#5
0
 def test_init(self):
     ll = pyskip.LinkedList()
     self.assertEqual(ll.head, None)