예제 #1
0
    def test_pop_removes_item_in_the_middle_of_the_list(self):
        l1 = LinkedList([1, 2, 3, 4, 5])

        elem = l1.pop(2)
        self.assertEqual(elem, 3)
        self.assertEqual(l1.count(), 4)
        self.assertEqual(l1, LinkedList([1, 2, 4, 5]))

        elem = l1.pop(1)
        self.assertEqual(elem, 2)
        self.assertEqual(l1.count(), 3)
        self.assertEqual(l1, LinkedList([1, 4, 5]))
예제 #2
0
    def test_pop_with_a_single_element_list(self):
        # Default index
        l1 = LinkedList([9])

        elem = l1.pop()
        self.assertEqual(elem, 9)
        self.assertEqual(l1.count(), 0)
        self.assertEqual(l1, LinkedList([]))

        # index == 0
        l1 = LinkedList([9])

        elem = l1.pop(0)
        self.assertEqual(elem, 9)
        self.assertEqual(l1.count(), 0)
        self.assertEqual(l1, LinkedList([]))
예제 #3
0
    def test_pop_removes_last_item(self):
        l1 = LinkedList([1, 2, 3])

        elem = l1.pop(2)
        self.assertEqual(elem, 3)
        self.assertEqual(l1.count(), 2)
        self.assertEqual(l1, LinkedList([1, 2]))