[pypy-svn] rev 669 - in pypy/trunk/src/pypy/module: . test
lac at codespeak.net
lac at codespeak.net
Thu May 29 15:10:10 CEST 2003
Author: lac
Date: Thu May 29 15:10:10 2003
New Revision: 669
Modified:
pypy/trunk/src/pypy/module/builtin_app.py
pypy/trunk/src/pypy/module/test/test_functional.py
Log:
Added trivial functions to test map. Fixed bug where map(None) did not
raise a TypeError.
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 15:10:10 2003
@@ -3,7 +3,15 @@
return function(*args, **kwds)
def map(function, *collections):
- if len(collections) == 1:
+ """does 3 separate things.
+ 1. if function is None, return a list of tuples, each with one
+ item from each collection. If the collections have different
+ lengths, shorter ones are padded with None."""
+
+ if len(collections) == 0:
+ raise TypeError, "map() requires at least one sequence"
+
+ elif len(collections) == 1:
#it's the most common case, so make it faster
if function is None:
return collections[0]
Modified: pypy/trunk/src/pypy/module/test/test_functional.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_functional.py (original)
+++ pypy/trunk/src/pypy/module/test/test_functional.py Thu May 29 15:10:10 2003
@@ -1,15 +1,46 @@
import testsupport
from pypy.module.builtin_app import map, filter, reduce, zip
+# trivial functions for testing
+
+def add_two(x):
+ return x + 2
+
+def add_both(x, y):
+ return x + y
+
+
class TestMap(testsupport.TestCase):
+ def test_trivial_map_one_seq(self):
+ self.assertEqual(map(add_two, [1, 2, 3, 4]), [3, 4, 5, 6])
+
+ def test_trivial_map_two_seq(self):
+ self.assertEqual(map(add_both, [1, 2, 3, 4],[1, 2, 3, 4]), [2, 4, 6, 8])
+
+ def test_trivial_map_sizes_dont_match_and_should(self):
+ self.assertRaises(TypeError, map, add_both, [1, 2, 3, 4], [1, 2, 3])
+
+ def test_trivial_map_no_arguments(self):
+ self.assertRaises(TypeError, map)
+
+ def test_trivial_map_no_function_no_seq(self):
+ self.assertRaises(TypeError, map, None)
+
+ def test_trivial_map_no_fuction_one_seq(self):
+ self.assertEqual(map(None, [1, 2, 3]), [1, 2, 3])
+
+ def test_trivial_map_no_function(self):
+ self.assertEqual(map(None, [1,2,3], [4,5,6], [7,8], [1]),
+ [(1, 4, 7, 1), (2, 5, 8, None), (3, 6, None, None)])
+
def test_map_identity1(self):
a = ['1', 2, 3, 'b', None]
b = a[:]
self.assertEqual(map(lambda x: x, a), a)
self.assertEqual(a, b)
- def test_map_None1(self):
+ def test_map_None(self):
a = ['1', 2, 3, 'b', None]
b = a[:]
self.assertEqual(map(None, a), a)
More information about the Pypy-commit
mailing list