summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_iter.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-04-29 21:27:32 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-04-29 21:27:32 (GMT)
commit67d687a1145d12f1e7e835a0c8259ba1cc2450b1 (patch)
tree149659a94c9324080026103b025eafef2fa80095 /Lib/test/test_iter.py
parent541703b18f6eaff9ffdc4d101cb692a4362da42f (diff)
downloadcpython-67d687a1145d12f1e7e835a0c8259ba1cc2450b1.zip
cpython-67d687a1145d12f1e7e835a0c8259ba1cc2450b1.tar.gz
cpython-67d687a1145d12f1e7e835a0c8259ba1cc2450b1.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_iter.py')
-rw-r--r--Lib/test/test_iter.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py
index 13ed5bd..c9f6961 100644
--- a/Lib/test/test_iter.py
+++ b/Lib/test/test_iter.py
@@ -467,6 +467,34 @@ class TestCase(unittest.TestCase):
except OSError:
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):
from operator import add