Improve test-util
This commit is contained in:
parent
df520e99ca
commit
ad82c64d4d
|
|
@ -4,7 +4,7 @@
|
||||||
(require "remove-complex-oper.scm")
|
(require "remove-complex-oper.scm")
|
||||||
(require "c2.scm")
|
(require "c2.scm")
|
||||||
|
|
||||||
(define programs
|
(define programs
|
||||||
(list
|
(list
|
||||||
`(program ()
|
`(program ()
|
||||||
(- 20))
|
(- 20))
|
||||||
|
|
@ -28,9 +28,9 @@
|
||||||
(let ([y (let ([x 20])
|
(let ([y (let ([x 20])
|
||||||
(+ x (let ([x 22]) x)))]) y))))
|
(+ x (let ([x 22]) x)))]) y))))
|
||||||
|
|
||||||
(for/list ([program programs] [env (build-list (length programs) (lambda (_) '()))])
|
(for ([program programs] [env (build-list (length programs) (lambda (_) '()))])
|
||||||
(test-eq ((interp-R1 env) program)
|
(test-eq ((interp-R1 env) program)
|
||||||
((interp-R1 env) (remove-complex-opera* program))))
|
((interp-R1 env) (remove-complex-opera* program))))
|
||||||
|
|
||||||
(test-eq
|
(test-eq
|
||||||
(remove-complex-opera* (list-ref programs 0))
|
(remove-complex-opera* (list-ref programs 0))
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
|
|
||||||
(test-eq
|
(test-eq
|
||||||
(remove-complex-opera* (list-ref programs 6))
|
(remove-complex-opera* (list-ref programs 6))
|
||||||
`(program ()
|
`(program ()
|
||||||
(let ((x.1
|
(let ((x.1
|
||||||
(let ((tmp.1 (- 2)))
|
(let ((tmp.1 (- 2)))
|
||||||
(+ tmp.1 3))))
|
(+ tmp.1 3))))
|
||||||
|
|
@ -69,9 +69,9 @@
|
||||||
(test-eq
|
(test-eq
|
||||||
(remove-complex-opera* (list-ref programs 7))
|
(remove-complex-opera* (list-ref programs 7))
|
||||||
`(program ()
|
`(program ()
|
||||||
(let ((x.1
|
(let ((x.1
|
||||||
(let ((tmp.1 (- 1)))
|
(let ((tmp.1 (- 1)))
|
||||||
(+ tmp.1 2))))
|
(+ tmp.1 2))))
|
||||||
(let ((tmp.2 (+ x.1 2)))
|
(let ((tmp.2 (+ x.1 2)))
|
||||||
(let ((tmp.3 (+ 4 5)))
|
(let ((tmp.3 (+ 4 5)))
|
||||||
(+ tmp.2 tmp.3))))))
|
(+ tmp.2 tmp.3))))))
|
||||||
|
|
@ -79,7 +79,7 @@
|
||||||
(test-eq
|
(test-eq
|
||||||
(remove-complex-opera* (list-ref programs 8))
|
(remove-complex-opera* (list-ref programs 8))
|
||||||
`(program () (let([a.1 42]) (let ([b.1 a.1]) b.1))))
|
`(program () (let([a.1 42]) (let ([b.1 a.1]) b.1))))
|
||||||
|
|
||||||
(test-eq
|
(test-eq
|
||||||
(remove-complex-opera* (list-ref programs 9))
|
(remove-complex-opera* (list-ref programs 9))
|
||||||
`(program () (let ([tmp.1 (- 1)]) tmp.1)))
|
`(program () (let ([tmp.1 (- 1)]) tmp.1)))
|
||||||
|
|
@ -95,5 +95,3 @@
|
||||||
(test-eq
|
(test-eq
|
||||||
(remove-complex-opera* (list-ref programs 12))
|
(remove-complex-opera* (list-ref programs 12))
|
||||||
`(program () (let ((y.1 (let ((x.1 20)) (let ((x.2 22)) (+ x.1 x.2))))) y.1)))
|
`(program () (let ((y.1 (let ((x.1 20)) (let ((x.2 22)) (+ x.1 x.2))))) y.1)))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
(require "uniquify.scm")
|
(require "uniquify.scm")
|
||||||
(require "c2.scm")
|
(require "c2.scm")
|
||||||
|
|
||||||
(test-eq ((uniquify-exp (make-immutable-hash) (make-immutable-hash)) `(read))
|
(test-eq ((uniquify-exp (make-immutable-hash) (make-immutable-hash)) `(read))
|
||||||
`(#hash() (read)))
|
`(#hash() (read)))
|
||||||
(let ([tbl (hash-set (make-immutable-hash) `x 1)])
|
(let ([tbl (hash-set (make-immutable-hash) `x 1)])
|
||||||
(test-eq ((uniquify-exp tbl tbl) `x)
|
(test-eq ((uniquify-exp tbl tbl) `x)
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
`(#hash((x . 2)) (let ([x.2 2]) 3))))
|
`(#hash((x . 2)) (let ([x.2 2]) 3))))
|
||||||
(test-eq ((uniquify-exp (make-immutable-hash) (make-immutable-hash)) `(let ([x 2]) (+ x 3)))
|
(test-eq ((uniquify-exp (make-immutable-hash) (make-immutable-hash)) `(let ([x 2]) (+ x 3)))
|
||||||
`(#hash((x . 1)) (let ([x.1 2]) (+ x.1 3))))
|
`(#hash((x . 1)) (let ([x.1 2]) (+ x.1 3))))
|
||||||
|
|
||||||
|
|
||||||
(test-eq (uniquify
|
(test-eq (uniquify
|
||||||
`(program ()
|
`(program ()
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
`(program ()
|
`(program ()
|
||||||
(let ([x 32])
|
(let ([x 32])
|
||||||
(+ (let ([x 10]) x) (let ([x 3]) x) x))))
|
(+ (let ([x 10]) x) (let ([x 3]) x) x))))
|
||||||
`(#hash((x . 3))
|
`(#hash((x . 3))
|
||||||
(program ()
|
(program ()
|
||||||
(let ([x.1 32])
|
(let ([x.1 32])
|
||||||
(+ (let ([x.2 10]) x.2) (let ([x.3 3]) x.3) x.1)))))
|
(+ (let ([x.2 10]) x.2) (let ([x.3 3]) x.3) x.1)))))
|
||||||
|
|
@ -59,15 +59,14 @@
|
||||||
(let ([x 32])
|
(let ([x 32])
|
||||||
(+ (+ (let ([x 10]) x) (let ([x 3]) x)) x))))
|
(+ (+ (let ([x 10]) x) (let ([x 3]) x)) x))))
|
||||||
(define env1 '())
|
(define env1 '())
|
||||||
|
|
||||||
(define p2
|
(define p2
|
||||||
`(program ()
|
`(program ()
|
||||||
(let ([x (let ([y 9])
|
(let ([x (let ([y 9])
|
||||||
y)])
|
y)])
|
||||||
(+ x y))))
|
(+ x y))))
|
||||||
(define env2 '((y 5)))
|
(define env2 '((y 5)))
|
||||||
|
|
||||||
(for/list ([program (list p1 p2)] [env (list env1 env2)])
|
(for ([program (list p1 p2)] [env (list env1 env2)])
|
||||||
(test-eq ((interp-R1 env) program)
|
(test-eq ((interp-R1 env) program)
|
||||||
((interp-R1 env) (cadr (uniquify program)))))
|
((interp-R1 env) (cadr (uniquify program)))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
#lang racket
|
#lang racket
|
||||||
|
|
||||||
(provide test-eq ppexp)
|
(provide test-eq)
|
||||||
|
|
||||||
(define (test-eq a b)
|
(define (test-eq a b)
|
||||||
(if (equal? a b) #t (error "assert failed: " a " != " b)))
|
(if (equal? a b) (displayln "PASS") (error (format "FAIL: ~a != ~a" a b))))
|
||||||
|
|
||||||
(define (ppexp exp) (begin (print exp) (newline)))
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue