summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-02-08 04:05:26 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-02-08 04:05:26 (GMT)
commitee33b27ef0bd49227aa59f0d3bca67e7f1e0ab64 (patch)
tree84eaeb0aa5137a9fc753fec4271421f761487abb /Lib/test
parent3b6d025d9bc6a0109e9a2ebd28a4864e8007193a (diff)
downloadcpython-ee33b27ef0bd49227aa59f0d3bca67e7f1e0ab64.zip
cpython-ee33b27ef0bd49227aa59f0d3bca67e7f1e0ab64.tar.gz
cpython-ee33b27ef0bd49227aa59f0d3bca67e7f1e0ab64.tar.bz2
Make deque.rotate() smarter. Beef-up related tests.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_deque.py52
1 files changed, 43 insertions, 9 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 016c2ae..f3bc59f 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -41,16 +41,50 @@ class TestBasic(unittest.TestCase):
self.assertEqual(list(d), list(reversed('abcd')))
def test_rotate(self):
- s = 'abcde'
+ 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)
- d.rotate(2)
- self.assertEqual(''.join(d), 'deabc')
- d.rotate(3)
- self.assertEqual(''.join(d), s)
- d.rotate(-3)
- self.assertEqual(''.join(d), 'deabc')
- d.rotate(-15)
- self.assertEqual(''.join(d), 'deabc')
+ 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))
def test_len(self):
d = deque('ab')