• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python backport_collections.deque函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_extendleft

 def test_extendleft(self):
     d = deque("a")
     self.assertRaises(TypeError, d.extendleft, 1)
     d.extendleft("bcd")
     self.assertEqual(list(d), list(reversed("abcd")))
     d.extendleft(d)
     self.assertEqual(list(d), list("abcddcba"))
     d = deque()
     d.extendleft(range(1000))
     self.assertEqual(list(d), list(reversed(range(1000))))
     self.assertRaises(SyntaxError, d.extendleft, fail())
开发者ID:gward,项目名称:backport_collections,代码行数:11,代码来源:test_deque.py


示例2: test_rotate

    def test_rotate(self):
        s = tuple("abcde")
        n = len(s)

        d = deque(s)
        d.rotate(1)  # verify rot(1)
        self.assertEqual("".join(d), "eabcd")

        d = deque(s)
        d.rotate(-1)  # verify rot(-1)
        self.assertEqual("".join(d), "bcdea")
        d.rotate()  # check default to 1
        self.assertEqual(tuple(d), s)

        for i in xrange(n * 3):
            d = deque(s)
            e = deque(d)
            d.rotate(i)  # check vs. rot(1) n times
            for j in xrange(i):
                e.rotate(1)
            self.assertEqual(tuple(d), tuple(e))
            d.rotate(-i)  # check that it works in reverse
            self.assertEqual(tuple(d), s)
            e.rotate(n - i)  # check that it wraps forward
            self.assertEqual(tuple(e), s)

        for i in xrange(n * 3):
            d = deque(s)
            e = deque(d)
            d.rotate(-i)
            for j in xrange(i):
                e.rotate(-1)  # check vs. rot(-1) n times
            self.assertEqual(tuple(d), tuple(e))
            d.rotate(i)  # check that it works in reverse
            self.assertEqual(tuple(d), s)
            e.rotate(i - n)  # check that it wraps backaround
            self.assertEqual(tuple(e), s)

        d = deque(s)
        e = deque(s)
        e.rotate(BIG + 17)  # verify on long series of rotates
        dr = d.rotate
        for i in xrange(BIG + 17):
            dr()
        self.assertEqual(tuple(d), tuple(e))

        self.assertRaises(TypeError, d.rotate, "x")  # Wrong arg type
        self.assertRaises(TypeError, d.rotate, 1, 10)  # Too many args

        d = deque()
        d.rotate()  # rotate an empty deque
        self.assertEqual(d, deque())
开发者ID:gward,项目名称:backport_collections,代码行数:52,代码来源:test_deque.py


示例3: test_maxlen_zero

    def test_maxlen_zero(self):
        it = iter(range(100))
        deque(it, maxlen=0)
        self.assertEqual(list(it), [])

        it = iter(range(100))
        d = deque(maxlen=0)
        d.extend(it)
        self.assertEqual(list(it), [])

        it = iter(range(100))
        d = deque(maxlen=0)
        d.extendleft(it)
        self.assertEqual(list(it), [])
开发者ID:gward,项目名称:backport_collections,代码行数:14,代码来源:test_deque.py


示例4: test_pickle

 def test_pickle(self):
     d = deque(xrange(200))
     for i in range(pickle.HIGHEST_PROTOCOL + 1):
         s = pickle.dumps(d, i)
         e = pickle.loads(s)
         self.assertNotEqual(id(d), id(e))
         self.assertEqual(list(d), list(e))
开发者ID:gward,项目名称:backport_collections,代码行数:7,代码来源:test_deque.py


示例5: test_container_iterator

    def test_container_iterator(self):
        # Bug #3680: tp_traverse was not implemented for deque iterator objects
        class C(object):
            pass

        for i in range(2):
            obj = C()
            ref = weakref.ref(obj)
            if i == 0:
                container = deque([obj, 1])
            else:
                container = reversed(deque([obj, 1]))
            obj.x = iter(container)
            del obj, container
            gc.collect()
            self.assertTrue(ref() is None, "Cycle was not collected")
开发者ID:gward,项目名称:backport_collections,代码行数:16,代码来源:test_deque.py


示例6: __init__

    def __init__(self):
        self.game = Game()
        self.found_game = False

        self.variation_stack = collections.deque([self.game])
        self.starting_comment = ""
        self.in_variation = False
开发者ID:unidan,项目名称:Magnus,代码行数:7,代码来源:pgn.py


