コード例 #1
0
    def test_getValueAt(self):
        # arrange
        TestAppend.linkedList.append(node=pylinkedlist.Node(91))
        TestAppend.linkedList.append(node=pylinkedlist.Node(51))
        TestAppend.linkedList.append(node=pylinkedlist.Node(21))
        TestAppend.linkedList.append(node=pylinkedlist.Node(11))
        TestAppend.linkedList.append(node=pylinkedlist.Node(81))

        # act
        valOne = TestAppend.linkedList.getValueAt(0)
        valTwo = TestAppend.linkedList.getValueAt(2)
        valThree = TestAppend.linkedList.getValueAt(4)

        with pytest.raises(IndexError) as excinfoOne:
            TestAppend.linkedList.getValueAt(-99)

        with pytest.raises(IndexError) as excinfoTwo:
            TestAppend.linkedList.getValueAt(99)

        # assert
        assert valOne == 91
        assert valTwo == 21
        assert valThree == 81
        assert excinfoOne.value.message == "Value given out of range"
        assert excinfoTwo.value.message == "Value given out of range"
コード例 #2
0
    def test_clear(self):
        # arrange
        TestAppend.linkedList.append(node=pylinkedlist.Node(91))
        TestAppend.linkedList.append(node=pylinkedlist.Node(51))
        TestAppend.linkedList.append(node=pylinkedlist.Node(21))

        # act
        TestAppend.linkedList.clear()

        # assert
        assert TestAppend.linkedList.count() == 0
コード例 #3
0
    def test_last(self):
        # arrange
        TestAppend.linkedList.append(node=pylinkedlist.Node(10))
        TestAppend.linkedList.append(node=pylinkedlist.Node(20))
        TestAppend.linkedList.append(node=pylinkedlist.Node(30))

        # act
        lastNode = TestAppend.linkedList.last()

        # assert
        assert lastNode.data == 30
コード例 #4
0
    def test_count(self):
        # arrange
        TestAppend.linkedList.append(node=pylinkedlist.Node(91))
        TestAppend.linkedList.append(node=pylinkedlist.Node(51))
        TestAppend.linkedList.append(node=pylinkedlist.Node(21))
        TestAppend.linkedList.append(node=pylinkedlist.Node(11))
        TestAppend.linkedList.append(node=pylinkedlist.Node(81))

        # act
        # ...

        # assert
        assert TestAppend.linkedList.count() == 5
コード例 #5
0
    def test_prepend(self):
        # arrange
        TestAppend.linkedList.prepend(node=pylinkedlist.Node(10))
        TestAppend.linkedList.prepend(node=pylinkedlist.Node(20))
        TestAppend.linkedList.prepend(node=pylinkedlist.Node(30))
        expectedOrder = [40, 30, 20, 10]

        # act
        TestAppend.linkedList.prepend(node=pylinkedlist.Node(40))

        actualOrder = [
            TestAppend.linkedList.getValueAt(0),
            TestAppend.linkedList.getValueAt(1),
            TestAppend.linkedList.getValueAt(2),
            TestAppend.linkedList.getValueAt(3),
        ]

        # assert
        assert expectedOrder == actualOrder
コード例 #6
0
    def test_insertAtOutOfIndex(self):
        # arrange
        # ...

        # act
        with pytest.raises(IndexError) as excinfoOne:
            TestAppend.linkedList.insertAt(5, node=pylinkedlist.Node(81))

        # assert
        assert excinfoOne.value.message == "Value given out of range"
コード例 #7
0
    def test_append(self):
        # arrange
        TestAppend.linkedList.append(node=pylinkedlist.Node(21))
        TestAppend.linkedList.append(node=pylinkedlist.Node(31))
        TestAppend.linkedList.append(node=pylinkedlist.Node(11))
        expectedOrder = [21, 31, 11, 91]

        # act
        TestAppend.linkedList.append(node=pylinkedlist.Node(91))

        actualOrder = [
            TestAppend.linkedList.getValueAt(0),
            TestAppend.linkedList.getValueAt(1),
            TestAppend.linkedList.getValueAt(2),
            TestAppend.linkedList.getValueAt(3),
        ]

        # assert
        assert expectedOrder == actualOrder
コード例 #8
0
    def test_insertat0whenempty(self):
        # arrange
        TestAppend.linkedList.insertAt(0, node=pylinkedlist.Node(81))
        valOne = TestAppend.linkedList.getValueAt(0)

        # act
        # ...

        # assert
        assert TestAppend.linkedList.count() == 1
        assert valOne == 81
コード例 #9
0
    def test_insertAt(self):
        # arrange
        TestAppend.linkedList.append(node=pylinkedlist.Node(91))
        TestAppend.linkedList.append(node=pylinkedlist.Node(51))
        TestAppend.linkedList.append(node=pylinkedlist.Node(21))
        TestAppend.linkedList.append(node=pylinkedlist.Node(11))
        TestAppend.linkedList.append(node=pylinkedlist.Node(81))
        expectedOrder = [91, 51, 21, 66, 11, 81]

        # act
        TestAppend.linkedList.insertAt(3, node=pylinkedlist.Node(66))

        actualOrder = [
            TestAppend.linkedList.getValueAt(0),
            TestAppend.linkedList.getValueAt(1),
            TestAppend.linkedList.getValueAt(2),
            TestAppend.linkedList.getValueAt(3),
            TestAppend.linkedList.getValueAt(4),
            TestAppend.linkedList.getValueAt(5)
        ]

        assert expectedOrder == actualOrder