porolog 1.0.2 → 1.0.3
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/README.md +22 -13
- data/coverage/index.html +4564 -4552
- data/doc/Array.html +9 -9
- data/doc/Object.html +1 -1
- data/doc/Porolog.html +77 -67
- data/doc/Symbol.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +22 -14
- data/doc/index.html +22 -14
- data/doc/top-level-namespace.html +1 -1
- data/lib/porolog.rb +4 -2
- data/lib/porolog/core_ext.rb +8 -8
- data/lib/porolog/goal.rb +2 -2
- data/lib/porolog/predicate/builtin.rb +34 -34
- data/lib/porolog/rule.rb +1 -1
- data/lib/porolog/variable.rb +7 -7
- data/test/porolog/arguments_test.rb +73 -73
- data/test/porolog/core_ext_test.rb +39 -39
- data/test/porolog/goal_test.rb +72 -72
- data/test/porolog/instantiation_test.rb +153 -153
- data/test/porolog/porolog_test.rb +272 -270
- data/test/porolog/predicate/builtin_test.rb +166 -166
- data/test/porolog/predicate_test.rb +85 -85
- data/test/porolog/rule_test.rb +69 -69
- data/test/porolog/scope_test.rb +89 -89
- data/test/porolog/tail_test.rb +23 -23
- data/test/porolog/value_test.rb +32 -34
- data/test/porolog/variable_test.rb +120 -120
- data/test/samples_test.rb +11 -11
- data/test/test_helper.rb +56 -61
- metadata +2 -2
@@ -21,7 +21,7 @@ describe 'Porolog' do
|
|
21
21
|
|
22
22
|
it 'should output an atom' do
|
23
23
|
assert_output 'hello' do
|
24
|
-
builtin :write
|
24
|
+
Porolog::builtin :write
|
25
25
|
|
26
26
|
assert_solutions write('hello'), [{}]
|
27
27
|
end
|
@@ -29,7 +29,7 @@ describe 'Porolog' do
|
|
29
29
|
|
30
30
|
it 'should output an integer' do
|
31
31
|
assert_output '456' do
|
32
|
-
builtin :write
|
32
|
+
Porolog::builtin :write
|
33
33
|
|
34
34
|
assert_solutions write(456), [{}]
|
35
35
|
end
|
@@ -37,7 +37,7 @@ describe 'Porolog' do
|
|
37
37
|
|
38
38
|
it 'should output an uninstantiated variable' do
|
39
39
|
assert_output ':X' do
|
40
|
-
builtin :write
|
40
|
+
Porolog::builtin :write
|
41
41
|
|
42
42
|
assert_solutions write(:X), [{ X: nil }]
|
43
43
|
end
|
@@ -45,8 +45,8 @@ describe 'Porolog' do
|
|
45
45
|
|
46
46
|
it 'should output an instantiated variable' do
|
47
47
|
assert_output '72' do
|
48
|
-
builtin :write, :is
|
49
|
-
predicate :inst
|
48
|
+
Porolog::builtin :write, :is
|
49
|
+
Porolog::predicate :inst
|
50
50
|
|
51
51
|
inst(:X, :Y) << [
|
52
52
|
is(:Y, :X) {|x| x + 4 },
|
@@ -63,7 +63,7 @@ describe 'Porolog' do
|
|
63
63
|
|
64
64
|
it 'should output an atom and a new line' do
|
65
65
|
assert_output "hello\n" do
|
66
|
-
builtin :writenl
|
66
|
+
Porolog::builtin :writenl
|
67
67
|
|
68
68
|
assert_solutions writenl('hello'), [{}]
|
69
69
|
end
|
@@ -71,7 +71,7 @@ describe 'Porolog' do
|
|
71
71
|
|
72
72
|
it 'should output an integer and a new line' do
|
73
73
|
assert_output "456\n" do
|
74
|
-
builtin :writenl
|
74
|
+
Porolog::builtin :writenl
|
75
75
|
|
76
76
|
assert_solutions writenl(456), [{}]
|
77
77
|
end
|
@@ -79,7 +79,7 @@ describe 'Porolog' do
|
|
79
79
|
|
80
80
|
it 'should output an uninstantiated variable and a new line' do
|
81
81
|
assert_output ":X\n" do
|
82
|
-
builtin :writenl
|
82
|
+
Porolog::builtin :writenl
|
83
83
|
|
84
84
|
assert_solutions writenl(:X), [{ X: nil }]
|
85
85
|
end
|
@@ -87,8 +87,8 @@ describe 'Porolog' do
|
|
87
87
|
|
88
88
|
it 'should output an instantiated variable and a new line' do
|
89
89
|
assert_output "72\n" do
|
90
|
-
builtin :writenl, :is
|
91
|
-
predicate :inst
|
90
|
+
Porolog::builtin :writenl, :is
|
91
|
+
Porolog::predicate :inst
|
92
92
|
|
93
93
|
inst(:X, :Y) << [
|
94
94
|
is(:Y, :X) {|x| x + 4 },
|
@@ -105,8 +105,8 @@ describe 'Porolog' do
|
|
105
105
|
|
106
106
|
it 'should output a newline' do
|
107
107
|
assert_output "\n\n\n" do
|
108
|
-
builtin :nl
|
109
|
-
predicate :f, :n
|
108
|
+
Porolog::builtin :nl
|
109
|
+
Porolog::predicate :f, :n
|
110
110
|
|
111
111
|
n(1).fact!
|
112
112
|
n(5).fact!
|
@@ -130,8 +130,8 @@ describe 'Porolog' do
|
|
130
130
|
describe '#is' do
|
131
131
|
|
132
132
|
it 'should raise an exception when not provided with a variable' do
|
133
|
-
builtin :is
|
134
|
-
predicate :is_test
|
133
|
+
Porolog::builtin :is
|
134
|
+
Porolog::predicate :is_test
|
135
135
|
|
136
136
|
is_test(:variable) << [
|
137
137
|
# :nocov:
|
@@ -139,14 +139,14 @@ describe 'Porolog' do
|
|
139
139
|
# :nocov:
|
140
140
|
]
|
141
141
|
|
142
|
-
assert_raises NonVariableError do
|
142
|
+
assert_raises Porolog::NonVariableError do
|
143
143
|
assert_solutions is_test(6), [{}]
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'should not raise an exception when provided with an instantiated variable' do
|
148
|
-
builtin :is
|
149
|
-
predicate :is_test
|
148
|
+
Porolog::builtin :is
|
149
|
+
Porolog::predicate :is_test
|
150
150
|
|
151
151
|
is_test(:variable) << [
|
152
152
|
is(:variable) { 6 }
|
@@ -156,8 +156,8 @@ describe 'Porolog' do
|
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'should call the block provided and instantiate the variable to the result of the provided block' do
|
159
|
-
builtin :is
|
160
|
-
predicate :is_test
|
159
|
+
Porolog::builtin :is
|
160
|
+
Porolog::predicate :is_test
|
161
161
|
|
162
162
|
calls = []
|
163
163
|
|
@@ -180,8 +180,8 @@ describe 'Porolog' do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'should return false when the variable cannot be instantiated' do
|
183
|
-
builtin :is
|
184
|
-
predicate :is_test
|
183
|
+
Porolog::builtin :is
|
184
|
+
Porolog::predicate :is_test
|
185
185
|
|
186
186
|
calls = []
|
187
187
|
|
@@ -209,32 +209,32 @@ describe 'Porolog' do
|
|
209
209
|
describe '#eq' do
|
210
210
|
|
211
211
|
it 'should return no solutions when given unequal values' do
|
212
|
-
builtin :eq
|
212
|
+
Porolog::builtin :eq
|
213
213
|
|
214
214
|
assert_solutions eq([3,2,1,4], [1,2,3,4]), []
|
215
215
|
end
|
216
216
|
|
217
217
|
it 'should return a solution when given equal values' do
|
218
|
-
builtin :eq
|
218
|
+
Porolog::builtin :eq
|
219
219
|
|
220
220
|
assert_solutions eq([1,2,3,4], [1,2,3,4]), [{}]
|
221
221
|
end
|
222
222
|
|
223
223
|
it 'should return a solution with an unbound variable when given the same unbound variable' do
|
224
|
-
builtin :eq
|
224
|
+
Porolog::builtin :eq
|
225
225
|
|
226
226
|
assert_solutions eq(:X, :X), [{ X: nil}]
|
227
227
|
end
|
228
228
|
|
229
229
|
it 'should return no solutions when given two unbound variables' do
|
230
|
-
builtin :eq
|
230
|
+
Porolog::builtin :eq
|
231
231
|
|
232
232
|
assert_solutions eq(:X, :Y), []
|
233
233
|
end
|
234
234
|
|
235
235
|
it 'should return one solution with unbound variables when given given two uninstantiated variables that are bound to each other' do
|
236
|
-
builtin :eq, :is
|
237
|
-
predicate :bind_and_eq
|
236
|
+
Porolog::builtin :eq, :is
|
237
|
+
Porolog::predicate :bind_and_eq
|
238
238
|
|
239
239
|
bind_and_eq(:X, :Y) << [
|
240
240
|
is(:X, :Y) { |y| y },
|
@@ -245,8 +245,8 @@ describe 'Porolog' do
|
|
245
245
|
end
|
246
246
|
|
247
247
|
it 'should return no solutions when given two uninstantiated variables that are not bound to each other' do
|
248
|
-
builtin :eq, :is
|
249
|
-
predicate :bind_and_eq
|
248
|
+
Porolog::builtin :eq, :is
|
249
|
+
Porolog::predicate :bind_and_eq
|
250
250
|
|
251
251
|
bind_and_eq(:X, :Y) << [
|
252
252
|
is(:X, :P) { |p| p },
|
@@ -258,7 +258,7 @@ describe 'Porolog' do
|
|
258
258
|
end
|
259
259
|
|
260
260
|
it 'should return no solutions when given a value and an uninstantiated variable' do
|
261
|
-
builtin :eq
|
261
|
+
Porolog::builtin :eq
|
262
262
|
|
263
263
|
assert_solutions eq([1,2,3,4], :L), []
|
264
264
|
assert_solutions eq(:L, [1,2,3,4]), []
|
@@ -269,32 +269,32 @@ describe 'Porolog' do
|
|
269
269
|
describe '#is_eq' do
|
270
270
|
|
271
271
|
it 'should return no solutions when given unequal values' do
|
272
|
-
builtin :is_eq
|
272
|
+
Porolog::builtin :is_eq
|
273
273
|
|
274
274
|
assert_solutions is_eq([3,2,1,4], [1,2,3,4]), []
|
275
275
|
end
|
276
276
|
|
277
277
|
it 'should return a solution when given equal values' do
|
278
|
-
builtin :is_eq
|
278
|
+
Porolog::builtin :is_eq
|
279
279
|
|
280
280
|
assert_solutions is_eq([1,2,3,4], [1,2,3,4]), []
|
281
281
|
end
|
282
282
|
|
283
283
|
it 'should return a solution with an unbound variable when given the same unbound variable' do
|
284
|
-
builtin :is_eq
|
284
|
+
Porolog::builtin :is_eq
|
285
285
|
|
286
286
|
assert_solutions is_eq(:X, :X), [{ X: nil}]
|
287
287
|
end
|
288
288
|
|
289
289
|
it 'should return no solutions when given given two unbound variables' do
|
290
|
-
builtin :is_eq
|
290
|
+
Porolog::builtin :is_eq
|
291
291
|
|
292
292
|
assert_solutions is_eq(:X, :Y), [{ X: nil, Y: nil }]
|
293
293
|
end
|
294
294
|
|
295
295
|
it 'should return one solution with unbound variables when given given two uninstantiated variables that are bound to each other' do
|
296
|
-
builtin :is_eq, :is
|
297
|
-
predicate :bind_and_eq
|
296
|
+
Porolog::builtin :is_eq, :is
|
297
|
+
Porolog::predicate :bind_and_eq
|
298
298
|
|
299
299
|
bind_and_eq(:X, :Y) << [
|
300
300
|
is(:X, :Y) { |y| y },
|
@@ -305,8 +305,8 @@ describe 'Porolog' do
|
|
305
305
|
end
|
306
306
|
|
307
307
|
it 'should return no solutions when given given two uninstantiated variables that are not bound to each other' do
|
308
|
-
builtin :is_eq, :is
|
309
|
-
predicate :bind_and_eq
|
308
|
+
Porolog::builtin :is_eq, :is
|
309
|
+
Porolog::predicate :bind_and_eq
|
310
310
|
|
311
311
|
bind_and_eq(:X, :Y) << [
|
312
312
|
is(:X, :P) { |p| p },
|
@@ -318,13 +318,13 @@ describe 'Porolog' do
|
|
318
318
|
end
|
319
319
|
|
320
320
|
it 'should not instantiate the right hand side when not given a left hand side variable' do
|
321
|
-
builtin :is_eq
|
321
|
+
Porolog::builtin :is_eq
|
322
322
|
|
323
323
|
assert_solutions is_eq([1,2,3,4], :L), []
|
324
324
|
end
|
325
325
|
|
326
326
|
it 'should instantiate the left hand side variable' do
|
327
|
-
builtin :is_eq
|
327
|
+
Porolog::builtin :is_eq
|
328
328
|
|
329
329
|
assert_solutions is_eq(:L, [1,2,3,4]), [{ L: [1,2,3,4] }]
|
330
330
|
end
|
@@ -334,8 +334,8 @@ describe 'Porolog' do
|
|
334
334
|
describe '#ruby' do
|
335
335
|
|
336
336
|
it 'should execute ruby code' do
|
337
|
-
builtin :ruby
|
338
|
-
predicate :logic, :data
|
337
|
+
Porolog::builtin :ruby
|
338
|
+
Porolog::predicate :logic, :data
|
339
339
|
|
340
340
|
data(1).fact!
|
341
341
|
data(5).fact!
|
@@ -363,8 +363,8 @@ describe 'Porolog' do
|
|
363
363
|
end
|
364
364
|
|
365
365
|
it 'should execute ruby code which triggers a failure' do
|
366
|
-
builtin :ruby
|
367
|
-
predicate :logic, :data
|
366
|
+
Porolog::builtin :ruby
|
367
|
+
Porolog::predicate :logic, :data
|
368
368
|
|
369
369
|
data(1).fact!
|
370
370
|
data(5).fact!
|
@@ -394,32 +394,32 @@ describe 'Porolog' do
|
|
394
394
|
describe '#noteq' do
|
395
395
|
|
396
396
|
it 'should return a solution when given unequal values' do
|
397
|
-
builtin :noteq
|
397
|
+
Porolog::builtin :noteq
|
398
398
|
|
399
399
|
assert_solutions noteq([3,2,1,4], [1,2,3,4]), [{}]
|
400
400
|
end
|
401
401
|
|
402
402
|
it 'should return no solutions when given equal values' do
|
403
|
-
builtin :noteq
|
403
|
+
Porolog::builtin :noteq
|
404
404
|
|
405
405
|
assert_solutions noteq([1,2,3,4], [1,2,3,4]), []
|
406
406
|
end
|
407
407
|
|
408
408
|
it 'should return no solutions with an unbound variable when given the same unbound variable' do
|
409
|
-
builtin :noteq
|
409
|
+
Porolog::builtin :noteq
|
410
410
|
|
411
411
|
assert_solutions noteq(:X, :X), []
|
412
412
|
end
|
413
413
|
|
414
414
|
it 'should return a solution when given two unbound variables' do
|
415
|
-
builtin :noteq
|
415
|
+
Porolog::builtin :noteq
|
416
416
|
|
417
417
|
assert_solutions noteq(:X, :Y), [{ X: nil, Y: nil }]
|
418
418
|
end
|
419
419
|
|
420
420
|
it 'should return no solutions with unbound variables when given given two uninstantiated variables that are bound to each other' do
|
421
|
-
builtin :noteq, :is
|
422
|
-
predicate :bind_and_noteq
|
421
|
+
Porolog::builtin :noteq, :is
|
422
|
+
Porolog::predicate :bind_and_noteq
|
423
423
|
|
424
424
|
bind_and_noteq(:X, :Y) << [
|
425
425
|
is(:X, :Y) { |y| y },
|
@@ -430,8 +430,8 @@ describe 'Porolog' do
|
|
430
430
|
end
|
431
431
|
|
432
432
|
it 'should return a solution when given two uninstantiated variables that are not bound to each other' do
|
433
|
-
builtin :noteq, :is
|
434
|
-
predicate :bind_and_noteq
|
433
|
+
Porolog::builtin :noteq, :is
|
434
|
+
Porolog::predicate :bind_and_noteq
|
435
435
|
|
436
436
|
bind_and_noteq(:X, :Y) << [
|
437
437
|
is(:X, :P) { |p| p },
|
@@ -443,7 +443,7 @@ describe 'Porolog' do
|
|
443
443
|
end
|
444
444
|
|
445
445
|
it 'should return a solution when given an unbound variable' do
|
446
|
-
builtin :noteq
|
446
|
+
Porolog::builtin :noteq
|
447
447
|
|
448
448
|
assert_solutions noteq([1,2,3,4], :L), [{ L: nil }]
|
449
449
|
assert_solutions noteq(:L, [1,2,3,4]), [{ L: nil }]
|
@@ -454,7 +454,7 @@ describe 'Porolog' do
|
|
454
454
|
describe '#is_noteq' do
|
455
455
|
|
456
456
|
it 'should return solutions without the exclusions' do
|
457
|
-
builtin :is_noteq
|
457
|
+
Porolog::builtin :is_noteq
|
458
458
|
|
459
459
|
assert_solutions is_noteq(:X, [1,2,3,4,5], 2, 5), [
|
460
460
|
{ X: 1, _a: [1,3,4] },
|
@@ -464,13 +464,13 @@ describe 'Porolog' do
|
|
464
464
|
end
|
465
465
|
|
466
466
|
it 'should return no solutions when the exclusions are not unique' do
|
467
|
-
builtin :is_noteq
|
467
|
+
Porolog::builtin :is_noteq
|
468
468
|
|
469
469
|
assert_solutions is_noteq(:X, [1,2,3,4,5], 2, 5, 2), []
|
470
470
|
end
|
471
471
|
|
472
472
|
it 'should return no solutions when the target is not a variable' do
|
473
|
-
builtin :is_noteq
|
473
|
+
Porolog::builtin :is_noteq
|
474
474
|
|
475
475
|
assert_solutions is_noteq(7, [1,2,3,4,5], 2, 5, 2), []
|
476
476
|
end
|
@@ -480,7 +480,7 @@ describe 'Porolog' do
|
|
480
480
|
describe '#less' do
|
481
481
|
|
482
482
|
it 'should return no solutions when given a greater value' do
|
483
|
-
builtin :less
|
483
|
+
Porolog::builtin :less
|
484
484
|
|
485
485
|
assert_solutions less(7, 4), []
|
486
486
|
assert_solutions less('h', 'b'), []
|
@@ -488,7 +488,7 @@ describe 'Porolog' do
|
|
488
488
|
end
|
489
489
|
|
490
490
|
it 'should return no solutions when given equal values' do
|
491
|
-
builtin :less
|
491
|
+
Porolog::builtin :less
|
492
492
|
|
493
493
|
assert_solutions less(4, 4), []
|
494
494
|
assert_solutions less('b', 'b'), []
|
@@ -496,19 +496,19 @@ describe 'Porolog' do
|
|
496
496
|
end
|
497
497
|
|
498
498
|
it 'should return a solution when given lesser values' do
|
499
|
-
builtin :less
|
499
|
+
Porolog::builtin :less
|
500
500
|
|
501
501
|
assert_solutions less(2, 4), [{}]
|
502
502
|
end
|
503
503
|
|
504
504
|
it 'should return no solutions with an unbound variable when given the same unbound variable' do
|
505
|
-
builtin :less
|
505
|
+
Porolog::builtin :less
|
506
506
|
|
507
507
|
assert_solutions less(:X, :X), []
|
508
508
|
end
|
509
509
|
|
510
510
|
it 'should return no solutions when given two unbound variables' do
|
511
|
-
builtin :less
|
511
|
+
Porolog::builtin :less
|
512
512
|
|
513
513
|
assert_solutions less(:X, :Y), []
|
514
514
|
end
|
@@ -518,7 +518,7 @@ describe 'Porolog' do
|
|
518
518
|
describe '#gtr' do
|
519
519
|
|
520
520
|
it 'should return no solutions when given a lesser value' do
|
521
|
-
builtin :gtr
|
521
|
+
Porolog::builtin :gtr
|
522
522
|
|
523
523
|
assert_solutions gtr(4, 7), []
|
524
524
|
assert_solutions gtr('b', 'h'), []
|
@@ -526,7 +526,7 @@ describe 'Porolog' do
|
|
526
526
|
end
|
527
527
|
|
528
528
|
it 'should return no solutions when given equal values' do
|
529
|
-
builtin :gtr
|
529
|
+
Porolog::builtin :gtr
|
530
530
|
|
531
531
|
assert_solutions gtr(4, 4), []
|
532
532
|
assert_solutions gtr('b', 'b'), []
|
@@ -534,19 +534,19 @@ describe 'Porolog' do
|
|
534
534
|
end
|
535
535
|
|
536
536
|
it 'should return a solution when given greater values' do
|
537
|
-
builtin :gtr
|
537
|
+
Porolog::builtin :gtr
|
538
538
|
|
539
539
|
assert_solutions gtr(4, 2), [{}]
|
540
540
|
end
|
541
541
|
|
542
542
|
it 'should return no solutions with an unbound variable when given the same unbound variable' do
|
543
|
-
builtin :gtr
|
543
|
+
Porolog::builtin :gtr
|
544
544
|
|
545
545
|
assert_solutions gtr(:X, :X), []
|
546
546
|
end
|
547
547
|
|
548
548
|
it 'should return no solutions when given two unbound variables' do
|
549
|
-
builtin :gtr
|
549
|
+
Porolog::builtin :gtr
|
550
550
|
|
551
551
|
assert_solutions gtr(:X, :Y), []
|
552
552
|
end
|
@@ -556,7 +556,7 @@ describe 'Porolog' do
|
|
556
556
|
describe '#lesseq' do
|
557
557
|
|
558
558
|
it 'should return no solutions when given a greater value' do
|
559
|
-
builtin :lesseq
|
559
|
+
Porolog::builtin :lesseq
|
560
560
|
|
561
561
|
assert_solutions lesseq(7, 4), []
|
562
562
|
assert_solutions lesseq('h', 'b'), []
|
@@ -564,7 +564,7 @@ describe 'Porolog' do
|
|
564
564
|
end
|
565
565
|
|
566
566
|
it 'should return a solution when given equal values' do
|
567
|
-
builtin :lesseq
|
567
|
+
Porolog::builtin :lesseq
|
568
568
|
|
569
569
|
assert_solutions lesseq(4, 4), [{}]
|
570
570
|
assert_solutions lesseq('b', 'b'), [{}]
|
@@ -572,7 +572,7 @@ describe 'Porolog' do
|
|
572
572
|
end
|
573
573
|
|
574
574
|
it 'should return a solution when given lesser values' do
|
575
|
-
builtin :lesseq
|
575
|
+
Porolog::builtin :lesseq
|
576
576
|
|
577
577
|
assert_solutions lesseq(2, 4), [{}]
|
578
578
|
assert_solutions lesseq('b', 'h'), [{}]
|
@@ -580,19 +580,19 @@ describe 'Porolog' do
|
|
580
580
|
end
|
581
581
|
|
582
582
|
it 'should return a solution with an unbound variable when given the same unbound variable' do
|
583
|
-
builtin :lesseq
|
583
|
+
Porolog::builtin :lesseq
|
584
584
|
|
585
585
|
assert_solutions lesseq(:X, :X), [{ X: nil }]
|
586
586
|
end
|
587
587
|
|
588
588
|
it 'should return no solutions when given two unbound variables' do
|
589
|
-
builtin :lesseq
|
589
|
+
Porolog::builtin :lesseq
|
590
590
|
|
591
591
|
assert_solutions lesseq(:X, :Y), []
|
592
592
|
end
|
593
593
|
|
594
594
|
it 'should return no solutions when given one unbound variable' do
|
595
|
-
builtin :lesseq
|
595
|
+
Porolog::builtin :lesseq
|
596
596
|
|
597
597
|
assert_solutions lesseq(:X, 11), []
|
598
598
|
end
|
@@ -602,7 +602,7 @@ describe 'Porolog' do
|
|
602
602
|
describe '#gtreq' do
|
603
603
|
|
604
604
|
it 'should return no solutions when given a lesser value' do
|
605
|
-
builtin :gtreq
|
605
|
+
Porolog::builtin :gtreq
|
606
606
|
|
607
607
|
assert_solutions gtreq(4, 7), []
|
608
608
|
assert_solutions gtreq('b', 'h'), []
|
@@ -610,7 +610,7 @@ describe 'Porolog' do
|
|
610
610
|
end
|
611
611
|
|
612
612
|
it 'should return a solution when given equal values' do
|
613
|
-
builtin :gtreq
|
613
|
+
Porolog::builtin :gtreq
|
614
614
|
|
615
615
|
assert_solutions gtreq(4, 4), [{}]
|
616
616
|
assert_solutions gtreq('b', 'b'), [{}]
|
@@ -618,7 +618,7 @@ describe 'Porolog' do
|
|
618
618
|
end
|
619
619
|
|
620
620
|
it 'should return a solution when given gtreqer values' do
|
621
|
-
builtin :gtreq
|
621
|
+
Porolog::builtin :gtreq
|
622
622
|
|
623
623
|
assert_solutions gtreq(4, 2), [{}]
|
624
624
|
assert_solutions gtreq('h', 'b'), [{}]
|
@@ -626,19 +626,19 @@ describe 'Porolog' do
|
|
626
626
|
end
|
627
627
|
|
628
628
|
it 'should return a solution with an unbound variable when given the same unbound variable' do
|
629
|
-
builtin :gtreq
|
629
|
+
Porolog::builtin :gtreq
|
630
630
|
|
631
631
|
assert_solutions gtreq(:X, :X), [{ X: nil }]
|
632
632
|
end
|
633
633
|
|
634
634
|
it 'should return no solutions when given two unbound variables' do
|
635
|
-
builtin :gtreq
|
635
|
+
Porolog::builtin :gtreq
|
636
636
|
|
637
637
|
assert_solutions gtreq(:X, :Y), []
|
638
638
|
end
|
639
639
|
|
640
640
|
it 'should return no solutions when given one unbound variable' do
|
641
|
-
builtin :gtreq
|
641
|
+
Porolog::builtin :gtreq
|
642
642
|
|
643
643
|
assert_solutions gtreq(:X, 11), []
|
644
644
|
end
|
@@ -648,25 +648,25 @@ describe 'Porolog' do
|
|
648
648
|
describe '#length' do
|
649
649
|
|
650
650
|
it 'should return a solution for an array and an integer' do
|
651
|
-
builtin :length
|
651
|
+
Porolog::builtin :length
|
652
652
|
|
653
653
|
assert_solutions length([1,2,3,4,5], 5), [{}]
|
654
654
|
end
|
655
655
|
|
656
656
|
it 'should return no solutions for an array and an integer that do not satisy the length' do
|
657
|
-
builtin :length
|
657
|
+
Porolog::builtin :length
|
658
658
|
|
659
659
|
assert_solutions length([1,2,3,4,5], 2), []
|
660
660
|
end
|
661
661
|
|
662
662
|
it 'should instaniate the length of the list' do
|
663
|
-
builtin :length
|
663
|
+
Porolog::builtin :length
|
664
664
|
|
665
665
|
assert_solutions length([1,2,3,4,5], :N), [{ N: 5 }]
|
666
666
|
end
|
667
667
|
|
668
668
|
it 'should instaniate the list' do
|
669
|
-
builtin :length
|
669
|
+
Porolog::builtin :length
|
670
670
|
|
671
671
|
assert_solutions length(:L, 4), [
|
672
672
|
{ L: [nil, nil, nil, nil], _a: nil, _b: nil, _c: nil, _d: nil }
|
@@ -674,13 +674,13 @@ describe 'Porolog' do
|
|
674
674
|
end
|
675
675
|
|
676
676
|
it 'should return no solutions for a variable array and length' do
|
677
|
-
builtin :length
|
677
|
+
Porolog::builtin :length
|
678
678
|
|
679
679
|
assert_solutions length(:L, :N), []
|
680
680
|
end
|
681
681
|
|
682
682
|
it 'should return no solutions for invalid types' do
|
683
|
-
builtin :length
|
683
|
+
Porolog::builtin :length
|
684
684
|
|
685
685
|
assert_solutions length(3, [1,2,3]), []
|
686
686
|
end
|
@@ -690,26 +690,26 @@ describe 'Porolog' do
|
|
690
690
|
describe '#between' do
|
691
691
|
|
692
692
|
it 'should return a solution when the value is in range' do
|
693
|
-
builtin :between
|
693
|
+
Porolog::builtin :between
|
694
694
|
|
695
695
|
assert_solutions between(3, 1, 10), [{}]
|
696
696
|
end
|
697
697
|
|
698
698
|
it 'should return no solutions when the value is not in range' do
|
699
|
-
builtin :between
|
699
|
+
Porolog::builtin :between
|
700
700
|
|
701
701
|
assert_solutions between(-40, 1, 10), []
|
702
702
|
end
|
703
703
|
|
704
704
|
it 'should return no solutions when given an uninstantiated variable for the range' do
|
705
|
-
builtin :between
|
705
|
+
Porolog::builtin :between
|
706
706
|
|
707
707
|
assert_solutions between(:X, 1, :Ten), []
|
708
708
|
assert_solutions between(:X, :One, 10), []
|
709
709
|
end
|
710
710
|
|
711
711
|
it 'should return solutions for instantiating' do
|
712
|
-
builtin :between
|
712
|
+
Porolog::builtin :between
|
713
713
|
|
714
714
|
assert_solutions between(:X, 1, 10), [
|
715
715
|
{ X: 1 },
|
@@ -726,31 +726,31 @@ describe 'Porolog' do
|
|
726
726
|
end
|
727
727
|
|
728
728
|
it 'should instantiate the minimum possible when the value is above the lower bound' do
|
729
|
-
builtin :between
|
729
|
+
Porolog::builtin :between
|
730
730
|
|
731
731
|
assert_solutions between(4, 1, :upper), [{ upper: 4}]
|
732
732
|
end
|
733
733
|
|
734
734
|
it 'should instantiate the maximum possible when the value is below the upper bound' do
|
735
|
-
builtin :between
|
735
|
+
Porolog::builtin :between
|
736
736
|
|
737
737
|
assert_solutions between(4, :lower, 10), [{ lower: 4}]
|
738
738
|
end
|
739
739
|
|
740
740
|
it 'should return no solutions the value is below the lower bound' do
|
741
|
-
builtin :between
|
741
|
+
Porolog::builtin :between
|
742
742
|
|
743
743
|
assert_solutions between(-7, 1, :upper), []
|
744
744
|
end
|
745
745
|
|
746
746
|
it 'should return no solutions the value is above the upper bound' do
|
747
|
-
builtin :between
|
747
|
+
Porolog::builtin :between
|
748
748
|
|
749
749
|
assert_solutions between(24, :lower, 10), []
|
750
750
|
end
|
751
751
|
|
752
752
|
it 'should instantiate both bounds when given a value' do
|
753
|
-
builtin :between
|
753
|
+
Porolog::builtin :between
|
754
754
|
|
755
755
|
assert_solutions between(24, :lower, :upper), [{ lower: 24, upper: 24 }]
|
756
756
|
end
|
@@ -760,55 +760,55 @@ describe 'Porolog' do
|
|
760
760
|
describe '#member' do
|
761
761
|
|
762
762
|
it 'should return no solutions for a non-member' do
|
763
|
-
builtin :member
|
763
|
+
Porolog::builtin :member
|
764
764
|
|
765
765
|
assert_solutions member(5, [1,2,3,4]), []
|
766
766
|
end
|
767
767
|
|
768
768
|
it 'should return no solutions for a non-list' do
|
769
|
-
builtin :member
|
769
|
+
Porolog::builtin :member
|
770
770
|
|
771
771
|
assert_solutions member(5, 5), []
|
772
772
|
end
|
773
773
|
|
774
774
|
it 'should return a solution for a member' do
|
775
|
-
builtin :member
|
775
|
+
Porolog::builtin :member
|
776
776
|
|
777
777
|
assert_solutions member(3, [1,2,3,4]), [{}]
|
778
778
|
end
|
779
779
|
|
780
780
|
it 'should return a solution for an array member' do
|
781
|
-
builtin :member
|
781
|
+
Porolog::builtin :member
|
782
782
|
|
783
783
|
assert_solutions member([2,3], [[1,2],[2,3],[3,4]]), [{}]
|
784
784
|
end
|
785
785
|
|
786
786
|
it 'should return a solution for a member' do
|
787
|
-
builtin :member
|
787
|
+
Porolog::builtin :member
|
788
788
|
|
789
789
|
assert_solutions member(3, [1,2,3,4]), [{}]
|
790
790
|
end
|
791
791
|
|
792
792
|
it 'should return a solution for a member' do
|
793
|
-
builtin :member
|
793
|
+
Porolog::builtin :member
|
794
794
|
|
795
795
|
assert_solutions member(3, [1,2,:C,4]), [{ C: 3 }]
|
796
796
|
end
|
797
797
|
|
798
798
|
it 'should return a solution for an array member' do
|
799
|
-
builtin :member
|
799
|
+
Porolog::builtin :member
|
800
800
|
|
801
801
|
assert_solutions member([:A,3], [[1,2],[2,3],[3,4]]), [{ A: 2 }]
|
802
802
|
end
|
803
803
|
|
804
804
|
it 'should return a solution for an array member' do
|
805
|
-
builtin :member
|
805
|
+
Porolog::builtin :member
|
806
806
|
|
807
807
|
assert_solutions member([2,3], [[1,:B],[:B,3],[3,4]]), [{ B: 2 }]
|
808
808
|
end
|
809
809
|
|
810
810
|
it 'should return solutions for each member' do
|
811
|
-
builtin :member
|
811
|
+
Porolog::builtin :member
|
812
812
|
|
813
813
|
assert_solutions member(:M, [[1,2],[2,3],[3,4]]), [
|
814
814
|
{ M: [1,2] },
|
@@ -818,11 +818,11 @@ describe 'Porolog' do
|
|
818
818
|
end
|
819
819
|
|
820
820
|
it 'should return limited solutions for variables' do
|
821
|
-
builtin :member
|
821
|
+
Porolog::builtin :member
|
822
822
|
|
823
823
|
assert_solutions member(:M, :L, 12), Array.new(12){|i|
|
824
824
|
v = '_a'
|
825
|
-
{ M: nil, L: [*([nil] * (i+1)), UNKNOWN_TAIL] }.merge((1..(i * (i + 1) / 2)).map{ m = v.dup ; v.succ! ; [m.to_sym, nil] }.to_h)
|
825
|
+
{ M: nil, L: [*([nil] * (i+1)), Porolog::UNKNOWN_TAIL] }.merge((1..(i * (i + 1) / 2)).map{ m = v.dup ; v.succ! ; [m.to_sym, nil] }.to_h)
|
826
826
|
}
|
827
827
|
end
|
828
828
|
|
@@ -831,37 +831,37 @@ describe 'Porolog' do
|
|
831
831
|
describe '#append' do
|
832
832
|
|
833
833
|
it 'should return no solutions for a non-append' do
|
834
|
-
builtin :append
|
834
|
+
Porolog::builtin :append
|
835
835
|
|
836
836
|
assert_solutions append([1,2,3], [4,5,6], [1,2,7,4,5,6]), []
|
837
837
|
end
|
838
838
|
|
839
839
|
it 'should return a solution for a valid append' do
|
840
|
-
builtin :append
|
840
|
+
Porolog::builtin :append
|
841
841
|
|
842
842
|
assert_solutions append([1,2,3], [4,5,6], [1,2,3,4,5,6]), [{}]
|
843
843
|
end
|
844
844
|
|
845
845
|
it 'should return no solutions for a non-list' do
|
846
|
-
builtin :append
|
846
|
+
Porolog::builtin :append
|
847
847
|
|
848
848
|
assert_solutions append(5, 5, 55), []
|
849
849
|
end
|
850
850
|
|
851
851
|
it 'should return a solution for a valid append' do
|
852
|
-
builtin :append
|
852
|
+
Porolog::builtin :append
|
853
853
|
|
854
854
|
assert_solutions append([1,2,3], [4,5,6], [1,2,3,4,5,6]), [{}]
|
855
855
|
end
|
856
856
|
|
857
857
|
it 'should return a solution for an array append' do
|
858
|
-
builtin :append
|
858
|
+
Porolog::builtin :append
|
859
859
|
|
860
860
|
assert_solutions append([[1,2],[2,3],[3,4]], [[4,5],[5,6],[6,7]], [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]), [{}]
|
861
861
|
end
|
862
862
|
|
863
863
|
it 'should instantiate prefix variable' do
|
864
|
-
builtin :append
|
864
|
+
Porolog::builtin :append
|
865
865
|
|
866
866
|
assert_solutions append(:prefix, [[4,5],[5,6],[6,7]], [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]), [
|
867
867
|
{ prefix: [[1, 2], [2, 3], [3, 4]] }
|
@@ -869,7 +869,7 @@ describe 'Porolog' do
|
|
869
869
|
end
|
870
870
|
|
871
871
|
it 'should instantiate suffix variable' do
|
872
|
-
builtin :append
|
872
|
+
Porolog::builtin :append
|
873
873
|
|
874
874
|
assert_solutions append([[1,2],[2,3],[3,4]], :suffix, [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]), [
|
875
875
|
{ suffix: [[4, 5], [5, 6], [6, 7]] }
|
@@ -877,7 +877,7 @@ describe 'Porolog' do
|
|
877
877
|
end
|
878
878
|
|
879
879
|
it 'should instantiate embedded variables' do
|
880
|
-
builtin :append
|
880
|
+
Porolog::builtin :append
|
881
881
|
|
882
882
|
assert_solutions append([[:A,:B],[:C,:D],[:E,:F]], [:G,:H,:I], [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]), [
|
883
883
|
{ A: 1, B: 2, C: 2, D: 3, E: 3, F: 4, G: [4, 5], H: [5, 6], I: [6, 7] }
|
@@ -885,7 +885,7 @@ describe 'Porolog' do
|
|
885
885
|
end
|
886
886
|
|
887
887
|
it 'should instantiate embedded variables' do
|
888
|
-
builtin :append
|
888
|
+
Porolog::builtin :append
|
889
889
|
|
890
890
|
assert_solutions append([1,2,3,4], ['apple','banana','carrot'], :L), [
|
891
891
|
{ L: [1, 2, 3, 4, 'apple', 'banana', 'carrot'] }
|
@@ -893,7 +893,7 @@ describe 'Porolog' do
|
|
893
893
|
end
|
894
894
|
|
895
895
|
it 'should return solutions for all possible splits of a list' do
|
896
|
-
builtin :append
|
896
|
+
Porolog::builtin :append
|
897
897
|
|
898
898
|
assert_solutions append(:M, :L, [1,2,3,4,5]), [
|
899
899
|
{ M: [], L: [1, 2, 3, 4, 5] },
|
@@ -906,8 +906,8 @@ describe 'Porolog' do
|
|
906
906
|
end
|
907
907
|
|
908
908
|
it 'should instantiate using a head and tail for an unbound variable and an array' do
|
909
|
-
builtin :append, :is_eq
|
910
|
-
predicate :append_is_eq
|
909
|
+
Porolog::builtin :append, :is_eq
|
910
|
+
Porolog::predicate :append_is_eq
|
911
911
|
|
912
912
|
append_is_eq(:A, :B, :C) << [
|
913
913
|
append(:A, :B, :C),
|
@@ -920,8 +920,8 @@ describe 'Porolog' do
|
|
920
920
|
end
|
921
921
|
|
922
922
|
it 'should instantiate using a head and tail for unbound variables' do
|
923
|
-
builtin :append, :is_eq
|
924
|
-
predicate :append_is_eq
|
923
|
+
Porolog::builtin :append, :is_eq
|
924
|
+
Porolog::predicate :append_is_eq
|
925
925
|
|
926
926
|
append_is_eq(:A, :B, :C) << [
|
927
927
|
append(:A, :B, :C),
|
@@ -934,8 +934,8 @@ describe 'Porolog' do
|
|
934
934
|
end
|
935
935
|
|
936
936
|
it 'should instantiate using a head and tail for unbound variables' do
|
937
|
-
builtin :append, :is_eq
|
938
|
-
predicate :append_is_eq
|
937
|
+
Porolog::builtin :append, :is_eq
|
938
|
+
Porolog::predicate :append_is_eq
|
939
939
|
|
940
940
|
append_is_eq(:A, :B, :C) << [
|
941
941
|
append(:A, :B, :C),
|
@@ -953,31 +953,31 @@ describe 'Porolog' do
|
|
953
953
|
describe '#permutation' do
|
954
954
|
|
955
955
|
it 'returns no solutions for non-arrays' do
|
956
|
-
builtin :permutation
|
956
|
+
Porolog::builtin :permutation
|
957
957
|
|
958
958
|
assert_solutions permutation('1234', '1234'), []
|
959
959
|
end
|
960
960
|
|
961
961
|
it 'returns a solution for identical arrays without variables' do
|
962
|
-
builtin :permutation
|
962
|
+
Porolog::builtin :permutation
|
963
963
|
|
964
964
|
assert_solutions permutation([1,2,3,4], [1,2,3,4]), [{}]
|
965
965
|
end
|
966
966
|
|
967
967
|
it 'returns a solutions for rearranged arrays without variables' do
|
968
|
-
builtin :permutation
|
968
|
+
Porolog::builtin :permutation
|
969
969
|
|
970
970
|
assert_solutions permutation([3,2,1,4], [1,2,3,4]), [{}]
|
971
971
|
end
|
972
972
|
|
973
973
|
it 'returns a solution and instantiates a variable' do
|
974
|
-
builtin :permutation
|
974
|
+
Porolog::builtin :permutation
|
975
975
|
|
976
976
|
assert_solutions permutation([3,2,:A,4], [1,2,3,4]), [{ A: 1 }]
|
977
977
|
end
|
978
978
|
|
979
979
|
it 'returns solutions of permutations of instantiations' do
|
980
|
-
builtin :permutation
|
980
|
+
Porolog::builtin :permutation
|
981
981
|
|
982
982
|
assert_solutions permutation([3,2,:A,:B], [1,2,3,4]), [
|
983
983
|
{ A: 1, B: 4 },
|
@@ -986,7 +986,7 @@ describe 'Porolog' do
|
|
986
986
|
end
|
987
987
|
|
988
988
|
it 'returns solutions of permutations of instantiations in the other list' do
|
989
|
-
builtin :permutation
|
989
|
+
Porolog::builtin :permutation
|
990
990
|
|
991
991
|
assert_solutions permutation([3,2,1,4], [:A,2,3,:B]), [
|
992
992
|
{ A: 1, B: 4 },
|
@@ -995,7 +995,7 @@ describe 'Porolog' do
|
|
995
995
|
end
|
996
996
|
|
997
997
|
it 'infers instantiations of variables in both arrays' do
|
998
|
-
builtin :permutation
|
998
|
+
Porolog::builtin :permutation
|
999
999
|
|
1000
1000
|
assert_solutions permutation([3,2,:A,4], [1,2,:C,4]), [
|
1001
1001
|
{ A: 1, C: 3 }
|
@@ -1003,7 +1003,7 @@ describe 'Porolog' do
|
|
1003
1003
|
end
|
1004
1004
|
|
1005
1005
|
it 'infers instantiations of variables in both arrays when they represent the same value' do
|
1006
|
-
builtin :permutation
|
1006
|
+
Porolog::builtin :permutation
|
1007
1007
|
|
1008
1008
|
assert_solutions permutation([:A,2,1,4], [1,2,:C,4]), [
|
1009
1009
|
{ A: 1, C: 1 },
|
@@ -1014,7 +1014,7 @@ describe 'Porolog' do
|
|
1014
1014
|
end
|
1015
1015
|
|
1016
1016
|
it 'returns all permutations of an array' do
|
1017
|
-
builtin :permutation
|
1017
|
+
Porolog::builtin :permutation
|
1018
1018
|
|
1019
1019
|
assert_solutions permutation([3,2,1,4], :L), [
|
1020
1020
|
{ L: [3, 2, 1, 4] },
|
@@ -1045,7 +1045,7 @@ describe 'Porolog' do
|
|
1045
1045
|
end
|
1046
1046
|
|
1047
1047
|
it 'returns all permutations of an array when arguments are swapped' do
|
1048
|
-
builtin :permutation
|
1048
|
+
Porolog::builtin :permutation
|
1049
1049
|
|
1050
1050
|
assert_solutions permutation(:L, [3,2,1,4]), [
|
1051
1051
|
{ L: [3, 2, 1, 4] },
|
@@ -1080,25 +1080,25 @@ describe 'Porolog' do
|
|
1080
1080
|
describe '#reverse' do
|
1081
1081
|
|
1082
1082
|
it 'returns no solutions for non-arrays' do
|
1083
|
-
builtin :reverse
|
1083
|
+
Porolog::builtin :reverse
|
1084
1084
|
|
1085
1085
|
assert_solutions reverse('1234', '1234'), []
|
1086
1086
|
end
|
1087
1087
|
|
1088
1088
|
it 'returns a solution for mirrored arrays without variables' do
|
1089
|
-
builtin :reverse
|
1089
|
+
Porolog::builtin :reverse
|
1090
1090
|
|
1091
1091
|
assert_solutions reverse([1,2,3,4], [4,3,2,1]), [{}]
|
1092
1092
|
end
|
1093
1093
|
|
1094
1094
|
it 'returns a solution and instantiates a variable' do
|
1095
|
-
builtin :reverse
|
1095
|
+
Porolog::builtin :reverse
|
1096
1096
|
|
1097
1097
|
assert_solutions reverse([4,3,:A,1], [1,2,3,4]), [{ A: 2 }]
|
1098
1098
|
end
|
1099
1099
|
|
1100
1100
|
it 'returns a solution and instantiates multiple variables' do
|
1101
|
-
builtin :reverse
|
1101
|
+
Porolog::builtin :reverse
|
1102
1102
|
|
1103
1103
|
assert_solutions reverse([4,3,:A,:B], [1,2,3,4]), [
|
1104
1104
|
{ A: 2, B: 1 },
|
@@ -1106,7 +1106,7 @@ describe 'Porolog' do
|
|
1106
1106
|
end
|
1107
1107
|
|
1108
1108
|
it 'returns a solution and instantiates multiple variables in the other list' do
|
1109
|
-
builtin :reverse
|
1109
|
+
Porolog::builtin :reverse
|
1110
1110
|
|
1111
1111
|
assert_solutions reverse([4,3,2,1], [:A,2,3,:B]), [
|
1112
1112
|
{ A: 1, B: 4 },
|
@@ -1114,7 +1114,7 @@ describe 'Porolog' do
|
|
1114
1114
|
end
|
1115
1115
|
|
1116
1116
|
it 'infers instantiations of variables in both arrays' do
|
1117
|
-
builtin :reverse
|
1117
|
+
Porolog::builtin :reverse
|
1118
1118
|
|
1119
1119
|
assert_solutions reverse([4,3,:A,1], [1,2,:C,4]), [
|
1120
1120
|
{ A: 2, C: 3 }
|
@@ -1122,7 +1122,7 @@ describe 'Porolog' do
|
|
1122
1122
|
end
|
1123
1123
|
|
1124
1124
|
it 'infers instantiations of variables in both arrays when they represent the same value' do
|
1125
|
-
builtin :reverse
|
1125
|
+
Porolog::builtin :reverse
|
1126
1126
|
|
1127
1127
|
assert_solutions reverse([:A,3,2,1], [1,:A,3,:C]), [
|
1128
1128
|
{ A: 2, C: 2 },
|
@@ -1130,7 +1130,7 @@ describe 'Porolog' do
|
|
1130
1130
|
end
|
1131
1131
|
|
1132
1132
|
it 'allows unbound variables' do
|
1133
|
-
builtin :reverse
|
1133
|
+
Porolog::builtin :reverse
|
1134
1134
|
|
1135
1135
|
assert_solutions reverse([:A,3,2,1], :L), [
|
1136
1136
|
{ A: nil, L: [1,2,3,nil] },
|
@@ -1138,7 +1138,7 @@ describe 'Porolog' do
|
|
1138
1138
|
end
|
1139
1139
|
|
1140
1140
|
it 'instantiates a variable to the reversed array' do
|
1141
|
-
builtin :reverse
|
1141
|
+
Porolog::builtin :reverse
|
1142
1142
|
|
1143
1143
|
assert_solutions reverse([4,3,2,1], :L), [
|
1144
1144
|
{ L: [1, 2, 3, 4] },
|
@@ -1146,7 +1146,7 @@ describe 'Porolog' do
|
|
1146
1146
|
end
|
1147
1147
|
|
1148
1148
|
it 'instantiates a variable to the reversed array when arguments are swapped' do
|
1149
|
-
builtin :reverse
|
1149
|
+
Porolog::builtin :reverse
|
1150
1150
|
|
1151
1151
|
assert_solutions reverse(:L, [4,3,2,1]), [
|
1152
1152
|
{ L: [1, 2, 3, 4] },
|
@@ -1154,7 +1154,7 @@ describe 'Porolog' do
|
|
1154
1154
|
end
|
1155
1155
|
|
1156
1156
|
it 'returns no solutions for uninstantiated variables' do
|
1157
|
-
builtin :reverse
|
1157
|
+
Porolog::builtin :reverse
|
1158
1158
|
|
1159
1159
|
assert_solutions reverse(:X, :Y), [], goals: 1
|
1160
1160
|
end
|
@@ -1164,14 +1164,14 @@ describe 'Porolog' do
|
|
1164
1164
|
describe '#var' do
|
1165
1165
|
|
1166
1166
|
it 'should be unsuccessful for an atom' do
|
1167
|
-
builtin :var
|
1167
|
+
Porolog::builtin :var
|
1168
1168
|
|
1169
1169
|
assert_solutions var('1234'), []
|
1170
1170
|
end
|
1171
1171
|
|
1172
1172
|
it 'should be successful for an uninstantiated variable' do
|
1173
|
-
builtin :var, :is_eq
|
1174
|
-
predicate :vartest
|
1173
|
+
Porolog::builtin :var, :is_eq
|
1174
|
+
Porolog::predicate :vartest
|
1175
1175
|
|
1176
1176
|
vartest(:variable) << [
|
1177
1177
|
var(:variable),
|
@@ -1182,8 +1182,8 @@ describe 'Porolog' do
|
|
1182
1182
|
end
|
1183
1183
|
|
1184
1184
|
it 'should be successful for an uninstantiated bound variable' do
|
1185
|
-
builtin :var, :is_eq
|
1186
|
-
predicate :vartest
|
1185
|
+
Porolog::builtin :var, :is_eq
|
1186
|
+
Porolog::predicate :vartest
|
1187
1187
|
|
1188
1188
|
vartest(:variable) << [
|
1189
1189
|
is_eq(:variable, :bound),
|
@@ -1195,8 +1195,8 @@ describe 'Porolog' do
|
|
1195
1195
|
end
|
1196
1196
|
|
1197
1197
|
it 'should be successful for an uninstantiated bound variable' do
|
1198
|
-
builtin :var, :is_eq
|
1199
|
-
predicate :vartest
|
1198
|
+
Porolog::builtin :var, :is_eq
|
1199
|
+
Porolog::predicate :vartest
|
1200
1200
|
|
1201
1201
|
vartest(:variable) << [
|
1202
1202
|
is_eq(:variable, 'instantiated'),
|
@@ -1211,14 +1211,14 @@ describe 'Porolog' do
|
|
1211
1211
|
describe '#nonvar' do
|
1212
1212
|
|
1213
1213
|
it 'should be successful for an atom' do
|
1214
|
-
builtin :nonvar
|
1214
|
+
Porolog::builtin :nonvar
|
1215
1215
|
|
1216
1216
|
assert_solutions nonvar('1234'), [{}]
|
1217
1217
|
end
|
1218
1218
|
|
1219
1219
|
it 'should be unsuccessful for an uninstantiated variable' do
|
1220
|
-
builtin :nonvar, :is_eq
|
1221
|
-
predicate :nonvartest
|
1220
|
+
Porolog::builtin :nonvar, :is_eq
|
1221
|
+
Porolog::predicate :nonvartest
|
1222
1222
|
|
1223
1223
|
nonvartest(:variable) << [
|
1224
1224
|
nonvar(:variable),
|
@@ -1229,8 +1229,8 @@ describe 'Porolog' do
|
|
1229
1229
|
end
|
1230
1230
|
|
1231
1231
|
it 'should be unsuccessful for an uninstantiated bound variable' do
|
1232
|
-
builtin :nonvar, :is_eq
|
1233
|
-
predicate :nonvartest
|
1232
|
+
Porolog::builtin :nonvar, :is_eq
|
1233
|
+
Porolog::predicate :nonvartest
|
1234
1234
|
|
1235
1235
|
nonvartest(:variable) << [
|
1236
1236
|
is_eq(:variable, :bound),
|
@@ -1242,8 +1242,8 @@ describe 'Porolog' do
|
|
1242
1242
|
end
|
1243
1243
|
|
1244
1244
|
it 'should be unsuccessful for an uninstantiated bound variable' do
|
1245
|
-
builtin :nonvar, :is_eq
|
1246
|
-
predicate :nonvartest
|
1245
|
+
Porolog::builtin :nonvar, :is_eq
|
1246
|
+
Porolog::predicate :nonvartest
|
1247
1247
|
|
1248
1248
|
nonvartest(:variable) << [
|
1249
1249
|
is_eq(:variable, 'instantiated'),
|
@@ -1258,19 +1258,19 @@ describe 'Porolog' do
|
|
1258
1258
|
describe '#atom' do
|
1259
1259
|
|
1260
1260
|
it 'should be satisfied with a String' do
|
1261
|
-
builtin :atom
|
1261
|
+
Porolog::builtin :atom
|
1262
1262
|
|
1263
1263
|
assert_solutions atom('banana'), [{}]
|
1264
1264
|
end
|
1265
1265
|
|
1266
1266
|
it 'should not be satisfied with an Integer' do
|
1267
|
-
builtin :atom
|
1267
|
+
Porolog::builtin :atom
|
1268
1268
|
|
1269
1269
|
assert_solutions atom(6), []
|
1270
1270
|
end
|
1271
1271
|
|
1272
1272
|
it 'should not be satisfied with an Array' do
|
1273
|
-
builtin :atom
|
1273
|
+
Porolog::builtin :atom
|
1274
1274
|
|
1275
1275
|
assert_solutions atom([]), []
|
1276
1276
|
end
|
@@ -1280,25 +1280,25 @@ describe 'Porolog' do
|
|
1280
1280
|
describe '#atomic' do
|
1281
1281
|
|
1282
1282
|
it 'should be satisfied with a String' do
|
1283
|
-
builtin :atomic
|
1283
|
+
Porolog::builtin :atomic
|
1284
1284
|
|
1285
1285
|
assert_solutions atomic('banana'), [{}]
|
1286
1286
|
end
|
1287
1287
|
|
1288
1288
|
it 'should be satisfied with an Integer' do
|
1289
|
-
builtin :atomic
|
1289
|
+
Porolog::builtin :atomic
|
1290
1290
|
|
1291
1291
|
assert_solutions atomic(6), [{}]
|
1292
1292
|
end
|
1293
1293
|
|
1294
1294
|
it 'should not be satisfied with an Array' do
|
1295
|
-
builtin :atomic
|
1295
|
+
Porolog::builtin :atomic
|
1296
1296
|
|
1297
1297
|
assert_solutions atomic([]), []
|
1298
1298
|
end
|
1299
1299
|
|
1300
1300
|
it 'should not be satisfied with an uninstantiated variable' do
|
1301
|
-
builtin :atomic
|
1301
|
+
Porolog::builtin :atomic
|
1302
1302
|
|
1303
1303
|
assert_solutions atomic(:X), []
|
1304
1304
|
end
|
@@ -1308,25 +1308,25 @@ describe 'Porolog' do
|
|
1308
1308
|
describe '#integer' do
|
1309
1309
|
|
1310
1310
|
it 'should not be satisfied with a String' do
|
1311
|
-
builtin :integer
|
1311
|
+
Porolog::builtin :integer
|
1312
1312
|
|
1313
1313
|
assert_solutions integer('banana'), []
|
1314
1314
|
end
|
1315
1315
|
|
1316
1316
|
it 'should be satisfied with an Integer' do
|
1317
|
-
builtin :integer
|
1317
|
+
Porolog::builtin :integer
|
1318
1318
|
|
1319
1319
|
assert_solutions integer(6), [{}]
|
1320
1320
|
end
|
1321
1321
|
|
1322
1322
|
it 'should not be satisfied with an Array' do
|
1323
|
-
builtin :integer
|
1323
|
+
Porolog::builtin :integer
|
1324
1324
|
|
1325
1325
|
assert_solutions integer([]), []
|
1326
1326
|
end
|
1327
1327
|
|
1328
1328
|
it 'should not be satisfied with an uninstantiated variable' do
|
1329
|
-
builtin :integer
|
1329
|
+
Porolog::builtin :integer
|
1330
1330
|
|
1331
1331
|
assert_solutions integer(:X), []
|
1332
1332
|
end
|