-
Notifications
You must be signed in to change notification settings - Fork 0
/
11-test.ss
128 lines (120 loc) · 8.92 KB
/
11-test.ss
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
(set! totalScore 0)
(define (test-all)
(if (begin (set! totalScore 0) (reset-global-env) (and
(newline) (test-boolean-string-vector-empty-list) (display "Total score: 5/60") (newline) (newline)
(test-quote) (display "Total score: 10/60") (newline) (newline)
(test-if) (display "Total score: 15/60") (newline) (newline)
(test-lambda-app) (display "Total score: 45/60") (newline) (newline)
(test-primitives) (display "Total score: 60/60") (newline) (newline)))
(begin (set! totalScore 0) (newline))))
(define (test-boolean-string-vector-empty-list)
(and
(if (not (equal? (eval-one-exp (vector 1 1 1)) '#(1 1 1)))
(begin (display "Failed boolean-string-vector-empty-list case 1: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "Set!-local score is: 1/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote #t)) '#t))
(begin (display "Failed boolean-string-vector-empty-list case 2: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "Set!-local score is: 2/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote #f)) '#f))
(begin (display "Failed boolean-string-vector-empty-list case 3: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "Set!-local score is: 3/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote (quote ()))) '()))
(begin (display "Failed boolean-string-vector-empty-list case 4: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "Set!-local score is: 4/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote "hello")) '"hello"))
(begin (display "Failed boolean-string-vector-empty-list case 5: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "boolean-string-vector-empty-list score is: 5/5") (newline) #t))
(newline)))
(define (test-quote)
(and
(if (not (equal? (eval-one-exp (quote (quote 3))) '3))
(begin (display "Failed quote case 1: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "quote score is: 1/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote (quote a))) 'a))
(begin (display "Failed quote case 2: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "quote score is: 2/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote (quote (a b c)))) '(a b c)))
(begin (display "Failed quote case 3: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 3)) (display "quote score is: 5/5") (newline) #t))
(newline)))
(define (test-if)
(and
(if (not (equal? (eval-one-exp (quote (if 5 4 3))) '4))
(begin (display "Failed if case 1: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "if score is: 1/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote (if #t 4))) '4))
(begin (display "Failed if case 2: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "if score is: 2/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote (if (if #f 4 #f) 5 6))) '6))
(begin (display "Failed if case 3: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "if score is: 4/5") (newline) #t))
(if (not (equal? (eval-one-exp (quote (if (if #t #t #f) 7 43))) '7))
(begin (display "Failed if case 4: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "if score is: 5/5") (newline) #t))
(newline)))
(define (test-lambda-app)
(and
(if (not (equal? (eval-one-exp (quote ((lambda (x) (+ 3 x)) 6))) '9))
(begin (display "Failed lambda-app case 1: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "lambda-app score is: 2/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote (((lambda (x) (lambda (y) (+ x y))) 8) 9))) '17))
(begin (display "Failed lambda-app case 2: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "lambda-app score is: 4/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote ((lambda (x) (cadr x)) (quote (1 #t 3))))) '#t))
(begin (display "Failed lambda-app case 3: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "lambda-app score is: 6/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote ((lambda (a) ((lambda (p a) (* a (p 2))) (lambda (x) (+ x a)) 5)) 3))) '25))
(begin (display "Failed lambda-app case 4: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 3)) (display "lambda-app score is: 9/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote ((lambda (x) x) (quote (1 () 3))))) '(1 () 3)))
(begin (display "Failed lambda-app case 5: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "lambda-app score is: 11/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote ((lambda (x) (list (cadr x) (car x))) '(1 3)))) '(3 1)))
(begin (display "Failed lambda-app case 6: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "lambda-app score is: 13/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote (((lambda (f) ((lambda (x) (f (lambda (y) ((x x) y)))) (lambda (x) (f (lambda (y) ((x x) y)))))) (lambda (g) (lambda (n) (if (= n 0) 1 (* n (g (- n 1))))))) 5))) '120))
(begin (display "Failed lambda-app case 7: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 4)) (display "lambda-app score is: 17/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote ((lambda x (cadr x)) 77 42 33))) '42))
(begin (display "Failed lambda-app case 8: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 5)) (display "lambda-app score is: 22/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote ((lambda (x . y) (list x (cadr y))) 77 42 33))) '(77 33)))
(begin (display "Failed lambda-app case 9: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 5)) (display "lambda-app score is: 27/30") (newline) #t))
(if (not (equal? (eval-one-exp (quote ((lambda (x y) (list x y) (list y y)) 12 14))) '(14 14)))
(begin (display "Failed lambda-app case 10: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 3)) (display "lambda-app score is: 30/30") (newline) #t))
(newline)))
(define (test-primitives)
(and
(if (not (equal? (eval-one-exp (quote (/ 4 7))) '4/7))
(begin (display "Failed primitives case 1: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "primitives score is: 1/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote (- (* 2 3) (* 6 3)))) '-12))
(begin (display "Failed primitives case 2: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "primitives score is: 2/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote (car (quote (4 5 6))))) '4))
(begin (display "Failed primitives case 3: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "primitives score is: 4/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote (cons (quote a) (quote (b c d))))) '(a b c d)))
(begin (display "Failed primitives case 4: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "primitives score is: 6/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote (if (vector? #(1)) (vector 1 1 1) duh))) '#(1 1 1)))
(begin (display "Failed primitives case 5: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "primitives score is: 7/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote (procedure? car))) '#t))
(begin (display "Failed primitives case 6: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "primitives score is: 9/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote (procedure? procedure?))) '#t))
(begin (display "Failed primitives case 7: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "primitives score is: 11/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote (procedure? 5))) '#f))
(begin (display "Failed primitives case 8: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "primitives score is: 12/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote (eq? (cons 2 3) (cons 2 3)))) '#f))
(begin (display "Failed primitives case 9: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 1)) (display "primitives score is: 13/15") (newline) #t))
(if (not (equal? (eval-one-exp (quote ((car (list car)) (quote (2 5))))) '2))
(begin (display "Failed primitives case 10: ") (display totalScore) (newline) #f)
(begin (set! totalScore (+ totalScore 2)) (display "primitives score is: 15/15") (newline) #t))
(newline)))