示例7: test_extend

 def test_extend(self):
     d = deque("a")
     self.assertRaises(TypeError, d.extend, 1)
     d.extend("bcd")
     self.assertEqual(list(d), list("abcd"))
     d.extend(d)
     self.assertEqual(list(d), list("abcdabcd"))
开发者ID:gward,项目名称:backport_collections,代码行数:7,代码来源:test_deque.py


示例8: test_copy

 def test_copy(self):
     mut = [10]
     d = deque([mut])
     e = copy.copy(d)
     self.assertEqual(list(d), list(e))
     mut[0] = 11
     self.assertNotEqual(id(d), id(e))
     self.assertEqual(list(d), list(e))
开发者ID:gward,项目名称:backport_collections,代码行数:8,代码来源:test_deque.py


示例9: test_clear

 def test_clear(self):
     d = deque(xrange(100))
     self.assertEqual(len(d), 100)
     d.clear()
     self.assertEqual(len(d), 0)
     self.assertEqual(list(d), [])
     d.clear()  # clear an emtpy deque
     self.assertEqual(list(d), [])
开发者ID:gward,项目名称:backport_collections,代码行数:8,代码来源:test_deque.py


示例10: test_comparisons

    def test_comparisons(self):
        d = deque("xabc")
        d.popleft()
        for e in [d, deque("abc"), deque("ab"), deque(), list(d)]:
            self.assertEqual(d == e, type(d) == type(e) and list(d) == list(e))
            self.assertEqual(d != e, not (type(d) == type(e) and list(d) == list(e)))

        args = map(deque, ("", "a", "b", "ab", "ba", "abc", "xba", "xabc", "cba"))
        for x in args:
            for y in args:
                self.assertEqual(x == y, list(x) == list(y), (x, y))
                self.assertEqual(x != y, list(x) != list(y), (x, y))
                self.assertEqual(x < y, list(x) < list(y), (x, y))
                self.assertEqual(x <= y, list(x) <= list(y), (x, y))
                self.assertEqual(x > y, list(x) > list(y), (x, y))
                self.assertEqual(x >= y, list(x) >= list(y), (x, y))
                self.assertEqual(cmp(x, y), cmp(list(x), list(y)), (x, y))
开发者ID:gward,项目名称:backport_collections,代码行数:17,代码来源:test_deque.py


示例11: __init__

    def __init__(self):
        self._expectations = collections.deque()
        self._is_dead = threading.Event()
        self._std_streams_closed = False

        self._send_queue = queue.Queue()
        self._send_thread = threading.Thread(target=self._send_thread_target)
        self._send_thread.daemon = True
开发者ID:radbrawler,项目名称:python-chess,代码行数:8,代码来源:uci.py


示例12: test_gc_doesnt_blowup

    def test_gc_doesnt_blowup(self):
        import gc

        # This used to assert-fail in deque_traverse() under a debug
        # build, or run wild with a NULL pointer in a release build.
        d = deque()
        for i in xrange(100):
            d.append(1)
            gc.collect()
开发者ID:gward,项目名称:backport_collections,代码行数:9,代码来源:test_deque.py


示例13: test_big_queue_popright

 def test_big_queue_popright(self):
     d = deque()
     append, pop = d.appendleft, d.pop
     for i in xrange(BIG):
         append(i)
     for i in xrange(BIG):
         x = pop()
         if x != i:
             self.assertEqual(x, i)
开发者ID:gward,项目名称:backport_collections,代码行数:9,代码来源:test_deque.py


示例14: test_getitem

    def test_getitem(self):
        n = 200
        d = deque(xrange(n))
        l = range(n)
        for i in xrange(n):
            d.popleft()
            l.pop(0)
            if random.random() < 0.5:
                d.append(i)
                l.append(i)
            for j in xrange(1 - len(l), len(l)):
                assert d[j] == l[j]

        d = deque("superman")
        self.assertEqual(d[0], "s")
        self.assertEqual(d[-1], "n")
        d = deque()
        self.assertRaises(IndexError, d.__getitem__, 0)
        self.assertRaises(IndexError, d.__getitem__, -1)
开发者ID:gward,项目名称:backport_collections,代码行数:19,代码来源:test_deque.py


