[Python-checkins] python/dist/src/Lib/test test_itertools.py,1.4,1.5
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Sat, 22 Feb 2003 20:40:09 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv23087/Lib/test
Modified Files:
test_itertools.py
Log Message:
User requested changes to the itertools module.
Subsumed times() into repeat().
Added cycle() and chain().
Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_itertools.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_itertools.py 9 Feb 2003 06:40:58 -0000 1.4
--- test_itertools.py 23 Feb 2003 04:40:07 -0000 1.5
***************
*** 5,8 ****
--- 5,11 ----
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)])
***************
*** 10,13 ****
--- 13,20 ----
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):
***************
*** 36,46 ****
self.assertEqual(zip(xrange(3),repeat('a')),
[(0, 'a'), (1, 'a'), (2, '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
--- 43,49 ----
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_imap(self):
import operator
***************
*** 95,104 ****
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]
--- 98,101 ----
***************
*** 154,157 ****
--- 151,158 ----
... "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)))
"""