Commits

Jürgen Bömmels committed e5146e1

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

  • Participants
  • Parent commits 2f31b68

Comments (0)

Files changed (2)

File scheme/procedure.py

     _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

File scheme/test/test_eval.py

            """)
     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))")