[Python-checkins] python/dist/src/Lib/test test_itertools.py,1.12,1.13

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Wed, 18 Jun 2003 12:25:39 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv15836/Lib/test

Modified Files:
	test_itertools.py 
Log Message:
Minor updates:

* Updated comment on design of imap()
* Added untraversed object in izip() structure
* Replaced the pairwise() example with a more general window() example



Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_itertools.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** test_itertools.py	29 May 2003 07:18:57 -0000	1.12
--- test_itertools.py	18 Jun 2003 19:25:37 -0000	1.13
***************
*** 428,435 ****
  ...     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)))
- 
  >>> def padnone(seq):
  ...     "Returns the sequence elements and then returns None indefinitely"
--- 428,431 ----
***************
*** 443,446 ****
--- 439,452 ----
  ...     return sum(imap(operator.mul, vec1, vec2))
  
+ >>> def window(seq, n=2):
+ ...     "Returns a sliding window (of width n) over data from the iterable"
+ ...     "   s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ...                   "
+ ...     it = iter(seq)
+ ...     result = tuple(islice(it, n))
+ ...     if len(result) == n:
+ ...         yield result
+ ...     for elem in it:
+ ...         result = result[1:] + (elem,)
+ ...         yield result
  
  This is not part of the examples but it tests to make sure the definitions
***************
*** 474,479 ****
  False
  
! >>> list(pairwise('abc'))
  [('a', 'b'), ('b', 'c')]
  
  >>> list(islice(padnone('abc'), 0, 6))
--- 480,488 ----
  False
  
! >>> list(window('abc'))
  [('a', 'b'), ('b', 'c')]
+ 
+ >>> list(window('abc',5))
+ []
  
  >>> list(islice(padnone('abc'), 0, 6))