当前位置: 首页>>代码示例>>Python>>正文


Python LinkedList.searchValueAt方法代码示例

本文整理汇总了Python中LinkedList.LinkedList.searchValueAt方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.searchValueAt方法的具体用法?Python LinkedList.searchValueAt怎么用?Python LinkedList.searchValueAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinkedList.LinkedList的用法示例。


在下文中一共展示了LinkedList.searchValueAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestLinkedList

# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import searchValueAt [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.searchValueAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。