Move more tests to rackunit
This commit is contained in:
parent
cadcd25dbd
commit
0aeb312f14
|
|
@ -1,7 +1,8 @@
|
|||
#lang racket
|
||||
|
||||
(require rackunit)
|
||||
(provide remove-complex-opera-tests)
|
||||
|
||||
(require rackunit)
|
||||
(require "test-util.rkt")
|
||||
(require "uniquify.rkt")
|
||||
(require "remove-complex-oper.rkt")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#lang racket
|
||||
|
||||
(provide test-uniquify-tests)
|
||||
|
||||
(require rackunit)
|
||||
|
||||
(require "test-util.rkt")
|
||||
(require "rvar.rkt")
|
||||
(require "uniquify.rkt")
|
||||
(require/expose "uniquify.rkt" (uniquify-exp))
|
||||
|
|
@ -12,56 +13,6 @@
|
|||
(lambda (exp)
|
||||
(call-with-values (lambda () ((uniquify-exp symtable symtable) exp)) list)))
|
||||
|
||||
(test-eq ((list-uniquify-exp (make-immutable-hash)) (Prim 'read (list)))
|
||||
(list #hash() (Prim 'read '())))
|
||||
|
||||
(let ([tbl (hash-set (make-immutable-hash) 'x 1)])
|
||||
(test-eq ((list-uniquify-exp tbl) (Var 'x))
|
||||
(list #hash((x . 1)) (Var 'x.1))))
|
||||
|
||||
(test-eq ((list-uniquify-exp (make-immutable-hash)) (Let 'x (Int 2) (Int 3)))
|
||||
(list #hash((x . 1)) (Let 'x.1 (Int 2) (Int 3))))
|
||||
|
||||
(test-eq ((list-uniquify-exp (make-immutable-hash)) (Let 'x (Int 2) (Prim '+ (list (Var 'x) (Int 3)))))
|
||||
(list #hash((x . 1)) (Let 'x.1 (Int 2) (Prim '+ (list (Var 'x.1) (Int 3))))))
|
||||
|
||||
(test-eq (uniquify
|
||||
(Program '()
|
||||
(Let 'x (Int 32)
|
||||
(Prim '+ (list (Let 'x (Int 10) (Var 'x)) (Var 'x))))))
|
||||
(Program '()
|
||||
(Let 'x.1 (Int 32)
|
||||
(Prim '+ (list (Let 'x.2 (Int 10) (Var 'x.2)) (Var 'x.1))))))
|
||||
|
||||
(test-eq (uniquify
|
||||
(Program '()
|
||||
(Let 'x (Int 32)
|
||||
(Prim '- (list (Var 'x))))))
|
||||
(Program '()
|
||||
(Let 'x.1 (Int 32)
|
||||
(Prim '- (list (Var 'x.1))))))
|
||||
|
||||
|
||||
(test-eq (uniquify
|
||||
(Program '()
|
||||
(Let 'x (Int 32)
|
||||
(Prim '+ (list (Let 'x (Int 10) (Var 'x))
|
||||
(Let 'x (Int 3) (Var 'x))
|
||||
(Var 'x))))))
|
||||
(Program '()
|
||||
(Let 'x.1 (Int 32)
|
||||
(Prim '+ (list (Let 'x.2 (Int 10) (Var 'x.2))
|
||||
(Let 'x.3 (Int 3) (Var 'x.3))
|
||||
(Var 'x.1))))))
|
||||
(test-eq (uniquify
|
||||
(Program '()
|
||||
(Let 'x (Let 'x (Int 4)
|
||||
(Prim '+ (list (Var 'x) (Int 1))))
|
||||
(Prim '+ (list (Var 'x) (Int 2))))))
|
||||
(Program '()
|
||||
(Let 'x.1 (Let 'x.2 (Int 4)
|
||||
(Prim '+ (list (Var 'x.2) (Int 1))))
|
||||
(Prim '+ (list (Var 'x.1) (Int 2))))))
|
||||
|
||||
(define p1
|
||||
(Program '()
|
||||
|
|
@ -75,6 +26,69 @@
|
|||
(Var 'y))
|
||||
(Prim '+ (list (Var 'x) (Int 5))))))
|
||||
|
||||
(for ([program (list p1 p2)])
|
||||
(test-eq (interp-RVar program)
|
||||
(interp-RVar (uniquify program))))
|
||||
(define test-uniquify-tests
|
||||
(test-suite
|
||||
"Uniquify pass testsuite"
|
||||
(test-case
|
||||
"uniquify-exp correctness"
|
||||
(let ([tbl (hash-set (make-immutable-hash) 'x 1)])
|
||||
(check-equal? ((list-uniquify-exp tbl) (Var 'x))
|
||||
(list #hash((x . 1)) (Var 'x.1))))
|
||||
|
||||
(check-equal? ((list-uniquify-exp (make-immutable-hash)) (Prim 'read (list)))
|
||||
(list #hash() (Prim 'read '())))
|
||||
|
||||
(check-equal? ((list-uniquify-exp (make-immutable-hash)) (Let 'x (Int 2) (Int 3)))
|
||||
(list #hash((x . 1)) (Let 'x.1 (Int 2) (Int 3))))
|
||||
|
||||
(check-equal? ((list-uniquify-exp (make-immutable-hash)) (Let 'x (Int 2) (Prim '+ (list (Var 'x) (Int 3)))))
|
||||
(list #hash((x . 1)) (Let 'x.1 (Int 2) (Prim '+ (list (Var 'x.1) (Int 3)))))))
|
||||
(test-case
|
||||
"uniqufication pass"
|
||||
(check-equal?
|
||||
(uniquify
|
||||
(Program '()
|
||||
(Let 'x (Int 32)
|
||||
(Prim '+ (list (Let 'x (Int 10) (Var 'x)) (Var 'x))))))
|
||||
(Program '()
|
||||
(Let 'x.1 (Int 32)
|
||||
(Prim '+ (list (Let 'x.2 (Int 10) (Var 'x.2)) (Var 'x.1))))))
|
||||
|
||||
(check-equal?
|
||||
(uniquify
|
||||
(Program '()
|
||||
(Let 'x (Int 32)
|
||||
(Prim '- (list (Var 'x))))))
|
||||
(Program '()
|
||||
(Let 'x.1 (Int 32)
|
||||
(Prim '- (list (Var 'x.1))))))
|
||||
|
||||
|
||||
(check-equal?
|
||||
(uniquify
|
||||
(Program '()
|
||||
(Let 'x (Int 32)
|
||||
(Prim '+ (list (Let 'x (Int 10) (Var 'x))
|
||||
(Let 'x (Int 3) (Var 'x))
|
||||
(Var 'x))))))
|
||||
(Program '()
|
||||
(Let 'x.1 (Int 32)
|
||||
(Prim '+ (list (Let 'x.2 (Int 10) (Var 'x.2))
|
||||
(Let 'x.3 (Int 3) (Var 'x.3))
|
||||
(Var 'x.1))))))
|
||||
(check-equal?
|
||||
(uniquify
|
||||
(Program '()
|
||||
(Let 'x (Let 'x (Int 4)
|
||||
(Prim '+ (list (Var 'x) (Int 1))))
|
||||
(Prim '+ (list (Var 'x) (Int 2))))))
|
||||
(Program '()
|
||||
(Let 'x.1 (Let 'x.2 (Int 4)
|
||||
(Prim '+ (list (Var 'x.2) (Int 1))))
|
||||
(Prim '+ (list (Var 'x.1) (Int 2)))))))
|
||||
|
||||
(test-case
|
||||
"Uniquify interpretation"
|
||||
(for ([program (list p1 p2)])
|
||||
(check-equal? (interp-RVar program)
|
||||
(interp-RVar (uniquify program)))))))
|
||||
|
|
|
|||
Loading…
Reference in New Issue