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


Python pyllist.sllist函数代码示例

本文整理汇总了Python中pyllist.sllist函数的典型用法代码示例。如果您正苦于以下问题:Python sllist函数的具体用法?Python sllist怎么用?Python sllist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_node_str

 def test_node_str(self):
     a = sllist([None, None]).first
     self.assertEqual(str(a), 'sllistnode(None)')
     b = sllist([1, None]).first
     self.assertEqual(str(b), 'sllistnode(1)')
     c = sllist(['abc', None]).first
     self.assertEqual(str(c), 'sllistnode(abc)')
开发者ID:235,项目名称:pypy-llist,代码行数:7,代码来源:test_pyllist.py

示例2: test_node_repr

 def test_node_repr(self):
     a = sllist([None]).first
     self.assertEqual(repr(a), '<sllistnode(None)>')
     b = sllist([1, None]).first
     self.assertEqual(repr(b), '<sllistnode(1)>')
     c = sllist(['abc', None]).first
     self.assertEqual(repr(c), '<sllistnode(\'abc\')>')
开发者ID:235,项目名称:pypy-llist,代码行数:7,代码来源:test_pyllist.py

示例3: test_node_repr

 def test_node_repr(self):
     a = sllist([None]).first
     self.assertEqual(repr(a), "<sllistnode(None)>")
     b = sllist([1, None]).first
     self.assertEqual(repr(b), "<sllistnode(1)>")
     c = sllist(["abc", None]).first
     self.assertEqual(repr(c), "<sllistnode('abc')>")
开发者ID:pombredanne,项目名称:pypy-llist,代码行数:7,代码来源:test_pyllist.py

示例4: test_guards_after_concat

 def test_guards_after_concat(self):
     a = sllist([1, 2])
     b = sllist([3, 4])
     c = a + b
     self.assertIsNot(c.first, None)
     self.assertEqual(c.first.value, 1)
     self.assertIsNot(c.last, None)
     self.assertEqual(c.last.value, 4)
开发者ID:rgsoda,项目名称:pypy-llist,代码行数:8,代码来源:test_pyllist.py

示例5: test_guards_after_concat_inplace

 def test_guards_after_concat_inplace(self):
     a = sllist([1, 2])
     b = sllist([3, 4])
     orig_a_first = a.first
     a += b
     self.assertIs(a.first, orig_a_first)
     self.assertEqual(a.first.value, 1)
     self.assertIsNot(a.last, None)
     self.assertEqual(a.last.value, 4)
开发者ID:rgsoda,项目名称:pypy-llist,代码行数:9,代码来源:test_pyllist.py

示例6: test_insert_value_before_first

 def test_insert_value_before_first(self):
     ll = sllist(xrange(4))
     ref = sllist([10, 0, 1, 2, 3])
     next = ll.nodeat(0)
     arg_node = sllistnode(10)
     new_node = ll.insert(arg_node, ll.nodeat(0))
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.next, next)
     self.assertEqual(new_node, ll.first)
     self.assertEqual(ll, ref)
开发者ID:235,项目名称:pypy-llist,代码行数:11,代码来源:test_pyllist.py

示例7: test_appendleft

 def test_appendleft(self):
     ll = sllist(xrange(4))
     ref = sllist([10, 0, 1, 2, 3])
     next = ll.nodeat(0)
     arg_node = sllistnode(10)
     new_node = ll.appendleft(arg_node)
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.next, next)
     self.assertEqual(ll.first, new_node)
     self.assertEqual(ll, ref)
开发者ID:235,项目名称:pypy-llist,代码行数:11,代码来源:test_pyllist.py

示例8: test_insert_value_before

 def test_insert_value_before(self):
     ll = sllist(xrange(4))
     ref = sllist([0, 1, 10, 2, 3])
     prev = ll.nodeat(1)
     next = ll.nodeat(2)
     arg_node = sllistnode(10)
     new_node = ll.insert(arg_node, ll.nodeat(2))
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.next, next)
     self.assertEqual(prev.next, new_node)
     self.assertEqual(ll, ref)
开发者ID:235,项目名称:pypy-llist,代码行数:12,代码来源:test_pyllist.py

