예제 #1
0
    def test_add_updatesTailCorrectly(self):
        sl = SingleLinkedList()
        sl.add(1)
        sl.add(2)
        sl.add(100)

        self.assertEqual(sl.tail.value, 100)
예제 #2
0
    def test_remove_whenElemIsTail_returnsRemovedNode(self):
        sl = SingleLinkedList()
        sl.add(1)
        sl.add(2)
        sl.add(3)
        removed = sl.remove(3)

        self.assertEqual(removed.value, 3)
예제 #3
0
    def test_reverse_whenListReversed_returnsAppropriateHeadAndTail(self):
        sl = SingleLinkedList()
        sl.add(1)
        sl.add(2)
        sl.add(3)

        sl.reverse()
        self.assertEqual(sl.head.value, 3)
        self.assertEqual(sl.tail.value, 1)
예제 #4
0
    def test_search_whenItemIsAvailable_returnsNode(self):
        sl = SingleLinkedList()
        sl.add(1)
        sl.add(2)

        item1 = sl.search(1)
        item2 = sl.search(2)
        self.assertTrue(item1.value == 1)
        self.assertTrue(item2.value == 2)
예제 #5
0
    def test_remove_whenElemInMiddle_returnsRemovedNode(self):
        sl = SingleLinkedList()
        sl.add(11)
        sl.add(32)
        sl.add(44)
        sl.add(99)
        removedNode = sl.remove(44)

        self.assertTrue(removedNode.value, 44)
예제 #6
0
    def test_search_whenItemIsNotAvailable_returnsFalse(self):
        sl = SingleLinkedList()
        sl.add(1)
        item2 = sl.search(2)

        self.assertEqual(item2, False)
예제 #7
0
    def test_add_addingFirstElem_savesAsHead(self):
        sl = SingleLinkedList()
        sl.add(1)

        self.assertEqual(sl.head.value, 1)
예제 #8
0
    def test_add_addingSecondElem_hasLengthOfTwo(self):
        sl = SingleLinkedList()
        sl.add(1)
        sl.add(2)

        self.assertEqual(len(sl), 2)