diff options
author | Raymond Hettinger <python@rcn.com> | 2003-02-23 04:40:07 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-02-23 04:40:07 (GMT) |
commit | 61fe64d5de313dd66e7d42940f54b69ef371fc4f (patch) | |
tree | 0a4e740a956baa9126736c14f6629f2d6506a323 /Lib/test | |
parent | c85b6a2d4d35d6ee0053a8f5870113512c1cdcb6 (diff) | |
download | cpython-61fe64d5de313dd66e7d42940f54b69ef371fc4f.zip cpython-61fe64d5de313dd66e7d42940f54b69ef371fc4f.tar.gz cpython-61fe64d5de313dd66e7d42940f54b69ef371fc4f.tar.bz2 |
User requested changes to the itertools module.
Subsumed times() into repeat().
Added cycle() and chain().
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_itertools.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 09b7d13..4c506d0 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -4,11 +4,18 @@ from itertools import * import sys class TestBasicOps(unittest.TestCase): + def test_chain(self): + self.assertEqual(list(chain('abc', 'def')), list('abcdef')) + def test_count(self): self.assertEqual(zip('abc',count()), [('a', 0), ('b', 1), ('c', 2)]) self.assertEqual(zip('abc',count(3)), [('a', 3), ('b', 4), ('c', 5)]) self.assertRaises(TypeError, count, 2, 3) + def test_cycle(self): + self.assertEqual(list(islice(cycle('abc'),10)), list('abcabcabca')) + self.assertEqual(list(cycle('')), []) + def test_ifilter(self): def isEven(x): return x%2==0 @@ -35,13 +42,9 @@ class TestBasicOps(unittest.TestCase): def test_repeat(self): self.assertEqual(zip(xrange(3),repeat('a')), [(0, 'a'), (1, 'a'), (2, 'a')]) + self.assertEqual(list(repeat('a', 3)), ['a', 'a', 'a']) self.assertRaises(TypeError, repeat) - def test_times(self): - self.assertEqual(list(times(3)), [None]*3) - self.assertEqual(list(times(3, True)), [True]*3) - self.assertRaises(ValueError, times, -1) - def test_imap(self): import operator self.assertEqual(list(imap(operator.pow, range(3), range(1,7))), @@ -94,12 +97,6 @@ class TestBasicOps(unittest.TestCase): libreftest = """ Doctest for examples in the library reference, libitertools.tex ->>> for i in times(3): -... print "Hello" -... -Hello -Hello -Hello >>> amounts = [120.15, 764.05, 823.14] >>> for checknum, amount in izip(count(1200), amounts): @@ -154,6 +151,10 @@ Samuele ... "Returns True if pred(x) is False for every element in the iterable" ... return not nth(ifilter(pred, seq), 0) +>>> def pairwise(seq): +... "s -> (s0,s1), (s1,s2), (s2, s3), ..." +... return izip(seq, islice(seq,1,len(seq))) + """ __test__ = {'libreftest' : libreftest} |