示例15: test_long_steadystate_queue_popright

 def test_long_steadystate_queue_popright(self):
     for size in (0, 1, 2, 100, 1000):
         d = deque(reversed(xrange(size)))
         append, pop = d.appendleft, d.pop
         for i in xrange(size, BIG):
             append(i)
             x = pop()
             if x != i - size:
                 self.assertEqual(x, i - size)
         self.assertEqual(list(reversed(list(d))), range(BIG - size, BIG))
开发者ID:gward,项目名称:backport_collections,代码行数:10,代码来源:test_deque.py


示例16: test_big_stack_left

 def test_big_stack_left(self):
     d = deque()
     append, pop = d.appendleft, d.popleft
     for i in xrange(BIG):
         append(i)
     for i in reversed(xrange(BIG)):
         x = pop()
         if x != i:
             self.assertEqual(x, i)
     self.assertEqual(len(d), 0)
开发者ID:gward,项目名称:backport_collections,代码行数:10,代码来源:test_deque.py


示例17: test_setitem

 def test_setitem(self):
     n = 200
     d = deque(xrange(n))
     for i in xrange(n):
         d[i] = 10 * i
     self.assertEqual(list(d), [10 * i for i in xrange(n)])
     l = list(d)
     for i in xrange(1 - n, 0, -1):
         d[i] = 7 * i
         l[i] = 7 * i
     self.assertEqual(list(d), l)
开发者ID:gward,项目名称:backport_collections,代码行数:11,代码来源:test_deque.py


示例18: test_reverse

 def test_reverse(self):
     n = 500  # O(n**2) test, don't make this too big
     data = [random.random() for i in range(n)]
     for i in range(n):
         d = deque(data[:i])
         r = d.reverse()
         self.assertEqual(list(d), list(reversed(data[:i])))
         self.assertIs(r, None)
         d.reverse()
         self.assertEqual(list(d), data[:i])
     self.assertRaises(TypeError, d.reverse, 1)  # Arity is zero
开发者ID:gward,项目名称:backport_collections,代码行数:11,代码来源:test_deque.py


示例19: test_maxlen

    def test_maxlen(self):
        self.assertRaises(ValueError, deque, "abc", -1)
        self.assertRaises(ValueError, deque, "abc", -2)
        it = iter(range(10))
        d = deque(it, maxlen=3)
        self.assertEqual(list(it), [])
        self.assertEqual(repr(d), "deque([7, 8, 9], maxlen=3)")
        self.assertEqual(list(d), range(7, 10))
        self.assertEqual(d, deque(range(10), 3))
        d.append(10)
        self.assertEqual(list(d), range(8, 11))
        d.appendleft(7)
        self.assertEqual(list(d), range(7, 10))
        d.extend([10, 11])
        self.assertEqual(list(d), range(9, 12))
        d.extendleft([8, 7])
        self.assertEqual(list(d), range(7, 10))
        d = deque(xrange(200), maxlen=10)
        d.append(d)
        test_support.unlink(test_support.TESTFN)
        fo = open(test_support.TESTFN, "wb")
        try:
            print >> fo, d,
            fo.close()
            fo = open(test_support.TESTFN, "rb")
            self.assertEqual(fo.read(), repr(d))
        finally:
            fo.close()
            test_support.unlink(test_support.TESTFN)

        d = deque(range(10), maxlen=None)
        self.assertEqual(repr(d), "deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])")
        fo = open(test_support.TESTFN, "wb")
        try:
            print >> fo, d,
            fo.close()
            fo = open(test_support.TESTFN, "rb")
            self.assertEqual(fo.read(), repr(d))
        finally:
            fo.close()
            test_support.unlink(test_support.TESTFN)
开发者ID:gward,项目名称:backport_collections,代码行数:41,代码来源:test_deque.py


示例20: test_delitem

 def test_delitem(self):
     n = 500  # O(n**2) test, don't make this too big
     d = deque(xrange(n))
     self.assertRaises(IndexError, d.__delitem__, -n - 1)
     self.assertRaises(IndexError, d.__delitem__, n)
     for i in xrange(n):
         self.assertEqual(len(d), n - i)
         j = random.randrange(-len(d), len(d))
         val = d[j]
         self.assertIn(val, d)
         del d[j]
         self.assertNotIn(val, d)
     self.assertEqual(len(d), 0)
开发者ID:gward,项目名称:backport_collections,代码行数:13,代码来源:test_deque.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python csv.writer函数代码示例发布时间:2022-05-24
下一篇:
Python tasks.background函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap