skeem 0.2.10 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +1 -1
- data/lib/skeem/interpreter.rb +3 -3
- data/lib/skeem/primitive/primitive_builder.rb +95 -0
- data/lib/skeem/standard/base.skm +32 -25
- data/lib/skeem/version.rb +1 -1
- data/spec/skeem/interpreter_spec.rb +92 -158
- data/spec/skeem/primitive/primitive_builder_spec.rb +134 -184
- data/spec/spec_helper.rb +24 -0
- metadata +2 -2
@@ -6,6 +6,8 @@ require_relative '../../../lib/skeem/interpreter'
|
|
6
6
|
module Skeem
|
7
7
|
module Primitive
|
8
8
|
describe 'Testing primitive procedures' do
|
9
|
+
include InterpreterSpec
|
10
|
+
|
9
11
|
subject do
|
10
12
|
# We load the interpreter with the primitive procedures only
|
11
13
|
Interpreter.new { |interp| interp.add_primitives(interp.runtime) }
|
@@ -31,55 +33,47 @@ SKEEM
|
|
31
33
|
|
32
34
|
context 'Arithmetic operators:' do
|
33
35
|
it 'should implement the addition operator' do
|
34
|
-
[
|
36
|
+
checks = [
|
35
37
|
['(+)', 0], # '+' as nullary operator. Example from section 6.2.6
|
36
38
|
['(+ -3)', -3], # '+' as unary operator
|
37
39
|
['(+ 3 4)', 7], # '+' as binary operator. Example from section 4.1.3
|
38
40
|
['(+ 1/2 2/3)', Rational(7,6)],
|
39
41
|
['(+ 1/2 3)', Rational(7,2)],
|
40
42
|
['(+ 2 2.34)', 4.34]
|
41
|
-
]
|
42
|
-
|
43
|
-
expect(result).to eq(predicted)
|
44
|
-
end
|
43
|
+
]
|
44
|
+
compare_to_predicted(checks)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should implement the minus operator' do
|
48
|
-
[
|
48
|
+
checks = [
|
49
49
|
['(- 3)', -3], # '-' as unary operator (= sign change)
|
50
50
|
['(- -2/3)', Rational(2, 3)],
|
51
51
|
['(- 3 4)', -1], # '-' as binary operator. Example from section 6.2.6
|
52
52
|
['(- 3 4 5)', -6] # '-' as variadic operator. Example from section 6.2.6
|
53
|
-
]
|
54
|
-
|
55
|
-
expect(result).to eq(predicted)
|
56
|
-
end
|
53
|
+
]
|
54
|
+
compare_to_predicted(checks)
|
57
55
|
end
|
58
56
|
|
59
57
|
it 'should implement the product operator' do
|
60
|
-
[
|
58
|
+
checks = [
|
61
59
|
['(*)', 1], # '*' as nullary operator. Example from section 6.2.6
|
62
60
|
['(* 4)', 4], # '*' as unary operator. Example from section 6.2.6
|
63
61
|
['(* 5 8)', 40], # '*' as binary operator.
|
64
62
|
['(* 2/3 5/7)', Rational(10, 21)],
|
65
63
|
['(* 2 3 4 5)', 120] # '*' as variadic operator.
|
66
|
-
]
|
67
|
-
|
68
|
-
expect(result).to eq(predicted)
|
69
|
-
end
|
64
|
+
]
|
65
|
+
compare_to_predicted(checks)
|
70
66
|
end
|
71
67
|
|
72
68
|
it 'should implement the division operator' do
|
73
|
-
[
|
69
|
+
checks = [
|
74
70
|
['(/ 3)', Rational(1, 3)], # '/' as unary operator (= inverse of argument)
|
75
71
|
['(/ 3/4)', Rational(4, 3)],
|
76
72
|
['(/ 3 4)', Rational(3, 4)], # '/' as binary operator.
|
77
73
|
['(/ 2/3 5/7)', Rational(14, 15)],
|
78
74
|
['(/ 3 4 5)', Rational(3, 20)] # '/' as variadic operator. Example from section 6.2.6
|
79
|
-
]
|
80
|
-
|
81
|
-
expect(result).to eq(predicted)
|
82
|
-
end
|
75
|
+
]
|
76
|
+
compare_to_predicted(checks)
|
83
77
|
|
84
78
|
result = subject.run('(/ 3 4.5)')
|
85
79
|
expect(result.value).to be_within(0.000001).of(0.66666667)
|
@@ -92,12 +86,11 @@ SKEEM
|
|
92
86
|
['(floor/ 5 -2)', [-3, -1]],
|
93
87
|
['(floor/ -5 -2)', [2, -1]]
|
94
88
|
]
|
95
|
-
checks
|
96
|
-
result = subject.run(skeem_expr)
|
89
|
+
compare_to_predicted(checks) do |result, expectation|
|
97
90
|
expect([result.car, result.cdr]).to eq(expectation)
|
98
91
|
end
|
99
92
|
end
|
100
|
-
|
93
|
+
|
101
94
|
it 'should implement the truncate/ procedure' do
|
102
95
|
checks = [
|
103
96
|
['(truncate/ 5 2)', [2, 1]], # Binary procedure.
|
@@ -105,11 +98,73 @@ SKEEM
|
|
105
98
|
['(truncate/ 5 -2)', [-2, 1]],
|
106
99
|
['(truncate/ -5 -2)', [2, -1]]
|
107
100
|
]
|
108
|
-
checks
|
109
|
-
result = subject.run(skeem_expr)
|
101
|
+
compare_to_predicted(checks) do |result, expectation|
|
110
102
|
expect([result.car, result.cdr]).to eq(expectation)
|
111
103
|
end
|
112
|
-
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should implement the gcd procedure' do
|
107
|
+
checks = [
|
108
|
+
['(gcd)', 0],
|
109
|
+
['(gcd 47)', 47],
|
110
|
+
['(gcd 7 11)', 1],
|
111
|
+
['(gcd 32 -36)', 4],
|
112
|
+
['(gcd 32 -36 25)', 1]
|
113
|
+
]
|
114
|
+
compare_to_predicted(checks)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should implement the lcm procedure' do
|
118
|
+
checks = [
|
119
|
+
['(lcm)', 1],
|
120
|
+
['(lcm 47)', 47],
|
121
|
+
['(lcm 7 11)', 77],
|
122
|
+
['(lcm 32 -36)', 288],
|
123
|
+
['(lcm 32 -36 10)', 1440],
|
124
|
+
['(lcm 32.0 -36)', 288]
|
125
|
+
]
|
126
|
+
compare_to_predicted(checks)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should implement the numerator procedure' do
|
130
|
+
checks = [
|
131
|
+
['(numerator (/ 6 4))', 3]
|
132
|
+
]
|
133
|
+
compare_to_predicted(checks)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should implement the denominator procedure' do
|
137
|
+
checks = [
|
138
|
+
['(denominator (/ 6 4))', 2]
|
139
|
+
]
|
140
|
+
compare_to_predicted(checks)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should implement the floor procedure' do
|
144
|
+
checks = [
|
145
|
+
['(floor -4.3)', -5],
|
146
|
+
['(floor 3.5)', 3]
|
147
|
+
]
|
148
|
+
compare_to_predicted(checks)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should implement the ceiling procedure' do
|
152
|
+
checks = [
|
153
|
+
['(ceiling -4.3)', -4],
|
154
|
+
['(ceiling 3.5)', 4]
|
155
|
+
]
|
156
|
+
compare_to_predicted(checks)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should implement the round procedure' do
|
160
|
+
checks = [
|
161
|
+
['(round -4.3)', -4],
|
162
|
+
['(round 3.5)', 4],
|
163
|
+
['(round 7/2)', 4],
|
164
|
+
['(round 7)', 7]
|
165
|
+
]
|
166
|
+
compare_to_predicted(checks)
|
167
|
+
end
|
113
168
|
end # context
|
114
169
|
|
115
170
|
context 'Comparison operators' do
|
@@ -132,8 +187,7 @@ SKEEM
|
|
132
187
|
['(define p (lambda (x) x)) (eqv? p p)', true],
|
133
188
|
["(eqv? #f 'nil)", false]
|
134
189
|
]
|
135
|
-
checks
|
136
|
-
result = subject.run(skeem_expr)
|
190
|
+
compare_to_predicted(checks) do |result, expectation|
|
137
191
|
if result.length > 1
|
138
192
|
expect(result.last).to eq(expectation)
|
139
193
|
else
|
@@ -163,8 +217,7 @@ SKEEM
|
|
163
217
|
['(equal? car cdr)', false],
|
164
218
|
['(equal? (lambda (x) x) (lambda (y) y))', false],
|
165
219
|
]
|
166
|
-
checks
|
167
|
-
result = subject.run(skeem_expr)
|
220
|
+
compare_to_predicted(checks) do |result, expectation|
|
168
221
|
if result.length > 1
|
169
222
|
expect(result.last).to eq(expectation)
|
170
223
|
else
|
@@ -182,10 +235,7 @@ SKEEM
|
|
182
235
|
['(= 3 4)', false],
|
183
236
|
['(= "foo" "bar")', false]
|
184
237
|
]
|
185
|
-
checks
|
186
|
-
result = subject.run(skeem_expr)
|
187
|
-
expect(result).to eq(expectation)
|
188
|
-
end
|
238
|
+
compare_to_predicted(checks)
|
189
239
|
end
|
190
240
|
|
191
241
|
it 'should implement the less than operator' do
|
@@ -197,10 +247,7 @@ SKEEM
|
|
197
247
|
['(< 3 2)', false],
|
198
248
|
['(< 3 4 5 4)', false]
|
199
249
|
]
|
200
|
-
checks
|
201
|
-
result = subject.run(skeem_expr)
|
202
|
-
expect(result.value).to eq(expectation)
|
203
|
-
end
|
250
|
+
compare_to_predicted(checks)
|
204
251
|
end
|
205
252
|
|
206
253
|
it 'should implement the greater than operator' do
|
@@ -212,10 +259,7 @@ SKEEM
|
|
212
259
|
['(> 3 4)', false],
|
213
260
|
['(> 3 2 1 2)', false]
|
214
261
|
]
|
215
|
-
checks
|
216
|
-
result = subject.run(skeem_expr)
|
217
|
-
expect(result).to eq(expectation)
|
218
|
-
end
|
262
|
+
compare_to_predicted(checks)
|
219
263
|
end
|
220
264
|
|
221
265
|
it 'should implement the less or equal than operator' do
|
@@ -228,10 +272,7 @@ SKEEM
|
|
228
272
|
['(<= 3 4 5 4)', false],
|
229
273
|
['(<= 3 4 5 5)', true]
|
230
274
|
]
|
231
|
-
checks
|
232
|
-
result = subject.run(skeem_expr)
|
233
|
-
expect(result).to eq(expectation)
|
234
|
-
end
|
275
|
+
compare_to_predicted(checks)
|
235
276
|
end
|
236
277
|
|
237
278
|
it 'should implement the greater or equal than operator' do
|
@@ -244,10 +285,7 @@ SKEEM
|
|
244
285
|
['(>= 3 2 1 2)', false],
|
245
286
|
['(>= 3 2 1 1)', true]
|
246
287
|
]
|
247
|
-
checks
|
248
|
-
result = subject.run(skeem_expr)
|
249
|
-
expect(result).to eq(expectation)
|
250
|
-
end
|
288
|
+
compare_to_predicted(checks)
|
251
289
|
end
|
252
290
|
|
253
291
|
it 'should implement the max procedure' do
|
@@ -256,10 +294,7 @@ SKEEM
|
|
256
294
|
['(max 3.9 4)', 4],
|
257
295
|
['(max 4 -7 2 0 -6)', 4]
|
258
296
|
]
|
259
|
-
checks
|
260
|
-
result = subject.run(skeem_expr)
|
261
|
-
expect(result).to eq(expectation)
|
262
|
-
end
|
297
|
+
compare_to_predicted(checks)
|
263
298
|
end
|
264
299
|
|
265
300
|
it 'should implement the min procedure' do
|
@@ -268,10 +303,7 @@ SKEEM
|
|
268
303
|
['(min 3.9 4)', 3.9],
|
269
304
|
['(min 4 -7 2 0 -6)', -7]
|
270
305
|
]
|
271
|
-
checks
|
272
|
-
result = subject.run(skeem_expr)
|
273
|
-
expect(result).to eq(expectation)
|
274
|
-
end
|
306
|
+
compare_to_predicted(checks)
|
275
307
|
end
|
276
308
|
end # context
|
277
309
|
|
@@ -284,10 +316,7 @@ SKEEM
|
|
284
316
|
['(number? "3")', false],
|
285
317
|
['(number? #t)', false]
|
286
318
|
]
|
287
|
-
checks
|
288
|
-
result = subject.run(skeem_expr)
|
289
|
-
expect(result).to eq(expectation)
|
290
|
-
end
|
319
|
+
compare_to_predicted(checks)
|
291
320
|
end
|
292
321
|
|
293
322
|
it 'should implement the real? predicate' do
|
@@ -298,10 +327,7 @@ SKEEM
|
|
298
327
|
['(real? "3")', false],
|
299
328
|
['(real? #t)', false]
|
300
329
|
]
|
301
|
-
checks
|
302
|
-
result = subject.run(skeem_expr)
|
303
|
-
expect(result).to eq(expectation)
|
304
|
-
end
|
330
|
+
compare_to_predicted(checks)
|
305
331
|
end
|
306
332
|
|
307
333
|
it 'should implement the rational? predicate' do
|
@@ -313,10 +339,7 @@ SKEEM
|
|
313
339
|
['(rational? "3")', false],
|
314
340
|
['(rational? #t)', false]
|
315
341
|
]
|
316
|
-
checks
|
317
|
-
result = subject.run(skeem_expr)
|
318
|
-
expect(result).to eq(expectation)
|
319
|
-
end
|
342
|
+
compare_to_predicted(checks)
|
320
343
|
end
|
321
344
|
|
322
345
|
it 'should implement the integer? predicate' do
|
@@ -328,10 +351,7 @@ SKEEM
|
|
328
351
|
['(integer? "3")', false],
|
329
352
|
['(integer? #t)', false]
|
330
353
|
]
|
331
|
-
|
332
|
-
result = subject.run(skeem_expr)
|
333
|
-
expect(result).to eq(expectation)
|
334
|
-
end
|
354
|
+
compare_to_predicted(checks)
|
335
355
|
end
|
336
356
|
|
337
357
|
it 'should implement the number->string procedure' do
|
@@ -342,10 +362,7 @@ SKEEM
|
|
342
362
|
['(number->string 1e-23)', '1.0e-23'],
|
343
363
|
['(number->string -7)', '-7']
|
344
364
|
]
|
345
|
-
checks
|
346
|
-
result = subject.run(skeem_expr)
|
347
|
-
expect(result).to eq(expectation)
|
348
|
-
end
|
365
|
+
compare_to_predicted(checks)
|
349
366
|
end
|
350
367
|
end # context
|
351
368
|
|
@@ -356,10 +373,7 @@ SKEEM
|
|
356
373
|
['(and (= 2 2) (< 2 1))', false],
|
357
374
|
['(and)', true]
|
358
375
|
]
|
359
|
-
checks
|
360
|
-
result = subject.run(skeem_expr)
|
361
|
-
expect(result).to eq(expectation)
|
362
|
-
end
|
376
|
+
compare_to_predicted(checks)
|
363
377
|
|
364
378
|
# If all the expressions evaluate to true values,
|
365
379
|
# the values of the last expression are returned.
|
@@ -381,10 +395,7 @@ SKEEM
|
|
381
395
|
['(or #f #f #f)', false],
|
382
396
|
|
383
397
|
]
|
384
|
-
checks
|
385
|
-
result = subject.run(skeem_expr)
|
386
|
-
expect(result).to eq(expectation)
|
387
|
-
end
|
398
|
+
compare_to_predicted(checks)
|
388
399
|
|
389
400
|
# When an expression evaluates to true value,
|
390
401
|
# the values of the this expression is returned.
|
@@ -400,10 +411,7 @@ SKEEM
|
|
400
411
|
['(boolean? 0)', false],
|
401
412
|
["(boolean? '())", false]
|
402
413
|
]
|
403
|
-
checks
|
404
|
-
result = subject.run(skeem_expr)
|
405
|
-
expect(result).to eq(expectation)
|
406
|
-
end
|
414
|
+
compare_to_predicted(checks)
|
407
415
|
end
|
408
416
|
end # context
|
409
417
|
|
@@ -414,10 +422,7 @@ SKEEM
|
|
414
422
|
['(string? 3)', false],
|
415
423
|
['(string? "hi")', true]
|
416
424
|
]
|
417
|
-
checks
|
418
|
-
result = subject.run(skeem_expr)
|
419
|
-
expect(result).to eq(expectation)
|
420
|
-
end
|
425
|
+
compare_to_predicted(checks)
|
421
426
|
end
|
422
427
|
|
423
428
|
it 'should implement the string->symbol procedure' do
|
@@ -436,10 +441,7 @@ SKEEM
|
|
436
441
|
['(string=? "Mom" "Mum")', false],
|
437
442
|
['(string=? "Mom" "Dad")', false]
|
438
443
|
]
|
439
|
-
checks
|
440
|
-
result = subject.run(skeem_expr)
|
441
|
-
expect(result).to eq(expectation)
|
442
|
-
end
|
444
|
+
compare_to_predicted(checks)
|
443
445
|
end
|
444
446
|
|
445
447
|
it 'should implement the string-append procedure' do
|
@@ -448,10 +450,7 @@ SKEEM
|
|
448
450
|
['(string-append "abc" "def")', 'abcdef'],
|
449
451
|
['(string-append "Hey " "you " "there!")', 'Hey you there!']
|
450
452
|
]
|
451
|
-
checks
|
452
|
-
result = subject.run(skeem_expr)
|
453
|
-
expect(result).to eq(expectation)
|
454
|
-
end
|
453
|
+
compare_to_predicted(checks)
|
455
454
|
end
|
456
455
|
|
457
456
|
it 'should implement the string-length procedure' do
|
@@ -460,10 +459,7 @@ SKEEM
|
|
460
459
|
['(string-length "")', 0],
|
461
460
|
['(string-length "hi there")', 8],
|
462
461
|
]
|
463
|
-
checks
|
464
|
-
result = subject.run(skeem_expr)
|
465
|
-
expect(result).to eq(expectation)
|
466
|
-
end
|
462
|
+
compare_to_predicted(checks)
|
467
463
|
end
|
468
464
|
end # context
|
469
465
|
|
@@ -477,10 +473,7 @@ SKEEM
|
|
477
473
|
["(symbol? '())", false],
|
478
474
|
['(symbol? #f)', false]
|
479
475
|
]
|
480
|
-
checks
|
481
|
-
result = subject.run(skeem_expr)
|
482
|
-
expect(result).to eq(expectation)
|
483
|
-
end
|
476
|
+
compare_to_predicted(checks)
|
484
477
|
end
|
485
478
|
|
486
479
|
it 'should implement the symbol->string procedure' do
|
@@ -490,10 +483,7 @@ SKEEM
|
|
490
483
|
["(equal? (symbol->string 'Martin) \"Martin\")", true],
|
491
484
|
['(equal? (symbol->string (string->symbol "Malvina")) "Malvina")', true]
|
492
485
|
]
|
493
|
-
checks
|
494
|
-
result = subject.run(skeem_expr)
|
495
|
-
expect(result).to eq(expectation)
|
496
|
-
end
|
486
|
+
compare_to_predicted(checks)
|
497
487
|
end
|
498
488
|
end # context
|
499
489
|
|
@@ -505,10 +495,7 @@ SKEEM
|
|
505
495
|
["(pair? '())", false],
|
506
496
|
["(pair? '#(a b))", false]
|
507
497
|
]
|
508
|
-
checks
|
509
|
-
result = subject.run(skeem_expr)
|
510
|
-
expect(result).to eq(expectation)
|
511
|
-
end
|
498
|
+
compare_to_predicted(checks)
|
512
499
|
end
|
513
500
|
|
514
501
|
it 'should implement the list? procedure' do
|
@@ -522,10 +509,7 @@ SKEEM
|
|
522
509
|
["(list? '(3 . 4))", false],
|
523
510
|
["(list? '())", true]
|
524
511
|
]
|
525
|
-
checks
|
526
|
-
result = subject.run(skeem_expr)
|
527
|
-
expect(result).to eq(expectation)
|
528
|
-
end
|
512
|
+
compare_to_predicted(checks)
|
529
513
|
end
|
530
514
|
|
531
515
|
it 'should implement the null? procedure' do
|
@@ -538,10 +522,7 @@ SKEEM
|
|
538
522
|
["(null? '(1 2 3))", false],
|
539
523
|
["(list? '())", true]
|
540
524
|
]
|
541
|
-
checks
|
542
|
-
result = subject.run(skeem_expr)
|
543
|
-
expect(result).to eq(expectation)
|
544
|
-
end
|
525
|
+
compare_to_predicted(checks)
|
545
526
|
end
|
546
527
|
|
547
528
|
it 'should implement the cons procedure' do
|
@@ -584,9 +565,7 @@ SKEEM
|
|
584
565
|
end
|
585
566
|
|
586
567
|
it 'should implement the car procedure' do
|
587
|
-
|
588
|
-
result = subject.run(example)
|
589
|
-
expect(result).to eq('a')
|
568
|
+
expect_expr("(car '(a b c))").to eq('a')
|
590
569
|
|
591
570
|
example = "(car '((a) b c d))" # => (a)
|
592
571
|
result = subject.run(example)
|
@@ -594,9 +573,7 @@ SKEEM
|
|
594
573
|
expect(result.length).to eq(1)
|
595
574
|
expect(result.car).to eq('a')
|
596
575
|
|
597
|
-
|
598
|
-
result = subject.run(example)
|
599
|
-
expect(result).to eq(1)
|
576
|
+
expect_expr("(car '(1 . 2))").to eq(1)
|
600
577
|
|
601
578
|
example = "(car '())" # => error
|
602
579
|
expect { subject.run(example) }.to raise_error(StandardError)
|
@@ -609,9 +586,7 @@ SKEEM
|
|
609
586
|
expect(result.length).to eq(3)
|
610
587
|
expect(result.to_a).to eq(['b', 'c', 'd'])
|
611
588
|
|
612
|
-
|
613
|
-
result = subject.run(example)
|
614
|
-
expect(result).to eq(2)
|
589
|
+
expect_expr("(cdr '(1 . 2))").to eq(2)
|
615
590
|
|
616
591
|
example = "(cdr '())" # => error
|
617
592
|
expect { subject.run(example) }.to raise_error(StandardError)
|
@@ -625,11 +600,7 @@ SKEEM
|
|
625
600
|
["(length '(1 2 3))", 3],
|
626
601
|
["(length '(a (b) (c d e)))", 3]
|
627
602
|
]
|
628
|
-
|
629
|
-
checks.each do |(skeem_expr, expectation)|
|
630
|
-
result = subject.run(skeem_expr)
|
631
|
-
expect(result).to eq(expectation)
|
632
|
-
end
|
603
|
+
compare_to_predicted(checks)
|
633
604
|
end
|
634
605
|
|
635
606
|
def array2list_ids(arr)
|
@@ -649,8 +620,7 @@ SKEEM
|
|
649
620
|
SkmPair.create_from_a(array2list_ids(['c']))]],
|
650
621
|
[ "(append '() 'a)", SkmIdentifier.create('a')]
|
651
622
|
]
|
652
|
-
checks
|
653
|
-
result = subject.run(skeem_expr)
|
623
|
+
compare_to_predicted(checks) do |result, expectation|
|
654
624
|
if result.kind_of?(SkmPair)
|
655
625
|
expect(result.to_a).to eq(expectation)
|
656
626
|
else
|
@@ -672,8 +642,7 @@ SKEEM
|
|
672
642
|
["(list->vector '())", []],
|
673
643
|
["(list->vector '(a b c))", ['a', 'b', 'c']]
|
674
644
|
]
|
675
|
-
checks
|
676
|
-
result = subject.run(skeem_expr)
|
645
|
+
compare_to_predicted(checks) do |result, expectation|
|
677
646
|
expect(result.to_a).to eq(expectation)
|
678
647
|
end
|
679
648
|
end
|
@@ -700,20 +669,19 @@ SKEEM
|
|
700
669
|
|
701
670
|
it 'should implement the assq procedure' do
|
702
671
|
subject.run("(define e '((a 1) (b 2) (c 3)))")
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
expect(result).to eq(false)
|
672
|
+
checks = [
|
673
|
+
["(assq 'a e)", ['a', 1]],
|
674
|
+
["(assq 'b e)", ['b', 2]],
|
675
|
+
["(assq 'c e)", ['c', 3]],
|
676
|
+
["(assq 'd e)", [nil]]
|
677
|
+
]
|
678
|
+
compare_to_predicted(checks) do |result, expectation|
|
679
|
+
expect(result.to_a).to eq(expectation)
|
680
|
+
end
|
681
|
+
|
682
|
+
expect_expr("(assq 'a '())").to eq(false)
|
683
|
+
expect_expr("(assq 'a '())").to eq(false)
|
684
|
+
expect_expr("(assq '(a) '(((a)) ((b)) ((c))))").to eq(false)
|
717
685
|
end
|
718
686
|
|
719
687
|
it 'should implement the assv procedure' do
|
@@ -726,8 +694,7 @@ SKEEM
|
|
726
694
|
["(list-copy '())", []],
|
727
695
|
["(list-copy '(a b c))", ['a', 'b', 'c']]
|
728
696
|
]
|
729
|
-
checks
|
730
|
-
result = subject.run(skeem_expr)
|
697
|
+
compare_to_predicted(checks) do |result, expectation|
|
731
698
|
expect(result.to_a).to eq(expectation)
|
732
699
|
end
|
733
700
|
|
@@ -753,10 +720,7 @@ SKEEM
|
|
753
720
|
["(vector? '(1 2 3))", false],
|
754
721
|
['(vector? #(1 #f "cool"))', true]
|
755
722
|
]
|
756
|
-
checks
|
757
|
-
result = subject.run(skeem_expr)
|
758
|
-
expect(result).to eq(expectation)
|
759
|
-
end
|
723
|
+
compare_to_predicted(checks)
|
760
724
|
end
|
761
725
|
|
762
726
|
it 'should implement the vector procedure' do
|
@@ -781,10 +745,7 @@ SKEEM
|
|
781
745
|
['(vector-length #(1 2))', 2],
|
782
746
|
['(vector-length (vector 1 2 3))', 3]
|
783
747
|
]
|
784
|
-
checks
|
785
|
-
result = subject.run(skeem_expr)
|
786
|
-
expect(result).to eq(expectation)
|
787
|
-
end
|
748
|
+
compare_to_predicted(checks)
|
788
749
|
end
|
789
750
|
|
790
751
|
it 'should implement the make-vector procedure' do
|
@@ -793,10 +754,7 @@ SKEEM
|
|
793
754
|
["(vector-length (make-vector 0 'a))", 0],
|
794
755
|
["(equal? (make-vector 5 'a) '#(a a a a a))", true],
|
795
756
|
]
|
796
|
-
checks
|
797
|
-
result = subject.run(skeem_expr)
|
798
|
-
expect(result).to eq(expectation)
|
799
|
-
end
|
757
|
+
compare_to_predicted(checks)
|
800
758
|
end
|
801
759
|
|
802
760
|
it 'should implement the vector-ref procedure' do
|
@@ -811,8 +769,7 @@ SKEEM
|
|
811
769
|
["(vector->list #())", []],
|
812
770
|
["(vector->list '#(a b c))", ['a', 'b', 'c']]
|
813
771
|
]
|
814
|
-
checks
|
815
|
-
result = subject.run(skeem_expr)
|
772
|
+
compare_to_predicted(checks) do |result, expectation|
|
816
773
|
expect(result.to_a).to eq(expectation)
|
817
774
|
end
|
818
775
|
end
|
@@ -826,20 +783,14 @@ SKEEM
|
|
826
783
|
["(procedure? (lambda (x) (* x x)))", true],
|
827
784
|
# ["(procedure? '(lambda (x) (* x x)))", false] # Parse fail: non-standard syntax
|
828
785
|
]
|
829
|
-
checks
|
830
|
-
result = subject.run(skeem_expr)
|
831
|
-
expect(result).to eq(expectation)
|
832
|
-
end
|
786
|
+
compare_to_predicted(checks)
|
833
787
|
end
|
834
788
|
|
835
789
|
it 'should implement the apply procedure' do
|
836
790
|
checks = [
|
837
791
|
["(apply + '(3 4))", 7]
|
838
792
|
]
|
839
|
-
checks
|
840
|
-
result = subject.run(skeem_expr)
|
841
|
-
expect(result).to eq(expectation)
|
842
|
-
end
|
793
|
+
compare_to_predicted(checks)
|
843
794
|
end
|
844
795
|
|
845
796
|
it 'should implement the map procedure' do
|
@@ -847,8 +798,7 @@ SKEEM
|
|
847
798
|
["(map car '((a b) (d e) (g h)))", ['a', 'd', 'g']],
|
848
799
|
["(map + '(1 2 3) '(4 5 6 7))", [5, 7, 9]]
|
849
800
|
]
|
850
|
-
checks
|
851
|
-
result = subject.run(skeem_expr)
|
801
|
+
compare_to_predicted(checks) do |result, expectation|
|
852
802
|
expect(result.to_a).to eq(expectation)
|
853
803
|
end
|
854
804
|
end
|