[pypy-svn] rev 701 - in pypy/trunk/src/pypy/module: . test
lac at codespeak.net
lac at codespeak.net
Thu May 29 17:39:00 CEST 2003
Author: lac
Date: Thu May 29 17:38:59 2003
New Revision: 701
Added:
pypy/trunk/src/pypy/module/test/test_zip.py
Modified:
pypy/trunk/src/pypy/module/builtin_app.py
Log:
Made more test for the zip function.
Modified: pypy/trunk/src/pypy/module/builtin_app.py
==============================================================================
--- pypy/trunk/src/pypy/module/builtin_app.py (original)
+++ pypy/trunk/src/pypy/module/builtin_app.py Thu May 29 17:38:59 2003
@@ -66,6 +66,11 @@
return res
def zip(*collections):
+ """return a list of tuples, where the nth tuple contains every
+ nth item of each collection. If the collections have different
+ lengths, zip returns a list as long as the shortest collection,
+ ignoring the trailing items in the other collections."""
+
if len(collections) == 0:
raise TypeError, "zip() requires at least one sequence"
res = []
Added: pypy/trunk/src/pypy/module/test/test_zip.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/module/test/test_zip.py Thu May 29 17:38:59 2003
@@ -0,0 +1,33 @@
+import testsupport
+from pypy.module.builtin_app import zip
+
+class TestZip(testsupport.TestCase):
+
+ def test_zip_no_arguments(self):
+ self.assertRaises(TypeError, zip)
+
+ def test_one_list(self):
+ self.assertEqual(zip([1, 2, 3]), [(1,), (2,), (3,)])
+
+ def test_three_lists_same_size(self):
+ self.assertEqual(zip([1, 2, 3], [3, 4, 5], [6, 7, 8]),
+ [(1, 3, 6), (2, 4, 7), (3, 5, 8)])
+
+ def test_three_lists_different_sizes(self):
+ self.assertEqual(zip([1, 2], [3, 4, 5, 6], [6, 7, 8]),
+ [(1, 3, 6), (2, 4, 7)])
+
+ def test_tuples(self):
+ self.assertEqual(zip((1, 2, 3)), [(1,), (2,), (3,)])
+
+ def test_string(self):
+ self.assertEqual(zip('hello'), [('h',), ('e',), ('l',), ('l',), ('o',)])
+
+ def test_mixed_types(self):
+ self.assertEqual(zip('hello', [1,2,3,4], (7,8,9,10)),
+ [('h', 1, 7), ('e', 2, 8), ('l', 3, 9), ('l', 4, 10)])
+
+if __name__ == '__main__':
+ testsupport.main()
+
+
More information about the Pypy-commit
mailing list