-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathtests-1.9.1-req.scm
101 lines (97 loc) · 3.12 KB
/
tests-1.9.1-req.scm
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
(add-tests-with-string-output "cons"
[(fxadd1 0) => "1\n"]
[(pair? (cons 1 2)) => "#t\n"]
[(pair? 12) => "#f\n"]
[(pair? #t) => "#f\n"]
[(pair? #f) => "#f\n"]
[(pair? ()) => "#f\n"]
[(fixnum? (cons 12 43)) => "#f\n"]
[(boolean? (cons 12 43)) => "#f\n"]
[(null? (cons 12 43)) => "#f\n"]
[(not (cons 12 43)) => "#f\n"]
[(if (cons 12 43) 32 43) => "32\n"]
[(car (cons 1 23)) => "1\n"]
[(cdr (cons 43 123)) => "123\n"]
[(let ((x (cons 1 2)) (y (cons 3 4))) (pair? x)) => "#t\n"]
[(pair? (cons (cons 12 3) #f)) => "#t\n"]
[(pair? (cons (cons 12 3) (cons #t #f))) => "#t\n"]
[(car (car (cons (cons 12 3) (cons #t #f)))) => "12\n"]
[(cdr (car (cons (cons 12 3) (cons #t #f)))) => "3\n"]
[(car (cdr (cons (cons 12 3) (cons #t #f)))) => "#t\n"]
[(cdr (cdr (cons (cons 12 3) (cons #t #f)))) => "#f\n"]
[(pair? (cons (fx* 1 1) 1)) => "#t\n"]
[(let ([x (let ([y (fx+ 1 2)]) (fx* y y))])
(cons x (fx+ x x)))
=> "(9 . 18)\n"]
[(let ([t0 (cons 1 2)] [t1 (cons 3 4)])
(let ([a0 (car t0)] [a1 (car t1)] [d0 (cdr t0)] [d1 (cdr t1)])
(let ([t0 (cons a0 d1)] [t1 (cons a1 d0)])
(cons t0 t1))))
=> "((1 . 4) 3 . 2)\n"]
[(let ([t (cons 1 2)])
(let ([t t])
(let ([t t])
(let ([t t])
t))))
=> "(1 . 2)\n"]
[(let ([t (let ([t (let ([t (let ([t (cons 1 2)]) t)]) t)]) t)]) t)
=> "(1 . 2)\n"]
[(let ([x ()])
(let ([x (cons x x)])
(let ([x (cons x x)])
(let ([x (cons x x)])
(cons x x)))))
=> "((((()) ()) (()) ()) ((()) ()) (()) ())\n"]
[(cons (let ([x #t]) (let ([y (cons x x)]) (cons x y)))
(cons (let ([x #f]) (let ([y (cons x x)]) (cons y x)))
()))
=> "((#t #t . #t) ((#f . #f) . #f))\n"]
)
(add-tests-with-string-output "begin/implicit-begin"
[(begin 12) => "12\n"]
[(begin 13 122) => "122\n"]
[(begin 123 2343 #t) => "#t\n"]
[(let ([t (begin 12 (cons 1 2))]) (begin t t)) => "(1 . 2)\n"]
[(let ([t (begin 13 (cons 1 2))])
(cons 1 t)
t) => "(1 . 2)\n"]
[(let ([t (cons 1 2)])
(if (pair? t)
(begin t)
12)) => "(1 . 2)\n"]
)
(add-tests-with-string-output "set-car! set-cdr!"
[(let ([x (cons 1 2)])
(begin (set-cdr! x ())
x)) => "(1)\n"]
[(let ([x (cons 1 2)])
(set-cdr! x ())
x) => "(1)\n"]
[(let ([x (cons 12 13)] [y (cons 14 15)])
(set-cdr! x y)
x) => "(12 14 . 15)\n"]
[(let ([x (cons 12 13)] [y (cons 14 15)])
(set-cdr! y x)
y) => "(14 12 . 13)\n"]
[(let ([x (cons 12 13)] [y (cons 14 15)])
(set-cdr! y x)
x) => "(12 . 13)\n"]
[(let ([x (cons 12 13)] [y (cons 14 15)])
(set-cdr! x y)
y) => "(14 . 15)\n"]
[(let ([x (let ([x (cons 1 2)]) (set-car! x #t) (set-cdr! x #f) x)])
(cons x x)
x) => "(#t . #f)\n"]
[(let ([x (cons 1 2)])
(set-cdr! x x)
(set-car! (cdr x) x)
(cons (eq? x (car x)) (eq? x (cdr x)))) => "(#t . #t)\n"]
[(let ([x #f])
(if (pair? x)
(set-car! x 12)
#f)
x) => "#f\n"]
)
(add-tests-with-string-output "more cons"
[(letrec ([f (lambda (i lst) (if (fx= i 0) lst (f (fxsub1 i) (cons i lst))))])
(f 10 ())) => "(1 2 3 4 5 6 7 8 9 10)\n"])