Last active
November 2, 2017 16:37
-
-
Save ThiagoLira/6c2221ee12875c6bb7a1860dc23b7cdb to your computer and use it in GitHub Desktop.
Test cases for Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Equal? | |
;numbers | |
(test (v*s-v (interpS '(equal? 3 2))) (numV 0)) | |
(test (v*s-v (interpS '(equal? (+ 3 2) 5))) (numV 1)) | |
;closures | |
(test (v*s-v (interpS '(equal? (lambda x (car x)) (lambda y (car y))))) (numV 0)) | |
(test (v*s-v (interpS '(equal? (lambda x (car x)) (lambda x (car x))))) (numV 1)) | |
;boxes | |
(test (v*s-v (interpS '(equal? (!# (-# 2) 32) (!# (-# 2) 32)))) (numV 1)) | |
(test (v*s-v (interpS '(equal? (!# (-# 2) 32) (!# (-# 2) 31)))) (numV 0)) | |
;lists | |
(test (v*s-v (interpS '(equal? (cons 3 2) (cons 2 3) )) )(numV 0)) | |
(test (v*s-v (interpS '(equal? (cons 3 2) (cons 3 2) )) )(numV 1)) | |
(test (v*s-v (interpS '(call (lambda x (equal? (car x) 15)) (cons 15 16)))) (numV 1)) | |
; nested lists | |
(test (v*s-v (interpS '(equal? (cons 3 (cons 1 2)) (cons 3 (cons 1 2)))) )(numV 1)) | |
(test (v*s-v (interpS '(equal? (cons (cons 1 2) 3) (cons (cons 1 2) 3))) )(numV 1)) | |
;lazy-eval | |
(test (unbox (cell-val (first (v*s-s (interpS '(car (cons (+ 3 2) (* 333 23912932039023) )))) ))) (suspV (multC (numC 333) (numC 23912932039023)) mt-env)) | |
(test (unbox (cell-val (first (v*s-s(interpS '(let ([x (+ 3 2329382938293829329382932) ]) (+ 3 2))))))) (suspV (plusC (numC 3) (numC 2329382938293829329382932)) mt-env)) | |
;infinite lists | |
(interpS '(letrec ([l (lambda n (cons n (call l (+ 1 n))))]) (car (cdr (call l 1))))) | |
(interpS '(letrec ([mapcar (lambda fl | |
(cons ( call (car fl) (car (cdr fl))) (call mapcar (cons (car fl) (cdr (cdr fl))))))]) | |
(letrec ([nats (cons 1 (call mapcar (cons (lambda x (+ x 1)) nats)))]) | |
(car (cdr (cdr nats)))))) | |
; let | |
(test (v*s-v (interpS '(let ([x 3]) (+ 2 x)))) (numV 5)) | |
; nested let | |
(test (v*s-v (interpS '(let ([x 3]) (let ([y 4]) (+ x y))))) (numV 7)) | |
; let* | |
(test (v*s-v (interpS '(let* ([x 3] [y (+ 3 x)]) (+ y x)))) (numV 9)) | |
; letrec | |
(test (v*s-v(interpS '(letrec [(fact (lambda n (if n (* n (call fact (- n 1))) 1)))] (call fact 12)))) (numV 479001600)) | |
(test (v*s-v(interpS '(let ([x 2]) | |
(let ([y 3]) | |
(let ([foo (lambda z (+ x (+ y z)))]) | |
(let ([x 7]) | |
(letrec ([bar (lambda k (if k (* 2 (call bar (- k 1))) 1))]) | |
(call bar (call foo 4))))))) )) (numV 512) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment