| 1 |
|
| 2 |
(add-tests-with-string-output "cons" |
| 3 |
[(fxadd1 0) => "1\n"] |
| 4 |
[(pair? (cons 1 2)) => "#t\n"] |
| 5 |
[(pair? 12) => "#f\n"] |
| 6 |
[(pair? #t) => "#f\n"] |
| 7 |
[(pair? #f) => "#f\n"] |
| 8 |
[(pair? ()) => "#f\n"] |
| 9 |
[(fixnum? (cons 12 43)) => "#f\n"] |
| 10 |
[(boolean? (cons 12 43)) => "#f\n"] |
| 11 |
[(null? (cons 12 43)) => "#f\n"] |
| 12 |
[(not (cons 12 43)) => "#f\n"] |
| 13 |
[(if (cons 12 43) 32 43) => "32\n"] |
| 14 |
[(car (cons 1 23)) => "1\n"] |
| 15 |
[(cdr (cons 43 123)) => "123\n"] |
| 16 |
[(car (car (cons (cons 12 3) (cons #t #f)))) => "12\n"] |
| 17 |
[(cdr (car (cons (cons 12 3) (cons #t #f)))) => "3\n"] |
| 18 |
[(car (cdr (cons (cons 12 3) (cons #t #f)))) => "#t\n"] |
| 19 |
[(cdr (cdr (cons (cons 12 3) (cons #t #f)))) => "#f\n"] |
| 20 |
[(let ([x (let ([y (fx+ 1 2)]) (fx* y y))]) |
| 21 |
(cons x (fx+ x x))) |
| 22 |
=> "(9 . 18)\n"] |
| 23 |
[(let ([t0 (cons 1 2)] [t1 (cons 3 4)]) |
| 24 |
(let ([a0 (car t0)] [a1 (car t1)] [d0 (cdr t0)] [d1 (cdr t1)]) |
| 25 |
(let ([t0 (cons a0 d1)] [t1 (cons a1 d0)]) |
| 26 |
(cons t0 t1)))) |
| 27 |
=> "((1 . 4) 3 . 2)\n"] |
| 28 |
[(let ([t (cons 1 2)]) |
| 29 |
(let ([t t]) |
| 30 |
(let ([t t]) |
| 31 |
(let ([t t]) |
| 32 |
t)))) |
| 33 |
=> "(1 . 2)\n"] |
| 34 |
[(let ([t (let ([t (let ([t (let ([t (cons 1 2)]) t)]) t)]) t)]) t) |
| 35 |
=> "(1 . 2)\n"] |
| 36 |
[(let ([x ()]) |
| 37 |
(let ([x (cons x x)]) |
| 38 |
(let ([x (cons x x)]) |
| 39 |
(let ([x (cons x x)]) |
| 40 |
(cons x x))))) |
| 41 |
=> "((((()) ()) (()) ()) ((()) ()) (()) ())\n"] |
| 42 |
[(cons (let ([x #t]) (let ([y (cons x x)]) (cons x y))) |
| 43 |
(cons (let ([x #f]) (let ([y (cons x x)]) (cons y x))) |
| 44 |
())) |
| 45 |
=> "((#t #t . #t) ((#f . #f) . #f))\n"] |
| 46 |
) |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
#!eof |
| 51 |
(add-tests-with-string-output "procedures" |
| 52 |
[(letrec () 12) => "12\n"] |
| 53 |
[(letrec () (let ([x 5]) (fx+ x x))) => "10\n"] |
| 54 |
[(letrec ([f (lambda () 5)]) 7) => "7\n"] |
| 55 |
[(letrec ([f (lambda () 5)]) (let ([x 12]) x)) => "12\n"] |
| 56 |
[(letrec ([f (lambda () 5)]) (f)) => "5\n"] |
| 57 |
[(letrec ([f (lambda () 5)]) (let ([x (f)]) x)) => "5\n"] |
| 58 |
[(letrec ([f (lambda () 5)]) (fx+ (f) 6)) => "11\n"] |
| 59 |
[(letrec ([f (lambda () 5)]) (fx- 20 (f))) => "15\n"] |
| 60 |
[(letrec ([f (lambda () 5)]) (fx+ (f) (f))) => "10\n"] |
| 61 |
[(letrec ([f (lambda () (fx+ 5 7))] |
| 62 |
[g (lambda () 13)]) |
| 63 |
(fx+ (f) (g))) => "25\n"] |
| 64 |
[(letrec ([f (lambda (x) (fx+ x 12))]) (f 13)) => "25\n"] |
| 65 |
[(letrec ([f (lambda (x) (fx+ x 12))]) (f (f 10))) => "34\n"] |
| 66 |
[(letrec ([f (lambda (x) (fx+ x 12))]) (f (f (f 0)))) => "36\n"] |
| 67 |
[(letrec ([f (lambda (x y) (fx+ x y))] |
| 68 |
[g (lambda (x) (fx+ x 12))]) |
| 69 |
(f 16 (f (g 0) (fx+ 1 (g 0))))) => "41\n"] |
| 70 |
[(letrec ([f (lambda (x) (g x x))] |
| 71 |
[g (lambda (x y) (fx+ x y))]) |
| 72 |
(f 12)) => "24\n"] |
| 73 |
[(letrec ([f (lambda (x) |
| 74 |
(if (fxzero? x) |
| 75 |
1 |
| 76 |
(fx* x (f (fxsub1 x)))))]) |
| 77 |
(f 5)) => "120\n"] |
| 78 |
[(letrec ([e (lambda (x) (if (fxzero? x) #t (o (fxsub1 x))))] |
| 79 |
[o (lambda (x) (if (fxzero? x) #f (e (fxsub1 x))))]) |
| 80 |
(e 25)) => "#f\n"] |
| 81 |
) |
| 82 |
|
| 83 |
(add-tests-with-string-output "deeply nested procedures" |
| 84 |
[(letrec ([sum (lambda (n ac) |
| 85 |
(if (fxzero? n) |
| 86 |
ac |
| 87 |
(app sum (fxsub1 n) (fx+ n ac))))]) |
| 88 |
(app sum 10000 0)) => "50005000\n"] |
| 89 |
[(letrec ([e (lambda (x) (if (fxzero? x) #t (app o (fxsub1 x))))] |
| 90 |
[o (lambda (x) (if (fxzero? x) #f (app e (fxsub1 x))))]) |
| 91 |
(app e 5000000)) => "#t\n"] |
| 92 |
) |