示例9: test_appendright

 def test_appendright(self):
     ll = sllist(xrange(4))
     ref = sllist([0, 1, 2, 3, 10])
     prev = ll.nodeat(-1)
     arg_node = sllistnode(10)
     new_node = ll.appendright(arg_node)
     self.assertNotEqual(new_node, arg_node)
     self.assertEqual(new_node.value, 10)
     self.assertEqual(new_node.next, None)
     self.assertEqual(prev.next, new_node)
     self.assertEqual(ll.last, new_node)
     self.assertEqual(ll, ref)
开发者ID:235,项目名称:pypy-llist,代码行数:12,代码来源:test_pyllist.py

示例10: test_concat

 def test_concat(self):
     a_ref = range(0, 1024, 4)
     a = sllist(a_ref)
     b_ref = range(8092, 8092 + 1024, 4)
     b = sllist(b_ref)
     ab_ref = sllist(a_ref + b_ref)
     c = a + b
     self.assertEqual(c, ab_ref)
     self.assertEqual(len(c), len(ab_ref))
     c = a + b_ref
     self.assertEqual(c, ab_ref)
     self.assertEqual(len(c), len(ab_ref))
开发者ID:235,项目名称:pypy-llist,代码行数:12,代码来源:test_pyllist.py

示例11: test_cmp

 def test_cmp(self):
     a = sllist(xrange(0, 1100))
     b = sllist(xrange(0, 1101))
     c = [xrange(0, 1100)]
     self.assertEqual(cmp(a, a), 0)
     self.assertEqual(cmp(a, b), -1)
     self.assertEqual(cmp(b, a), 1)
     self.assertEqual(cmp(a, c), 1)
     self.assertEqual(cmp(c, a), -1)
     self.assertEqual(cmp([], []), 0)
     self.assertEqual(cmp([], a), -1)
     self.assertEqual(cmp(a, []), 1)
开发者ID:235,项目名称:pypy-llist,代码行数:12,代码来源:test_pyllist.py

示例12: test_concat_empty

 def test_concat_empty(self):
     empty = sllist()
     filled_ref = range(0, 1024, 4)
     filled = sllist(filled_ref)
     res = empty + empty
     self.assertEqual(res, sllist([] + []))
     self.assertEqual(len(res), 0)
     res = empty + filled
     self.assertEqual(res, sllist([] + filled_ref))
     self.assertEqual(len(res), len(filled_ref))
     res = filled + empty
     self.assertEqual(res, sllist(filled_ref + []))
     self.assertEqual(len(res), len(filled_ref))
开发者ID:235,项目名称:pypy-llist,代码行数:13,代码来源:test_pyllist.py

示例13: test_init_empty

 def test_init_empty(self):
     ll = sllist()
     self.assertEqual(len(ll), 0)
     self.assertEqual(ll.size, 0)
     self.assertEqual(list(ll), [])
     self.assertIs(ll.first, None)
     self.assertIs(ll.last, None)
开发者ID:rgsoda,项目名称:pypy-llist,代码行数:7,代码来源:test_pyllist.py

示例14: test_guards_after_remove

 def test_guards_after_remove(self):
     ll = sllist([1, 2])
     ll.remove(ll.last)
     self.assertIs(ll.first, ll.last)
     ll.remove(ll.first)
     self.assertIs(ll.first, None)
     self.assertIs(ll.last, None)
开发者ID:rgsoda,项目名称:pypy-llist,代码行数:7,代码来源:test_pyllist.py

示例15: _add

def _add(letters):
    """
    Runs the loveAlgorithm to reduce a length-5 singly-linked list to length <= 2.

    Returns sllist([1]) if an infinite loop occurs on the input.
    """

    def step(sll):
        for node in sll.iternodes():
            try:
                node.value += node.next()
                if node.value >= 10:
                    sll.insertbefore(node, node.value/10)
                    node.value %= 10
            except TypeError:
                'reached end of sllist'
                sll.popright()

    visited = set()
    while len(letters) > 2:
        curr = str(letters)  # stringify the Sllist since you cannot hash a mutable object 
        if curr in visited:
            return sllist([1])
        visited.add(curr)

        step(letters)

    return letters
开发者ID:welsny,项目名称:LoveCalculator,代码行数:28,代码来源:algorithm.py


注:本文中的pyllist.sllist函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。