[pypy-commit] lang-scheme default: Add a test for the map function (untested so far).

boemmels noreply at buildbot.pypy.org
Fri Feb 17 23:54:42 CET 2012


Author: Juergen Boemmels <boemmels at web.de>
Branch: 
Changeset: r39:e5146e1917d1
Date: 2012-02-14 15:29 +0100
http://bitbucket.org/pypy/lang-scheme/changeset/e5146e1917d1/

Log:	Add a test for the map function (untested so far). Modified cons to
	raise the propper exception if called with the wrong args number

diff --git a/scheme/procedure.py b/scheme/procedure.py
--- a/scheme/procedure.py
+++ b/scheme/procedure.py
@@ -154,6 +154,9 @@
     _symbol_name = "cons"
 
     def procedure(self, ctx, lst):
+        if len(lst) != 2:
+            raise WrongArgsNumber()
+        
         w_car = lst[0]
         w_cdr = lst[1]
         #cons is always creating a new pair
diff --git a/scheme/test/test_eval.py b/scheme/test/test_eval.py
--- a/scheme/test/test_eval.py
+++ b/scheme/test/test_eval.py
@@ -1026,3 +1026,20 @@
            """)
     assert w_res.eq(symbol("consonant"))
 
+def test_map():
+    w_res = eval_noctx("(map car '((1 2) (3 4) (5 6) (7 8)))")
+    assert w_res.equal(parse_("(1 3 5 7)"))
+
+    w_res = eval_noctx("(map cons '(1 2 3) '(4 5 6))")
+    assert w_res.equal(parse_("((1 . 4) (2 . 5) (3 . 6))"))
+
+#    w_res = eval_noctx("(map error '())") # empty list no calls
+#    assert w_res is w_nil
+
+    w_res = eval_noctx("(map (lambda (a) (+ a 1)) '(1 2 3))")
+    assert w_res.equal(parse_("(2 3 4)"))
+
+    py.test.raises(WrongArgType, eval_noctx, "(map car 2)")
+    py.test.raises(WrongArgType, eval_noctx, "(map 2 '(1 2 3))")
+    py.test.raises(WrongArgsNumber, eval_noctx, "(map list)")
+    py.test.raises(WrongArgsNumber, eval_noctx, "(map cons '(1 2 3))")


More information about the pypy-commit mailing list