This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
050list2.test
334 lines (250 loc) · 7.54 KB
/
050list2.test
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
(test "len works on lists"
:valueof (len '(1 2 3 4 5))
:should be 5)
(test "lists coerce to function"
:valueof (type+coerce '(1 2 3) function)
:should be 'function)
(test "lists work in function position"
:valueof ((list 1 2 3) 1)
:should be 2)
(test "lists in function position don't leak memory"
:valueof (withs (l '(1 2 3)
n0 nrefs.l)
l.1 # do the lookup
(- nrefs.l n0))
:should be 0)
(test "lists work in function position - 2"
:valueof (let l '(list 1 2 3) l.3)
:should be 3)
(test "compose works with lists"
:valueof (let l '(1 (34 3) 2) (car+l 1))
:should be 34)
(test "lists can take negative indices"
:valueof (let l '(1 2 3) (l -1))
:should be 3)
(test "lists can take slices"
:valueof (let l '(1 2 3 4 5 6) (l 3 5))
:should be '(4 5))
(test "lists can take slices - 2"
:valueof (let l '(1 2 3 4 5 6) (l 3 -1))
:should be '(4 5))
(test "lists can take slices - explicit nil"
:valueof (let l '(1 2 3 4 5 6) (l 3 nil))
:should be '(4 5 6))
(test "lists can take slices - overflow"
:valueof (let l '(1 2 3 4 5 6) (l 3 10))
:should be '(4 5 6))
(test "lists can be assigned to"
:valueof (ret l '(1 2 3)
(l.1 <- 4))
:should be '(1 4 3))
(test "list assignment returns assigned value"
:valueof (let l '(1 2 3)
(l.1 <- 4))
:should be 4)
(test "list slices can be assigned to"
:valueof (ret l '(1 2 3 4 5 6 7)
((l 1 3) <- '(16 17 18)))
:should be '(1 16 17 18 4 5 6 7))
(test "list slice assignment returns assigned value"
:valueof (let l '(1 2 3 4 5 6 7)
((l 1 3) <- '(16 17 18)))
:should be '(16 17 18))
(test "list slice assignment returns single assigned value"
:valueof (let l '(1 2 3 4 5 6 7)
((l 1 3) <- '(16)))
:should be '(16))
(test "list slices can be assigned to - 2"
:valueof (ret l '(1 2 3 4 5 6 7)
((l -4 -1) <- '(29 37)))
:should be '(1 2 3 29 37 7))
(test "list slices can be assigned to - explicit nil"
:valueof (ret l '(1 2 3 4 5 6 7)
((l -4 nil) <- '(29 37)))
:should be '(1 2 3 29 37))
(test "list slices can be assigned to - explicit nil var"
:valueof (ret l '(1 2 3 4 5 6 7)
(let x nil
((l -4 x) <- '(29 37))))
:should be '(1 2 3 29 37))
(test "list index can be reset"
:valueof (ret l '(1 2 3)
(l.1 <- nil))
:should be '(1 nil 3))
(test "list slices can be deleted"
:valueof (ret l '(1 2 3 4 5 6 7)
((l 1 5) <- nil))
:should be '(1 6 7))
(test "list slices can be deleted - 2"
:valueof (ret l '(1 2 3 4 5 6 7)
((l -4 -1) <- nil))
:should be '(1 2 3 7))
(test "list slice assignment can delete at start of list (by rebinding the var)"
:valueof (ret l '(1 2 3 4)
((l 0 2) <- nil))
:should be '(3 4))
(test "nested lists can be assigned to"
:valueof (ret l '(1 (2 3))
(((l 1) 0) <- 3))
:should be '(1 (3 3)))
(test "elems of other types can be assigned to"
:valueof (let l (tag 'footype '(1 2 3))
(rep.l.0 <- 3)
rep.l)
:should be '(3 2 3))
(test "lists compare lexicographically"
:valueof (< '(1 2 3) '(1 2 4))
:should be_true)
(test "lists compare lexicographically - 2"
:valueof (< '(1 2 4) '(1 2 3))
:should be_false)
(test "shorter list compares with prefix"
:valueof (< '(1 2 4) '(1 2 3 4))
:should be_false)
(test "shorter list compares with prefix - 2"
:valueof (< '(1 2 2) '(1 2 3 4))
:should be_true)
(test "equal prefixes sort by length"
:valueof (< '(1 2 3) '(1 2 3 4))
:should be_true)
(test "equal prefixes sort by length - 2"
:valueof (< '(1 2 3 4) '(1 2 3))
:should be_false)
(test "overloading < also fixes >"
:valueof (> '(1 2 4) '(1 2 3))
:should be_true)
(test "overloading < also fixes > - 2"
:valueof (> '(1 2 4) nil)
:should be_true)
(test "overloading < also fixes > - 3"
:valueof (> '(1 2 3) '(1 2 4))
:should be_false)
(test "overloading < also fixes > - 4"
:valueof (> nil '(1 2 4))
:should be_false)
(test "comparing lists to ranges works"
:valueof (list.1 < list.2 < list.3)
:should be_true)
(test "comparing lists to ranges works - 2"
:valueof (list.1 < list.3 < list.2)
:should be_false)
(test "comparing lists returns latter arg on success"
:valueof ('(1 2 3) < '(1 2 4))
:should be '(1 2 4))
(test "pos works"
:valueof (pos 2 '(1 2 3))
:should be_true)
(test "pos works - 2"
:valueof (pos 4 '(1 2 3))
:should be_false)
(test "pos works - 3"
:valueof (pos nil '(1 2 3))
:should be_false)
(test "pos works - 4"
:valueof (pos nil '(1 nil 2 3))
:should be_true)
(test "rpos works"
:valueof (rpos 3 '(0 1 2 3))
:should be 3)
(test "rpos works - 2"
:valueof (rpos 3 '(0 1 2))
:should be_false)
(test "predicate works with a list"
:valueof ((predicate '(1 2 3)) 3)
:should be_true)
(test "predicate works with a list - 2"
:valueof ((predicate '(1 2 3)) 4)
:should be_false)
(test "single? - 1"
:valueof (single? nil)
:should be_false)
(test "single? - 2"
:valueof (single? '(1))
:should be_true)
(test "single? - 3"
:valueof (single? '(1 2))
:should be_false)
(test "single? - 4"
:valueof (single? '(1 ... 2))
:should be_false)
(test "pair? - 1"
:valueof (pair? nil)
:should be_false)
(test "pair? - 2"
:valueof (pair? '(1))
:should be_false)
(test "pair? - 3"
:valueof (pair? '(1 2))
:should be_true)
(test "pair? - 4"
:valueof (pair? '(1 ... 2))
:should be_false)
(test "pair? - 5"
:valueof (pair? '(1 2 3))
:should be_false)
(test "zip works"
:valueof (zip '(1 2) '(3 4 5))
:should be '((1 3) (2 4)))
(test "zipmax works"
:valueof (zipmax '(1 2) '(3 4 5))
:should be '((1 3) (2 4) (nil 5)))
(test "zip works with more than two args"
:valueof (zip '(1 2 3) '(4 5 6) '(7 8 9))
:should be '((1 4 7) (2 5 8) (3 6 9)))
(test "flatten works"
:valueof (flatten '(a b (c d e)))
:should be '(a b c d e))
(test "flatten works - 2"
:valueof (flatten '(a b (c d e) ... f))
:should be '(a b c d e f))
(test "join works"
:valueof (join '(1 2 3) nil '(4 5) nil nil '(6 (7 8)))
:should be '(1 2 3 4 5 6 (7 8)))
(test "+ works on lists"
:valueof (+ '(1 2 3) nil '(4 5) nil nil '(6 (7 8)))
:should be '(1 2 3 4 5 6 (7 8)))
(test "keep works"
:valueof (keep num? '(11 a 13))
:should be '(11 13))
(test "keep does not convert to predicate"
:valueof (keep '(0 1 2 nil 4) '(2 1 3 4))
:should be '(2 1 4))
(test "rem works"
:valueof (rem no '(1 2 nil 4 nil))
:should be '(1 2 4))
(test "rem converts to predicate"
:valueof (rem nil '(1 2 nil 4 nil))
:should be '(1 2 4))
(test "skip nil works"
:valueof (skip nil '(1 2 nil 4))
:should be '(1 2 4))
(test "all works with lists"
:valueof (all list? '((1) 2))
:should be_false)
(test "all does not convert to predicate"
:valueof (all (list nil 1 nil 1) '(1 3))
:should be_true)
(test "some works"
:valueof (some num? '(2 a "b"))
:should be_true)
(test "some works - 2"
:valueof (some num? '(a "b"))
:should be_false)
(test "some does not convert to predicate"
:valueof (some (list nil 1 nil nil) '(1 3))
:should be_true)
(test "some does not convert to predicate - 2"
:valueof (some (list nil 1 nil nil) '(1 2 3))
:should be_true)
(test "none works"
:valueof (none num? '(2 a "b"))
:should be_false)
(test "none works - 2"
:valueof (none num? '(a "b"))
:should be_true)
(test "map works with multiary functions"
:valueof (map list '(1 2 3) '(2 4 6) '(3 6 9))
:should be '((1 2 3) (2 4 6) (3 6 9)))
(test "intersperse works"
:valueof (intersperse 3 '(a b c d))
:should be '(a 3 b 3 c 3 d))