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


Python backport_collections.deque函数代码示例

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


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


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