Пример #1
0
class LinkedListTest(unittest.TestCase):
    def setUp(self) -> None:
        self.linkedlist = LinkedList()
        node1 = Node()
        node2 = Node()
        node1.next = node2
        node3 = Node()
        node2.next = node3
        self.linkedlist.head = node1

    def tearDowm(self) -> None:
        pass

    def test_linkedlist_length(self):
        self.assertEqual(3, self.linkedlist.len())

    def test_insert_at_begining(self):
        node_begining = Node
        self.linkedlist.insert_at_begining(node_begining)
        self.assertEqual(4, self.linkedlist.len())

    def test_insert_at_end(self):
        node_end = Node()
        self.linkedlist.insert_at_end(node_end)
        self.assertEqual(4, self.linkedlist.len())

    def test_insert_at_position(self):
        node_pos = Node()
        self.linkedlist.insert_at_position(0, node_pos)
        self.assertEqual(4, self.linkedlist.len())
Пример #2
0
    node1 = Node()
    node1.data = 1

    node2 = Node()
    node2.data = 2
    node1.next = node2

    node3 = Node()
    node3.data = 3
    node2.next = node3

    llst.head = node1

    #inserting the value at the begining.
    node = Node()
    node.data = 0
    llst.insert_at_begining(node)

    #inserting the value at the end
    node4 = Node()
    node4.data = 4
    llst.insert_at_end(node4)

    #insert value at given position
    node23 = Node()
    node23.data = 23
    llst.insert_at_position(0, node23)

    print(llst.len())