Beispiel #1
0
 public void Count()
 {
     var test = new IntegrationTest(@"
     (defun make-counter ()
       (let ((count 0))
     (lambda () (set! count (+ 1 count)))))
     (define count-a (make-counter))
     (define count-b (make-counter))
     ");
     test.Test("(count-a) (count-b) (count-a) (count-a) (count-b)", "1", "1", "2", "3", "2");
 }
Beispiel #2
0
 public void Adder()
 {
     var test = new IntegrationTest(@"
     (defun make-adder (x)
       (lambda (y)
     (+ x y)))
     (define add2 (make-adder 2))
     (define add3 (make-adder 3))
     ");
     test.Test("(add2 3) (add3 3)", "5", "6");
 }
Beispiel #3
0
 public void Fibonacci(string input, string output)
 {
     var test = new IntegrationTest(@"
     (defun fib (n)
       (defun iter (i p f)
     (if (eq i n)
     f
     (iter (+ i 1) f (+ p f))))
       (iter 0 1 0))
     ");
     test.Test(input, output);
 }
Beispiel #4
0
        public void Wiggle(string input)
        {
            var test = new IntegrationTest();
            string smidgen = Math.Pow(2, -32).ToString(CultureInfo.InvariantCulture);

            test.Test(string.Format("(+ {0} {0} -{0})", input), input);
            test.Test(string.Format("(= {0} (+ {0} {0} -{0}))", input), "T");

            test.Test(string.Format("(+ {0} {1} -{1})", input, smidgen), input);
            test.Test(string.Format("(= {0} (+ {0} {1} -{1}))", input, smidgen), "T");

            test.Test(string.Format("(< {0} (+ {0} {1}))", input, smidgen), "T");
            test.Test(string.Format("(< (- {0} {1}) {0})", input, smidgen), "T");

            test.Test(string.Format("(> {0} (- {0} {1}))", input, smidgen), "T");
            test.Test(string.Format("(> (+ {0} {1}) {0})", input, smidgen), "T");

            test.Test(string.Format("(= {0} (+ {0} {0}))", input), "NIL");
            test.Test(string.Format("(= {0} (+ {0} {1}))", input, smidgen), "NIL");
            test.Test(string.Format("(< {0} (- {0} {1}))", input, smidgen), "NIL");
            test.Test(string.Format("(> {0} (+ {0} {1}))", input, smidgen), "NIL");
        }