Permalink
Browse files

more tests

  • Loading branch information...
1 parent e966b61 commit df200226cdb067f76a327c0a7f92fdb5254f3c4b @ajb committed May 8, 2012
Showing with 15 additions and 0 deletions.
  1. +15 −0 Homework5/test/evalScheemTest.js
@@ -73,6 +73,21 @@ suite('scheem', function(){
assert.deepEqual(
evalSchemeString('(begin (define globalvar 9) ( ( lambda (x y globalvar) (set! globalvar (* x y)) ) 2 3 ) globalvar )', {}), 6);
});
+
+ test('an inner function modifies a variable in the outer function', function() {
+ assert.deepEqual(
+ evalSchemeString('( ( lambda (x y z) (+ x (+ y z)) ) 2 ((lambda (j) (set! x j)) 0) 3)', {}), 3);
+ });
+
+ test('an outer function returns an inner function', function() {
+ assert.deepEqual(
+ evalSchemeString('(begin (define plusPlusOne (lambda (x) ( (lambda (x) (+ x 1) ) (+ x 1) ) ) ) (plusPlusOne 1) )', {}), 3);
+ });
+
+ test('an outer function returns an inner function, inner function refers to outer function variables', function() {
+ assert.deepEqual(
+ evalSchemeString('(begin (define plusPlusOne (lambda (x) ( (lambda (j) (* j x) ) (+ x 1) ) ) ) (plusPlusOne 1) )', {}), 2);
+ });
});

0 comments on commit df20022

Please sign in to comment.