[Python-checkins] python/dist/src/Lib/test test_iter.py,1.23,1.24

tim_one@sourceforge.net tim_one@sourceforge.net
Mon, 29 Apr 2002 14:27:34 -0700


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

Modified Files:
	test_iter.py 
Log Message:
builtin_zip():  Take a good guess at how big the result list will be,
and allocate it in one gulp.

This isn't a bugfix, it's just a minor optimization that may or may not
pay off.


Index: test_iter.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_iter.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** test_iter.py	3 Dec 2001 19:33:25 -0000	1.23
--- test_iter.py	29 Apr 2002 21:27:31 -0000	1.24
***************
*** 468,471 ****
--- 468,499 ----
                  pass
  
+         self.assertEqual(zip(xrange(5)), [(i,) for i in range(5)])
+ 
+         # Classes that lie about their lengths.
+         class NoGuessLen5:
+             def __getitem__(self, i):
+                 if i >= 5:
+                     raise IndexError
+                 return i
+ 
+         class Guess3Len5(NoGuessLen5):
+             def __len__(self):
+                 return 3
+ 
+         class Guess30Len5(NoGuessLen5):
+             def __len__(self):
+                 return 30
+ 
+         self.assertEqual(len(Guess3Len5()), 3)
+         self.assertEqual(len(Guess30Len5()), 30)
+         self.assertEqual(zip(NoGuessLen5()), zip(range(5)))
+         self.assertEqual(zip(Guess3Len5()), zip(range(5)))
+         self.assertEqual(zip(Guess30Len5()), zip(range(5)))
+ 
+         expected = [(i, i) for i in range(5)]
+         for x in NoGuessLen5(), Guess3Len5(), Guess30Len5():
+             for y in NoGuessLen5(), Guess3Len5(), Guess30Len5():
+                 self.assertEqual(zip(x, y), expected)
+ 
      # Test reduces()'s use of iterators.
      def test_builtin_reduce(self):