Exemplo n.º 1
0
    def test_insert_at_index(self):
        dll = DoublyLinkedList()

        dll.insert_at_index(0, 'S')
        assert dll.get_at_index(0) == 'S'
        assert dll.head.data == 'S'
        assert dll.tail.data == 'S'
        assert dll.size == 1

        dll.insert_at_index(1, 'O')
        assert dll.get_at_index(1) == 'O'
        assert dll.head.data == 'S'
        assert dll.tail.data == 'O'
        assert dll.size == 2

        dll.insert_at_index(1, 'X')
        assert dll.get_at_index(1) == 'X'
        assert dll.head.data == 'S'
        assert dll.tail.data == 'O'
        assert dll.size == 3

        dll.insert_at_index(3, 'SSS')
        assert dll.get_at_index(3) == 'SSS'
        assert dll.head.data == 'S'
        assert dll.tail.data == 'SSS'
        assert dll.size == 4
Exemplo n.º 2
0
 def test_get_at_index(self):
     dll = DoublyLinkedList(['A', 'B', 'C'])
     assert dll.get_at_index(0) == 'A'
     assert dll.get_at_index(1) == 'B'
     assert dll.get_at_index(2) == 'C'