當前位置: 首頁>>代碼示例>>Python>>正文


Python LinkedList.removeAtInd方法代碼示例

本文整理匯總了Python中LinkedList.LinkedList.removeAtInd方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.removeAtInd方法的具體用法?Python LinkedList.removeAtInd怎麽用?Python LinkedList.removeAtInd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在LinkedList.LinkedList的用法示例。


在下文中一共展示了LinkedList.removeAtInd方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestLinkedList

# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import removeAtInd [as 別名]
class TestLinkedList(unittest.TestCase):
    def setUp(self):
        self.linkedList = LinkedList()

    def test_0(self):
        print("{} Can create linked list object".format(inspect.stack()[0][3]))
        self.assertTrue(type(self.linkedList) is LinkedList)

    def test_1(self):
        print("{} Newly created linked list, value and next should be null".format(inspect.stack()[0][3]))
        last = self.linkedList.getNext()
        self.assertEqual(last.value, None)
        self.assertEqual(last.next, None)

    def test_2(self):
        print("{} Newly created list, should be empty".format(inspect.stack()[0][3]))
        self.assertTrue(self.linkedList.isEmpty())

    def test_3(self):
        print("{} After one added, list size should be one".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.assertEqual(self.linkedList.getSize(), 1)

    def test_4(self):
        print("{} After two added, list size should be two".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.assertEqual(self.linkedList.getSize(), 2)

    def test_5(self):
        print("{} After one added, first index search should return value".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.assertEqual(self.linkedList.searchValueAt(0),1)

    def test_6(self):
        print("{} After one added, second index search should return null".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.assertEqual(self.linkedList.searchValueAt(1),None)

    def test_7(self):
        print("{} When two values are added, second index search should return second value".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.assertEqual(self.linkedList.searchValueAt(1),2)

    def test_8(self):
        print("{} When two values are added, first index search should return first value".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.assertEqual(self.linkedList.searchValueAt(0),1)

    def test_9(self):
        print("{} Remove first node on empty list, should return null".format(inspect.stack()[0][3]))
        self.assertEqual(self.linkedList.removeAtInd(0), None)

    def test_10(self):
        print("{} After one added then remove first node, list should be empty".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.removeAtInd(0)
        self.assertTrue(self.linkedList.isEmpty())

    def test_11(self):
        print("{} After one added then remove first node, then add another value, first index should have second value".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.removeAtInd(0)
        self.linkedList.add(2)
        self.assertEqual(self.linkedList.searchValueAt(0),2)

    def test_12(self):
        print("{} After two values added then second value removed, length of list should be one".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.linkedList.removeAtInd(1)
        self.assertEqual(self.linkedList.getSize(),1)

    def test_13(self):
        print("{} After two values added then value at third index removed, length of list should be two".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.linkedList.removeAtInd(2)
        self.assertEqual(self.linkedList.getSize(),2)

    def test_14(self):
        print("{} After two values added then second value removed, first index should be first value and value of second index should be null".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.linkedList.removeAtInd(1)
        self.assertEqual(self.linkedList.searchValueAt(1),None)
        self.assertEqual(self.linkedList.searchValueAt(1),None)

    def test_15(self):
        print("{} After two added then remove first node, length should be one".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
        self.linkedList.add(2)
        self.linkedList.removeAtInd(0)
        self.assertEqual(self.linkedList.getSize(),1)

    def test_16(self):
        print("{} After two values added then remove first, value at first index should be second value pushed".format(inspect.stack()[0][3]))
        self.linkedList.add(1)
#.........這裏部分代碼省略.........
開發者ID:jackreichert,項目名稱:exploring-algorithms,代碼行數:103,代碼來源:testingLinkedList.py


注:本文中的LinkedList.LinkedList.removeAtInd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。