-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw5test.rkt
74 lines (53 loc) · 2.75 KB
/
hw5test.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#lang racket
;; Programming Languages Homework 5 Simple Test
;; Save this file to the same directory as your homework file
;; These are basic tests. Passing these tests does not guarantee that your code will pass the actual homework grader
;; Be sure to put your homework file in the same folder as this test file.
;; Uncomment the line below and, if necessary, change the filename
;;(require "hw5")
(require rackunit)
(require "hw5.rkt")
(define tests
(test-suite
"Sample tests for Assignment 5"
;; check racketlist to mupllist with normal list
(check-equal? (racketlist->mupllist (list (int 3) (int 4))) (apair (int 3) (apair (int 4) (aunit))) "racketlist->mupllist test")
;; check mupllist to racketlist with normal list
(check-equal? (mupllist->racketlist (apair (int 3) (apair (int 4) (aunit)))) (list (int 3) (int 4)) "racketlist->mupllist test")
;; tests if ifgreater returns (int 2)
(check-equal? (eval-exp (ifgreater (int 3) (int 4) (int 3) (int 2))) (int 2) "ifgreater test")
;; mlet test
(check-equal? (eval-exp (mlet "x" (int 1) (add (int 5) (var "x")))) (int 6) "mlet test")
;; call test
(check-equal? (eval-exp (call (closure '() (fun #f "x" (add (var "x") (int 7)))) (int 1))) (int 8) "call test")
;;snd test
(check-equal? (eval-exp (snd (apair (int 1) (int 2)))) (int 2) "snd test")
;; isaunit test
(check-equal? (eval-exp (isaunit (closure '() (fun #f "x" (aunit))))) (int 0) "isaunit test")
;; ifaunit test
(check-equal? (eval-exp (ifaunit (int 1) (int 2) (int 3))) (int 3) "ifaunit test")
;; mlet* test
(check-equal? (eval-exp (mlet* (list (cons "x" (int 10))) (var "x"))) (int 10) "mlet* test")
;; ifeq test
(check-equal? (eval-exp (ifeq (int 1) (int 2) (int 3) (int 4))) (int 4) "ifeq test")
;; mupl-map test
(check-equal? (eval-exp (call (call mupl-map (fun #f "x" (add (var "x") (int 7)))) (apair (int 1) (aunit))))
(apair (int 8) (aunit)) "mupl-map test")
;; problems 1, 2, and 4 combined test
(check-equal? (mupllist->racketlist
(eval-exp (call (call mupl-mapAddN (int 7))
(racketlist->mupllist
(list (int 3) (int 4) (int 9)))))) (list (int 10) (int 11) (int 16)) "combined test")
(check-equal? (eval-exp (call
(fun "fib" "x"
(ifgreater (int 2) (var "x")
(var "x")
(add
(call (var "fib") (add (var "x") (int -1)))
(call (var "fib") (add (var "x") (int -2))))))
(int 10)))
(int 55) "test fib")
))
(require rackunit/text-ui)
;; runs the test
(run-tests tests)