mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
Implement and apply PEP 322, reverse iteration
This commit is contained in:
parent
f607fc5395
commit
85c20a41df
12 changed files with 198 additions and 9 deletions
|
@ -124,9 +124,27 @@ class TestBig(EnumerateTestCase):
|
|||
seq = range(10,20000,2)
|
||||
res = zip(range(20000), seq)
|
||||
|
||||
class TestReversed(unittest.TestCase):
|
||||
|
||||
def test_simple(self):
|
||||
class A:
|
||||
def __getitem__(self, i):
|
||||
if i < 5:
|
||||
return str(i)
|
||||
raise StopIteration
|
||||
def __len__(self):
|
||||
return 5
|
||||
for data in 'abc', range(5), tuple(enumerate('abc')), A(), xrange(1,17,5):
|
||||
self.assertEqual(list(data)[::-1], list(reversed(data)))
|
||||
self.assertRaises(TypeError, reversed, {})
|
||||
|
||||
def test_xrange_optimization(self):
|
||||
x = xrange(1)
|
||||
self.assertEqual(type(reversed(x)), type(iter(x)))
|
||||
|
||||
def test_main(verbose=None):
|
||||
testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig)
|
||||
testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig,
|
||||
TestReversed)
|
||||
test_support.run_unittest(*testclasses)
|
||||
|
||||
# verify reference counting
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue