# [pypy-svn] pypy collections-module: rotate().

Tue Feb 15 17:26:06 CET 2011

```Author: Armin Rigo <arigo at tunes.org>
Branch: collections-module
Changeset: r41976:8b2c6f893aee
Date: 2011-02-15 17:20 +0100
http://bitbucket.org/pypy/pypy/changeset/8b2c6f893aee/

Log:	rotate().

diff --git a/pypy/module/_collections/test/test_deque.py b/pypy/module/_collections/test/test_deque.py
--- a/pypy/module/_collections/test/test_deque.py
+++ b/pypy/module/_collections/test/test_deque.py
@@ -172,57 +172,24 @@
assert list(d) == list(reversed(range(1000, 1200)))

def test_rotate(self):
+        from _collections import deque
s = tuple('abcde')
n = len(s)

d = deque(s)
d.rotate(1)             # verify rot(1)
-        self.assertEqual(''.join(d), 'eabcd')
+        assert ''.join(d) == 'eabcd'

d = deque(s)
d.rotate(-1)            # verify rot(-1)
-        self.assertEqual(''.join(d), 'bcdea')
+        assert ''.join(d) == 'bcdea'
d.rotate()              # check default to 1
-        self.assertEqual(tuple(d), s)
+        assert 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())
+        d.rotate(500000002)
+        assert tuple(d) == tuple('deabc')
+        d.rotate(-5000002)
+        assert tuple(d) == tuple(s)

def test_len(self):
d = deque('ab')

diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -264,7 +264,7 @@
ri = BLOCKLEN - 1

@unwrap_spec('self', int)
-    def rotate(self, n):
+    def rotate(self, n=1):
len = self.len
if len == 0:
return
```