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.
@@ -18,7 +18,7 @@ describe 'Porolog' do
18
18
  describe '#inspect' do
19
19
 
20
20
  it 'should return distinctive notation' do
21
- assert_equal '...', UNKNOWN_TAIL.inspect
21
+ assert_equal '...', Porolog::UNKNOWN_TAIL.inspect
22
22
  end
23
23
 
24
24
  end
@@ -26,9 +26,9 @@ describe 'Porolog' do
26
26
  describe '#tail' do
27
27
 
28
28
  it 'should return itself' do
29
- assert_equal UNKNOWN_TAIL, UNKNOWN_TAIL.tail
30
- assert_equal UNKNOWN_TAIL, UNKNOWN_TAIL.tail(1)
31
- assert_equal UNKNOWN_TAIL, UNKNOWN_TAIL.tail(5)
29
+ assert_equal Porolog::UNKNOWN_TAIL, Porolog::UNKNOWN_TAIL.tail
30
+ assert_equal Porolog::UNKNOWN_TAIL, Porolog::UNKNOWN_TAIL.tail(1)
31
+ assert_equal Porolog::UNKNOWN_TAIL, Porolog::UNKNOWN_TAIL.tail(5)
32
32
  end
33
33
 
34
34
  end
@@ -39,35 +39,35 @@ describe 'Porolog' do
39
39
 
40
40
  it 'should create a Predicate' do
41
41
  # -- Precondition Baseline --
42
- assert_equal 0, Scope[:default].predicates.size
42
+ assert_equal 0, Porolog::Scope[:default].predicates.size
43
43
 
44
44
  # -- Test --
45
- single_predicate = predicate :single
45
+ single_predicate = Porolog::predicate :single
46
46
 
47
47
  # -- Compare Result Against Baseline --
48
- assert_equal 1, Scope[:default].predicates.size
49
- assert_equal :single, Scope[:default].predicates.first.name
48
+ assert_equal 1, Porolog::Scope[:default].predicates.size
49
+ assert_equal :single, Porolog::Scope[:default].predicates.first.name
50
50
  assert_Predicate single_predicate, :single, []
51
51
  end
52
52
 
53
53
  it 'should define a method to create Arguments for solving' do
54
54
  refute respond_to?(:delta)
55
55
 
56
- predicate :delta
56
+ Porolog::predicate :delta
57
57
 
58
58
  assert respond_to?(:delta)
59
59
  assert_Arguments delta(1, :X, ['left','right']), :delta, [1, :X, ['left','right']]
60
60
  end
61
61
 
62
62
  it 'should create multiple Predicates' do
63
- assert_equal 0, Scope[:default].predicates.size
63
+ assert_equal 0, Porolog::Scope[:default].predicates.size
64
64
 
65
- multiple_predicates = predicate :alpha, :beta, :gamma
65
+ multiple_predicates = Porolog::predicate :alpha, :beta, :gamma
66
66
 
67
- assert_equal 3, Scope[:default].predicates.size
68
- assert_equal :alpha, Scope[:default].predicates[0].name
69
- assert_equal :beta, Scope[:default].predicates[1].name
70
- assert_equal :gamma, Scope[:default].predicates[2].name
67
+ assert_equal 3, Porolog::Scope[:default].predicates.size
68
+ assert_equal :alpha, Porolog::Scope[:default].predicates[0].name
69
+ assert_equal :beta, Porolog::Scope[:default].predicates[1].name
70
+ assert_equal :gamma, Porolog::Scope[:default].predicates[2].name
71
71
  assert_instance_of Array, multiple_predicates
72
72
  assert_equal 3, multiple_predicates.size
73
73
  assert_Predicate multiple_predicates[0], :alpha, []
@@ -79,7 +79,7 @@ describe 'Porolog' do
79
79
  refute respond_to?(:epsilon)
80
80
  refute respond_to?(:upsilon)
81
81
 
82
- predicate :epsilon, :upsilon
82
+ Porolog::predicate :epsilon, :upsilon
83
83
 
84
84
  assert respond_to?(:epsilon)
85
85
  assert respond_to?(:upsilon)
@@ -95,8 +95,8 @@ describe 'Porolog' do
95
95
 
96
96
  class Base1
97
97
 
98
- builtin :between, class_base: self
99
- predicate :localised_predicate, class_base: self
98
+ Porolog::builtin :between, class_base: self
99
+ Porolog::predicate :localised_predicate, class_base: self
100
100
 
101
101
  localised_predicate(:X) << [
102
102
  between(:X, 1, 5)
@@ -144,7 +144,7 @@ describe 'Porolog' do
144
144
  ].join("\n")
145
145
 
146
146
  # -- Test --
147
- assert unify_goals(goal1, goal2), name
147
+ assert Porolog::unify_goals(goal1, goal2), name
148
148
 
149
149
  # -- Compare Result Against Baseline --
150
150
  assert_Goal_variables goal1, { m: nil, n: nil }, [
@@ -166,7 +166,7 @@ describe 'Porolog' do
166
166
  goal1 = new_goal :p, :x, :y
167
167
  goal2 = new_goal :q, :x, :y
168
168
 
169
- refute unify_goals(goal1, goal2), name
169
+ refute Porolog::unify_goals(goal1, goal2), name
170
170
 
171
171
  assert_equal ['Cannot unify goals because they are for different predicates: :p and :q'], goal1.log
172
172
  assert_equal ['Cannot unify goals because they are for different predicates: :p and :q'], goal2.log
@@ -188,7 +188,7 @@ describe 'Porolog' do
188
188
  [:x, 37, goal1, goal3],
189
189
  ]
190
190
 
191
- refute instantiate_unifications(unifications), name
191
+ refute Porolog::instantiate_unifications(unifications), name
192
192
  end
193
193
 
194
194
  it 'should create instantiations' do
@@ -216,7 +216,7 @@ describe 'Porolog' do
216
216
  ].join("\n")
217
217
 
218
218
  # -- Test --
219
- assert instantiate_unifications(unifications), name
219
+ assert Porolog::instantiate_unifications(unifications), name
220
220
 
221
221
  # -- Compare Result Against Baseline --
222
222
  assert_Goal_variables goal1, { x: 12, y: nil }, [
@@ -267,7 +267,7 @@ describe 'Porolog' do
267
267
  [:k, 37, goal2, goal3],
268
268
  ]
269
269
 
270
- refute instantiate_unifications(unifications), name
270
+ refute Porolog::instantiate_unifications(unifications), name
271
271
 
272
272
  assert_Goal_variables goal1, { x: nil, y: nil }, [
273
273
  'Goal1.:x',
@@ -295,11 +295,11 @@ describe 'Porolog' do
295
295
  describe 'when [:atomic,:atomic]' do
296
296
 
297
297
  it 'should unify equal atomic numbers' do
298
- assert unify(42, 42, goal), name
298
+ assert Porolog::unify(42, 42, goal), name
299
299
  end
300
300
 
301
301
  it 'should not unify unequal atomic numbers' do
302
- refute unify(42, 99, goal), name
302
+ refute Porolog::unify(42, 99, goal), name
303
303
 
304
304
  expected_log = [
305
305
  'Cannot unify because 42 != 99 (atomic != atomic)',
@@ -313,7 +313,7 @@ describe 'Porolog' do
313
313
  describe 'when [:array,:array]' do
314
314
 
315
315
  before do
316
- @spy = Spy.on(self, :unify_arrays).and_call_through
316
+ @spy = Spy.on(Porolog, :unify_arrays).and_call_through
317
317
  end
318
318
 
319
319
  after do
@@ -321,15 +321,15 @@ describe 'Porolog' do
321
321
  end
322
322
 
323
323
  it 'should unify empty arrays' do
324
- assert unify([], [], goal), name
324
+ assert Porolog::unify([], [], goal), name
325
325
  end
326
326
 
327
327
  it 'should unify equal arrays' do
328
- assert unify([7,11,13], [7,11,13], goal), name
328
+ assert Porolog::unify([7,11,13], [7,11,13], goal), name
329
329
  end
330
330
 
331
331
  it 'should not unify unequal arrays' do
332
- refute unify([7,11,13], [7,11,14], goal), name
332
+ refute Porolog::unify([7,11,13], [7,11,14], goal), name
333
333
 
334
334
  expected_log = [
335
335
  'Cannot unify incompatible values: 13 with 14',
@@ -340,7 +340,7 @@ describe 'Porolog' do
340
340
  end
341
341
 
342
342
  it 'should not unify arrays of different lengths' do
343
- refute unify([7,11,13], [7,11,13,13], goal), name
343
+ refute Porolog::unify([7,11,13], [7,11,13,13], goal), name
344
344
 
345
345
  expected_log = [
346
346
  'Cannot unify arrays of different lengths: [7, 11, 13] with [7, 11, 13, 13]',
@@ -359,13 +359,13 @@ describe 'Porolog' do
359
359
  end
360
360
 
361
361
  it 'should return an instantiation' do
362
- assert_equal [[:word, 'word', goal, goal]], unify(:word, 'word', goal), name
362
+ assert_equal [[:word, 'word', goal, goal]], Porolog::unify(:word, 'word', goal), name
363
363
  end
364
364
 
365
365
  it 'should not unify an instantiated variable with a different value' do
366
366
  goal.instantiate :word, 'other'
367
367
 
368
- assert_nil unify(:word, 'word', goal), name
368
+ assert_nil Porolog::unify(:word, 'word', goal), name
369
369
 
370
370
  expected_log = [
371
371
  'Cannot unify because Goal1."other" != "word" (variable != atomic)',
@@ -383,13 +383,13 @@ describe 'Porolog' do
383
383
  end
384
384
 
385
385
  it 'should return an instantiation' do
386
- assert_equal [[:word, 'word', goal, goal]], unify('word', :word, goal), name
386
+ assert_equal [[:word, 'word', goal, goal]], Porolog::unify('word', :word, goal), name
387
387
  end
388
388
 
389
389
  it 'should not unify instantiated variables with different values' do
390
390
  goal.instantiate :word, 'something'
391
391
 
392
- assert_nil unify('word', :word, goal), name
392
+ assert_nil Porolog::unify('word', :word, goal), name
393
393
 
394
394
  expected_log = [
395
395
  'Cannot unify because "word" != Goal1."something" (atomic != variable)',
@@ -407,14 +407,14 @@ describe 'Porolog' do
407
407
  end
408
408
 
409
409
  it 'should return an instantiation' do
410
- assert_equal [[:x, :y, goal, goal2]], unify(:x, :y, goal, goal2), name
410
+ assert_equal [[:x, :y, goal, goal2]], Porolog::unify(:x, :y, goal, goal2), name
411
411
  end
412
412
 
413
413
  it 'should not unify instantiated variables with different values' do
414
414
  goal.instantiate :word, 'something'
415
415
  goal.instantiate :draw, 'picturing'
416
416
 
417
- assert_nil unify(:draw, :word, goal), name
417
+ assert_nil Porolog::unify(:draw, :word, goal), name
418
418
 
419
419
  expected_log = [
420
420
  'Cannot unify because "picturing" != "something" (variable != variable)'
@@ -424,10 +424,10 @@ describe 'Porolog' do
424
424
  end
425
425
 
426
426
  it 'should unify the unknown array with a variable' do
427
- goal.instantiate :X, UNKNOWN_ARRAY
427
+ goal.instantiate :X, Porolog::UNKNOWN_ARRAY
428
428
  goal.instantiate :Y, [1,2,3,4]
429
429
 
430
- unifications = unify(goal[:X], goal[:Y], goal)
430
+ unifications = Porolog::unify(goal[:X], goal[:Y], goal)
431
431
 
432
432
  expected_unifications = [
433
433
  [goal[:X], goal[:Y], goal, goal]
@@ -442,9 +442,9 @@ describe 'Porolog' do
442
442
 
443
443
  it 'should unify the unknown array with an array' do
444
444
  goal.instantiate :X, [1,2,3,4]
445
- goal.instantiate :Y, UNKNOWN_ARRAY
445
+ goal.instantiate :Y, Porolog::UNKNOWN_ARRAY
446
446
 
447
- unifications = unify(goal[:X], goal[:Y], goal)
447
+ unifications = Porolog::unify(goal[:X], goal[:Y], goal)
448
448
 
449
449
  expected_unifications = [
450
450
  [goal[:X], goal[:Y], goal, goal]
@@ -464,16 +464,17 @@ describe 'Porolog' do
464
464
  it 'should return an instantiation' do
465
465
  expects(:unify_arrays).times(0)
466
466
 
467
- assert_equal [[:list, [7,11,13], goal, goal]], unify(:list, [7,11,13], goal), name
467
+ assert_equal [[:list, [7,11,13], goal, goal]], Porolog::unify(:list, [7,11,13], goal), name
468
468
  end
469
469
 
470
470
  it 'should not unify instantiated variables with different values' do
471
471
  goal.instantiate :word, [1,2,3,4]
472
- expects(:unify_arrays).times(1)
472
+ Porolog::expects(:unify_arrays).times(1)
473
473
 
474
- assert_nil unify(:word, [1,2,3,5], goal), name
474
+ assert_nil Porolog::unify(:word, [1,2,3,5], goal), name
475
475
 
476
476
  expected_log = [
477
+ #'Cannot unify incompatible values: 4 with 5',
477
478
  'Cannot unify because Goal1.[1, 2, 3, 4] != [1, 2, 3, 5] (variable/array != array)'
478
479
  ]
479
480
 
@@ -482,9 +483,9 @@ describe 'Porolog' do
482
483
 
483
484
  it 'should not unify instantiated variables with a non-array value' do
484
485
  goal.instantiate :word, 1234
485
- expects(:unify_arrays).times(0)
486
+ Porolog::expects(:unify_arrays).times(0)
486
487
 
487
- assert_nil unify(:word, [1,2,3,5], goal), name
488
+ assert_nil Porolog::unify(:word, [1,2,3,5], goal), name
488
489
 
489
490
  expected_log = [
490
491
  'Cannot unify because Goal1.1234 != [1, 2, 3, 5] (variable != array)'
@@ -500,7 +501,7 @@ describe 'Porolog' do
500
501
  it 'should not unify instantiated variables that are not instantiated with an array' do
501
502
  goal.instantiate :word, '1 2 3 4'
502
503
 
503
- assert_nil unify([1,2,3,4], :word, goal), name
504
+ assert_nil Porolog::unify([1,2,3,4], :word, goal), name
504
505
 
505
506
  expected_log = [
506
507
  'Cannot unify because [1, 2, 3, 4] != Goal1."1 2 3 4" (array != variable)'
@@ -512,16 +513,17 @@ describe 'Porolog' do
512
513
  it 'should return an instantiation' do
513
514
  expects(:unify_arrays).times(0)
514
515
 
515
- assert_equal [[:list, [7,11,13], goal, goal]], unify([7,11,13], :list, goal), name
516
+ assert_equal [[:list, [7,11,13], goal, goal]], Porolog::unify([7,11,13], :list, goal), name
516
517
  end
517
518
 
518
519
  it 'should not unify instantiated variables with different values' do
519
520
  goal.instantiate :word, [1,2,3,4]
520
- expects(:unify_arrays).times(1)
521
+ Porolog::expects(:unify_arrays).times(1)
521
522
 
522
- assert_nil unify([1,2,3,5], :word, goal), name
523
+ assert_nil Porolog::unify([1,2,3,5], :word, goal), name
523
524
 
524
525
  expected_log = [
526
+ #'Cannot unify incompatible values: 5 with 4',
525
527
  'Cannot unify because [1, 2, 3, 5] != Goal1.[1, 2, 3, 4] (variable/array != array)'
526
528
  ]
527
529
 
@@ -531,7 +533,7 @@ describe 'Porolog' do
531
533
  it 'should unify instantiated variables with unifiable values' do
532
534
  goal.instantiate :word, [1,2,3]/:w
533
535
 
534
- instantiations = unify([nil,nil,3,4,5], :word, goal)
536
+ instantiations = Porolog::unify([nil,nil,3,4,5], :word, goal)
535
537
 
536
538
  expected_log = []
537
539
  expected_instantiations = [
@@ -547,11 +549,11 @@ describe 'Porolog' do
547
549
  describe 'when [:array,:atomic], [:atomic,:array]' do
548
550
 
549
551
  before do
550
- expects(:unify_arrays).times(0)
552
+ Porolog::expects(:unify_arrays).times(0)
551
553
  end
552
554
 
553
555
  it 'should return nil for unifying array and atomic' do
554
- assert_nil unify([7,11,13], 'word', goal), name
556
+ assert_nil Porolog::unify([7,11,13], 'word', goal), name
555
557
 
556
558
  expected_log = [
557
559
  'Cannot unify [7, 11, 13] with "word" (array != atomic)',
@@ -561,7 +563,7 @@ describe 'Porolog' do
561
563
  end
562
564
 
563
565
  it 'should return nil for unifying atomic and array' do
564
- assert_nil unify('word', [7,11,13], goal), name
566
+ assert_nil Porolog::unify('word', [7,11,13], goal), name
565
567
 
566
568
  expected_log = [
567
569
  'Cannot unify "word" with [7, 11, 13] (atomic != array)',
@@ -577,7 +579,7 @@ describe 'Porolog' do
577
579
  let(:goal) { new_goal :p, :x, :y }
578
580
 
579
581
  it 'should unify an array and a tail' do
580
- assert unify([7,11,13], Tail.new([[7,11,goal[:P]]]), goal), name
582
+ assert Porolog::unify([7,11,13], Porolog::Tail.new([[7,11,goal[:P]]]), goal), name
581
583
 
582
584
  expected_log = []
583
585
 
@@ -585,7 +587,7 @@ describe 'Porolog' do
585
587
  end
586
588
 
587
589
  it 'should not unify an array and tail when they cannot be unified' do
588
- refute unify([7,11,13], Tail.new([[7,11,14]]), goal), name
590
+ refute Porolog::unify([7,11,13], Porolog::Tail.new([[7,11,14]]), goal), name
589
591
 
590
592
  expected_log = [
591
593
  'Cannot unify incompatible values: 13 with 14',
@@ -603,7 +605,7 @@ describe 'Porolog' do
603
605
  let(:goal) { new_goal :p, :x, :y }
604
606
 
605
607
  it 'should unify a tail and an array' do
606
- assert unify(Tail.new([[7,11,13]]), [7,11,goal[:P]], goal), name
608
+ assert Porolog::unify(Porolog::Tail.new([[7,11,13]]), [7,11,goal[:P]], goal), name
607
609
 
608
610
  expected_log = []
609
611
 
@@ -611,7 +613,7 @@ describe 'Porolog' do
611
613
  end
612
614
 
613
615
  it 'should not unify a tail and an array when they cannot be unified' do
614
- refute unify(Tail.new([[7,11,13]]), [7,11,14], goal), name
616
+ refute Porolog::unify(Porolog::Tail.new([[7,11,13]]), [7,11,14], goal), name
615
617
 
616
618
  expected_log = [
617
619
  'Cannot unify incompatible values: 13 with 14',
@@ -631,7 +633,7 @@ describe 'Porolog' do
631
633
  [goal[:B], [goal[:H]]/:T, goal, goal],
632
634
  [goal[:C], [goal[:H]]/:NT, goal, goal]
633
635
  ]
634
- assert_equal expected_unifications, unify(
636
+ assert_equal expected_unifications, Porolog::unify(
635
637
  [:A, :B, :C],
636
638
  [:A, [:H]/:T, [:H]/:NT],
637
639
  goal
@@ -667,19 +669,19 @@ describe 'Porolog' do
667
669
  it 'should unify but without unifications when left is the unknown array' do
668
670
  expect_unify_arrays_with_calls 0, 0, 0
669
671
 
670
- assert_Unify_arrays [UNKNOWN_ARRAY, [:a,:b,:c]], goals, [g2[:a], g2[:b], g2[:c]]
672
+ assert_Unify_arrays [Porolog::UNKNOWN_ARRAY, [:a,:b,:c]], goals, [g2[:a], g2[:b], g2[:c]]
671
673
  end
672
674
 
673
675
  it 'should unify but without unifications when right is the unknown array' do
674
676
  expect_unify_arrays_with_calls 0, 0, 0
675
677
 
676
- assert_Unify_arrays [[:x,:y,:z], UNKNOWN_ARRAY], goals, [g1[:x], g1[:y], g1[:z]]
678
+ assert_Unify_arrays [[:x,:y,:z], Porolog::UNKNOWN_ARRAY], goals, [g1[:x], g1[:y], g1[:z]]
677
679
  end
678
680
 
679
681
  it 'should unify but without unifications when left and right are the unknown array' do
680
682
  expect_unify_arrays_with_calls 0, 0, 0
681
683
 
682
- assert_Unify_arrays [[UNKNOWN_TAIL], UNKNOWN_ARRAY], goals, UNKNOWN_ARRAY
684
+ assert_Unify_arrays [[Porolog::UNKNOWN_TAIL], Porolog::UNKNOWN_ARRAY], goals, Porolog::UNKNOWN_ARRAY
683
685
  end
684
686
 
685
687
  arrays_without_tails = [
@@ -694,10 +696,10 @@ describe 'Porolog' do
694
696
  []/:t,
695
697
  [1]/:z,
696
698
  [1, 2]/:s,
697
- [1, UNKNOWN_TAIL],
698
- [1, 2, 3, UNKNOWN_TAIL],
699
- [1, 2, 3, 4, UNKNOWN_TAIL],
700
- [:x, :y, :z, UNKNOWN_TAIL],
699
+ [1, Porolog::UNKNOWN_TAIL],
700
+ [1, 2, 3, Porolog::UNKNOWN_TAIL],
701
+ [1, 2, 3, 4, Porolog::UNKNOWN_TAIL],
702
+ [:x, :y, :z, Porolog::UNKNOWN_TAIL],
701
703
  [['one'], ['word'], ['sentences']]/:tail,
702
704
  ]
703
705
 
@@ -705,7 +707,7 @@ describe 'Porolog' do
705
707
  it "should call unify_arrays_with_no_tails when there are no tails: #{arrays.map(&:inspect).join(' and ')}" do
706
708
  expect_unify_arrays_with_calls 1, 0, 0
707
709
 
708
- unify_arrays(*arrays, *goals)
710
+ Porolog::unify_arrays(*arrays, *goals)
709
711
  end
710
712
  end
711
713
 
@@ -713,7 +715,7 @@ describe 'Porolog' do
713
715
  it "should call unify_arrays_with_all_tails when all arrays have tails: #{arrays.map(&:inspect).join(' and ')}" do
714
716
  expect_unify_arrays_with_calls 0, 0, 1
715
717
 
716
- unify_arrays(*arrays, *goals)
718
+ Porolog::unify_arrays(*arrays, *goals)
717
719
  end
718
720
  end
719
721
 
@@ -724,7 +726,7 @@ describe 'Porolog' do
724
726
  it "should call unify_arrays_with_some_tails when one array has a tail and the other does not: #{arrays.map(&:inspect).join(' and ')}" do
725
727
  expect_unify_arrays_with_calls 0, 1, 0
726
728
 
727
- unify_arrays(*arrays, *goals)
729
+ Porolog::unify_arrays(*arrays, *goals)
728
730
  end
729
731
  end
730
732
 
@@ -764,15 +766,15 @@ describe 'Porolog' do
764
766
  end
765
767
 
766
768
  it 'should unify a fixed array with the unknown array' do
767
- assert_Unify_arrays [[1,2,3], UNKNOWN_ARRAY], goals, [1,2,3]
769
+ assert_Unify_arrays [[1,2,3], Porolog::UNKNOWN_ARRAY], goals, [1,2,3]
768
770
  end
769
771
 
770
772
  it 'should unify the unknown array with the unknown array' do
771
- assert_Unify_arrays [UNKNOWN_ARRAY, UNKNOWN_ARRAY], goals, UNKNOWN_ARRAY
773
+ assert_Unify_arrays [Porolog::UNKNOWN_ARRAY, Porolog::UNKNOWN_ARRAY], goals, Porolog::UNKNOWN_ARRAY
772
774
  end
773
775
 
774
776
  it 'should unify arrays with variable tails' do
775
- assert_Unify_arrays [[:a, :b]/:c, [:x, :y]/:z], goals, [nil,nil,UNKNOWN_TAIL], [
777
+ assert_Unify_arrays [[:a, :b]/:c, [:x, :y]/:z], goals, [nil, nil, Porolog::UNKNOWN_TAIL], [
776
778
  [:a, :x, g1, g2],
777
779
  [:b, :y, g1, g2],
778
780
  [:c, :z, g1, g2],
@@ -780,7 +782,7 @@ describe 'Porolog' do
780
782
  end
781
783
 
782
784
  it 'should unify arrays with variable tails of different lenths' do
783
- assert_Unify_arrays [[:a, :b]/:c, [:x]/:z], goals, [nil,nil,UNKNOWN_TAIL], [
785
+ assert_Unify_arrays [[:a, :b]/:c, [:x]/:z], goals, [nil, nil, Porolog::UNKNOWN_TAIL], [
784
786
  [g2[:x], g1[:a], g2, g1],
785
787
  [g2[:z], [g1[:b]]/g1[:c], g2, g1],
786
788
  ]
@@ -817,7 +819,7 @@ describe 'Porolog' do
817
819
  :x,
818
820
  ]
819
821
 
820
- assert_nil unify_many_arrays(arrays, [goal] * arrays.size), name
822
+ assert_nil Porolog::unify_many_arrays(arrays, [goal] * arrays.size), name
821
823
 
822
824
  expected_log = [
823
825
  'Cannot unify: [1, 2, 3] with 123 with :x',
@@ -829,11 +831,11 @@ describe 'Porolog' do
829
831
  it 'should not return nil when all arrays are Arrays or variables' do
830
832
  arrays = [
831
833
  [1,2,3],
832
- UNKNOWN_ARRAY,
834
+ Porolog::UNKNOWN_ARRAY,
833
835
  :x,
834
836
  ]
835
837
 
836
- result = unify_many_arrays(arrays, [goal] * arrays.size)
838
+ result = Porolog::unify_many_arrays(arrays, [goal] * arrays.size)
837
839
  refute_nil result, name
838
840
 
839
841
  merged, unifications = result
@@ -849,10 +851,10 @@ describe 'Porolog' do
849
851
  it 'should automatically merge unknown arrays' do
850
852
  arrays = [
851
853
  [1,2,3],
852
- UNKNOWN_ARRAY,
854
+ Porolog::UNKNOWN_ARRAY,
853
855
  ]
854
856
 
855
- assert_equal [[1,2,3], []], unify_many_arrays(arrays, [goal] * arrays.size), name
857
+ assert_equal [[1,2,3], []], Porolog::unify_many_arrays(arrays, [goal] * arrays.size), name
856
858
  end
857
859
 
858
860
  it 'should call unify_arrays_with_no_tails when there are no Arrays with Tails' do
@@ -864,30 +866,30 @@ describe 'Porolog' do
864
866
  [nil, 2, 3, nil],
865
867
  ]
866
868
 
867
- unify_many_arrays(arrays, [goal] * arrays.size)
869
+ Porolog::unify_many_arrays(arrays, [goal] * arrays.size)
868
870
  end
869
871
 
870
872
  it 'should call unify_arrays_with_all_tails when all Arrays have Tails' do
871
873
  expect_unify_arrays_with_calls 0, 0, 1
872
874
 
873
875
  arrays = [
874
- [1, 2, 3, UNKNOWN_TAIL],
876
+ [1, 2, 3, Porolog::UNKNOWN_TAIL],
875
877
  [1, nil, 3, ]/:x,
876
878
  ]
877
879
 
878
- unify_many_arrays(arrays, [goal] * arrays.size)
880
+ Porolog::unify_many_arrays(arrays, [goal] * arrays.size)
879
881
  end
880
882
 
881
883
  it 'should call unify_arrays_with_some_tails when there is a combination of Arrays with and without Tails' do
882
884
  expect_unify_arrays_with_calls 0, 1, 0
883
885
 
884
886
  arrays = [
885
- [1, 2, 3, UNKNOWN_TAIL],
887
+ [1, 2, 3, Porolog::UNKNOWN_TAIL],
886
888
  [1, nil, 3, 4],
887
889
  [nil, 2, 3, nil],
888
890
  ]
889
891
 
890
- unify_many_arrays(arrays, [goal] * arrays.size)
892
+ Porolog::unify_many_arrays(arrays, [goal] * arrays.size)
891
893
  end
892
894
 
893
895
  end
@@ -904,26 +906,26 @@ describe 'Porolog' do
904
906
  # -- Arrays --
905
907
  let(:empty_array) { [] }
906
908
  let(:finite_array) { [1,2,3,4,5] }
907
- let(:array_with_unknown_tail) { [1,2,3,4,5,UNKNOWN_TAIL] }
909
+ let(:array_with_unknown_tail) { [1,2,3,4,5, Porolog::UNKNOWN_TAIL] }
908
910
  let(:array_with_variable_tail) { [1,2,3,4,5]/:tail }
909
- let(:unknown_array) { UNKNOWN_ARRAY }
911
+ let(:unknown_array) { Porolog::UNKNOWN_ARRAY }
910
912
 
911
913
  describe 'when not given an Array' do
912
914
 
913
915
  it 'should return false when given an uninstantiated variable' do
914
- refute has_tail?(variable), name
916
+ refute Porolog::has_tail?(variable), name
915
917
  end
916
918
 
917
919
  it 'should return false when given an Object' do
918
- refute has_tail?(object), name
920
+ refute Porolog::has_tail?(object), name
919
921
  end
920
922
 
921
923
  it 'should return false when given a Symbol' do
922
- refute has_tail?(symbol), name
924
+ refute Porolog::has_tail?(symbol), name
923
925
  end
924
926
 
925
927
  it 'should return false when given an Integer' do
926
- refute has_tail?(integer), name
928
+ refute Porolog::has_tail?(integer), name
927
929
  end
928
930
 
929
931
  end
@@ -931,23 +933,23 @@ describe 'Porolog' do
931
933
  describe 'when given an Array' do
932
934
 
933
935
  it 'should return false when the Array is empty' do
934
- refute has_tail?(empty_array), name
936
+ refute Porolog::has_tail?(empty_array), name
935
937
  end
936
938
 
937
939
  it 'should return false when the last element is atomic' do
938
- refute has_tail?(finite_array), name
940
+ refute Porolog::has_tail?(finite_array), name
939
941
  end
940
942
 
941
943
  it 'should return true when the last element is unknown' do
942
- assert has_tail?(array_with_unknown_tail), name
944
+ assert Porolog::has_tail?(array_with_unknown_tail), name
943
945
  end
944
946
 
945
947
  it 'should return true when the last element is a Tail' do
946
- assert has_tail?(array_with_variable_tail), name
948
+ assert Porolog::has_tail?(array_with_variable_tail), name
947
949
  end
948
950
 
949
951
  it 'should return true when given an unknown array' do
950
- assert has_tail?(unknown_array), name
952
+ assert Porolog::has_tail?(unknown_array), name
951
953
  end
952
954
 
953
955
  describe 'and the array has an instantiated tail' do
@@ -965,7 +967,7 @@ describe 'Porolog' do
965
967
  it 'should return false' do
966
968
  array = goal.variablise([:a, :b, :c, :d]/:e)
967
969
 
968
- refute has_tail?(array, true), name
970
+ refute Porolog::has_tail?(array, true), name
969
971
  end
970
972
 
971
973
  end
@@ -975,7 +977,7 @@ describe 'Porolog' do
975
977
  it 'should return true' do
976
978
  array = goal.variablise([:a, :b, :c, :d]/:e)
977
979
 
978
- assert has_tail?(array, false), name
980
+ assert Porolog::has_tail?(array, false), name
979
981
  end
980
982
 
981
983
  end
@@ -989,27 +991,27 @@ describe 'Porolog' do
989
991
  describe '#expand_splat' do
990
992
 
991
993
  it 'should return an empty array as is' do
992
- assert_equal [], expand_splat([])
994
+ assert_equal [], Porolog::expand_splat([])
993
995
  end
994
996
 
995
997
  it 'should return non-arrays as is' do
996
- assert_equal 5, expand_splat(5)
998
+ assert_equal 5, Porolog::expand_splat(5)
997
999
  end
998
1000
 
999
1001
  it 'should expand an array of just a Tail' do
1000
- assert_equal :t, expand_splat([]/:t)
1002
+ assert_equal :t, Porolog::expand_splat([]/:t)
1001
1003
  end
1002
1004
 
1003
1005
  it 'should not expand an array with a Tail' do
1004
- assert_equal [1,2,3]/:t, expand_splat([1,2,3]/:t)
1006
+ assert_equal [1,2,3]/:t, Porolog::expand_splat([1,2,3]/:t)
1005
1007
  end
1006
1008
 
1007
1009
  it 'should expand a tail' do
1008
- assert_equal [1,2,3,4,5], expand_splat([1,2,3,Tail.new([4,5])])
1010
+ assert_equal [1,2,3,4,5], Porolog::expand_splat([1, 2, 3, Porolog::Tail.new([4,5])])
1009
1011
  end
1010
1012
 
1011
1013
  it 'should expand nested arrays' do
1012
- assert_equal [99, [1,2,3,4], 99], expand_splat([99,[1,2,3,Tail.new([4])],99])
1014
+ assert_equal [99, [1,2,3,4], 99], Porolog::expand_splat([99,[1, 2, 3, Porolog::Tail.new([4])],99])
1013
1015
  end
1014
1016
 
1015
1017
  end
@@ -1030,7 +1032,7 @@ describe 'Porolog' do
1030
1032
  ]
1031
1033
  arrays_goals = goals[0..arrays.size]
1032
1034
 
1033
- assert_nil unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1035
+ assert_nil Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1034
1036
 
1035
1037
  expected_log = [
1036
1038
  'Wrong unification method called: no_tails but one or more of [[1, 2, 3, 4], [1, 2, 3, *:tail], [:w, :x, :y, :z]] has a tail',
@@ -1049,7 +1051,7 @@ describe 'Porolog' do
1049
1051
  ]
1050
1052
  arrays_goals = goals[0...arrays.size]
1051
1053
 
1052
- assert_nil unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1054
+ assert_nil Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1053
1055
 
1054
1056
  # -- First = Last --
1055
1057
  arrays = [
@@ -1061,7 +1063,7 @@ describe 'Porolog' do
1061
1063
  expected_merged = [1,2,3]
1062
1064
  expected_unifications = []
1063
1065
 
1064
- merged, unifications = unify_arrays_with_no_tails(arrays, arrays_goals, [])
1066
+ merged, unifications = Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, [])
1065
1067
 
1066
1068
  assert_equal expected_merged, merged
1067
1069
  assert_equal expected_unifications, unifications
@@ -1073,7 +1075,7 @@ describe 'Porolog' do
1073
1075
  ]
1074
1076
  arrays_goals = goals[0...arrays.size]
1075
1077
 
1076
- assert_nil unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1078
+ assert_nil Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1077
1079
 
1078
1080
  # -- Check Log --
1079
1081
  expected_log = [
@@ -1094,7 +1096,7 @@ describe 'Porolog' do
1094
1096
  ]
1095
1097
  arrays_goals = goals[0...arrays.size]
1096
1098
 
1097
- merged, unifications = unify_arrays_with_no_tails(arrays, arrays_goals, [])
1099
+ merged, unifications = Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, [])
1098
1100
 
1099
1101
  expected_merged = [1, 2, 3, 4, 5]
1100
1102
  expected_unifications = []
@@ -1111,7 +1113,7 @@ describe 'Porolog' do
1111
1113
  ]
1112
1114
  arrays_goals = goals[0...arrays.size]
1113
1115
 
1114
- assert_nil unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1116
+ assert_nil Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1115
1117
 
1116
1118
  expected_log = [
1117
1119
  'Cannot unify arrays of different lengths: [nil] with [nil, nil, nil, nil] with [nil, nil, nil, nil, nil, nil]',
@@ -1130,7 +1132,7 @@ describe 'Porolog' do
1130
1132
  ]
1131
1133
  arrays_goals = goals[0...arrays.size]
1132
1134
 
1133
- assert_nil unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1135
+ assert_nil Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1134
1136
 
1135
1137
  expected_log = [
1136
1138
  'Cannot unify incompatible values: 1 with 8',
@@ -1149,7 +1151,7 @@ describe 'Porolog' do
1149
1151
  ]
1150
1152
  arrays_goals = goals[0...arrays.size]
1151
1153
 
1152
- merged, unifications = unify_arrays_with_no_tails(arrays, arrays_goals, [])
1154
+ merged, unifications = Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, [])
1153
1155
 
1154
1156
  expected_merged = [1, 2, nil, 4, nil]
1155
1157
  expected_unifications = [
@@ -1173,7 +1175,7 @@ describe 'Porolog' do
1173
1175
  ]
1174
1176
  missing_goals = [nil, nil, nil]
1175
1177
 
1176
- merged, unifications = unify_arrays_with_no_tails(arrays, missing_goals, [])
1178
+ merged, unifications = Porolog::unify_arrays_with_no_tails(arrays, missing_goals, [])
1177
1179
 
1178
1180
  expected_merged = [1, 2, 3, 4, 5]
1179
1181
  expected_unifications = [
@@ -1196,7 +1198,7 @@ describe 'Porolog' do
1196
1198
 
1197
1199
  arrays_goals = [g1, nil, nil]
1198
1200
 
1199
- merged, unifications = unify_arrays_with_no_tails(arrays, arrays_goals, [])
1201
+ merged, unifications = Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, [])
1200
1202
 
1201
1203
  expected_merged = [1, 2, 3, [90, 91, 92, 93], 5]
1202
1204
  expected_unifications = [
@@ -1220,7 +1222,7 @@ describe 'Porolog' do
1220
1222
 
1221
1223
  arrays_goals = [g1, nil, nil]
1222
1224
 
1223
- assert_nil unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1225
+ assert_nil Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1224
1226
 
1225
1227
  expected_log = [
1226
1228
  'Cannot unify incompatible values: 92.1 with 92',
@@ -1234,7 +1236,7 @@ describe 'Porolog' do
1234
1236
 
1235
1237
  it 'should not expand variables when they are instantiated to the unknown array' do
1236
1238
  arrays_goals = goals[0...4]
1237
- g4.instantiate :z, UNKNOWN_ARRAY
1239
+ g4.instantiate :z, Porolog::UNKNOWN_ARRAY
1238
1240
  arrays = [
1239
1241
  [1, 2, nil, nil, nil],
1240
1242
  [:j, :n, :n, 4, nil],
@@ -1242,9 +1244,9 @@ describe 'Porolog' do
1242
1244
  :z
1243
1245
  ]
1244
1246
 
1245
- assert_equal UNKNOWN_ARRAY, g4[:z].value
1247
+ assert_equal Porolog::UNKNOWN_ARRAY, g4[:z].value
1246
1248
 
1247
- merged, unifications = unify_arrays_with_no_tails(arrays, arrays_goals, [])
1249
+ merged, unifications = Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, [])
1248
1250
 
1249
1251
  expected_merged = [1, 2, nil, 4, g3[:z]]
1250
1252
  expected_unifications = [
@@ -1265,7 +1267,7 @@ describe 'Porolog' do
1265
1267
 
1266
1268
  it 'should not expand variables when they are instantiated to the unknown tail' do
1267
1269
  arrays_goals = goals[0...4]
1268
- g4.instantiate :z, UNKNOWN_TAIL
1270
+ g4.instantiate :z, Porolog::UNKNOWN_TAIL
1269
1271
  arrays = [
1270
1272
  [1, 2, nil, nil, nil],
1271
1273
  [:j, :n, :n, 4, nil],
@@ -1275,7 +1277,7 @@ describe 'Porolog' do
1275
1277
 
1276
1278
  assert_equal g4[:z], g4[:z].value
1277
1279
 
1278
- merged, unifications = unify_arrays_with_no_tails(arrays, arrays_goals, [])
1280
+ merged, unifications = Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, [])
1279
1281
 
1280
1282
  expected_merged = [1, 2, nil, 4, nil]
1281
1283
  expected_unifications = [
@@ -1301,12 +1303,12 @@ describe 'Porolog' do
1301
1303
  arrays = [
1302
1304
  [ nil, 2, nil, :gi, nil],
1303
1305
  g2.value([1, nil, 3, [90, nil, nil, nil], nil]),
1304
- g3.value([nil, :x, nil, [nil, nil, UNKNOWN_ARRAY, :gy], 5]),
1306
+ g3.value([nil, :x, nil, [nil, nil, Porolog::UNKNOWN_ARRAY, :gy], 5]),
1305
1307
  ]
1306
1308
 
1307
1309
  arrays_goals = [g1, nil, nil]
1308
1310
 
1309
- assert_nil unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1311
+ assert_nil Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1310
1312
 
1311
1313
  expected_log = [
1312
1314
  'Cannot unify incompatible values: 92.1 with [...]',
@@ -1330,7 +1332,7 @@ describe 'Porolog' do
1330
1332
  ]
1331
1333
  arrays_goals = goals[0...arrays.size]
1332
1334
 
1333
- assert_nil unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1335
+ assert_nil Porolog::unify_arrays_with_no_tails(arrays, arrays_goals, []), name
1334
1336
 
1335
1337
  assert_equal [
1336
1338
  'Cannot unify: [Goal1.:a] with [Goal2.2] with [Goal3.3]',
@@ -1360,12 +1362,12 @@ describe 'Porolog' do
1360
1362
 
1361
1363
  it 'should not unify a finite array with an array with a tail that has more finite elements' do
1362
1364
  arrays = [
1363
- [nil, nil, nil, nil, UNKNOWN_TAIL],
1365
+ [nil, nil, nil, nil, Porolog::UNKNOWN_TAIL],
1364
1366
  [1, 2, 3]
1365
1367
  ]
1366
1368
  arrays_goals = goals[0...arrays.size]
1367
1369
 
1368
- assert_nil unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1370
+ assert_nil Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1369
1371
 
1370
1372
  expected_log = [
1371
1373
  'Cannot unify enough elements: [nil, nil, nil, nil, ...] with [Goal2.1, Goal2.2, Goal2.3]',
@@ -1377,34 +1379,34 @@ describe 'Porolog' do
1377
1379
 
1378
1380
  it 'should unify a finite array with an array with a tail that has less finite elements' do
1379
1381
  arrays = [
1380
- [nil, nil, UNKNOWN_TAIL],
1382
+ [nil, nil, Porolog::UNKNOWN_TAIL],
1381
1383
  [1, 2, 3]
1382
1384
  ]
1383
1385
  arrays_goals = goals[0...arrays.size]
1384
1386
 
1385
- assert_equal [[1,2,3],[]], unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1387
+ assert_equal [[1,2,3],[]], Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1386
1388
  end
1387
1389
 
1388
1390
  it 'should merge values with an unknown tail' do
1389
1391
  arrays = [
1390
- [1, 2, 3, UNKNOWN_TAIL],
1392
+ [1, 2, 3, Porolog::UNKNOWN_TAIL],
1391
1393
  [nil, nil, nil, 4, nil],
1392
1394
  [nil, nil, nil, nil, 5],
1393
1395
  ]
1394
1396
  arrays_goals = goals[0...arrays.size]
1395
1397
 
1396
- assert_equal [[1,2,3,4,5],[]], unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1398
+ assert_equal [[1,2,3,4,5],[]], Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1397
1399
  end
1398
1400
 
1399
1401
  it 'should return nil when the finite arrays have different sizes' do
1400
1402
  arrays = [
1401
- [nil, UNKNOWN_TAIL],
1403
+ [nil, Porolog::UNKNOWN_TAIL],
1402
1404
  [nil, nil, nil, nil],
1403
1405
  [nil, nil, nil, nil, nil, nil],
1404
1406
  ]
1405
1407
  arrays_goals = goals[0...arrays.size]
1406
1408
 
1407
- assert_nil unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1409
+ assert_nil Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1408
1410
 
1409
1411
  expected_log = [
1410
1412
  'Cannot unify different sizes of arrays: [nil, ...] with [nil, nil, nil, nil] with [nil, nil, nil, nil, nil, nil]',
@@ -1417,13 +1419,13 @@ describe 'Porolog' do
1417
1419
 
1418
1420
  it 'should return nil when the arrays have incompatible values' do
1419
1421
  arrays = [
1420
- [1, 2, 3, UNKNOWN_TAIL],
1422
+ [1, 2, 3, Porolog::UNKNOWN_TAIL],
1421
1423
  [nil, nil, nil, 4, nil],
1422
1424
  [5, nil, nil, nil, 5],
1423
1425
  ]
1424
1426
  arrays_goals = goals[0...arrays.size]
1425
1427
 
1426
- assert_nil unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1428
+ assert_nil Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1427
1429
 
1428
1430
  expected_log = [
1429
1431
  'Cannot unify enough elements: Goal1.1 with Goal3.5',
@@ -1436,13 +1438,13 @@ describe 'Porolog' do
1436
1438
 
1437
1439
  it 'should return necessary unification to unify variables' do
1438
1440
  arrays = [
1439
- [1, 2, nil, UNKNOWN_TAIL],
1441
+ [1, 2, nil, Porolog::UNKNOWN_TAIL],
1440
1442
  [:j, :n, :n, 4, nil],
1441
1443
  [:x, nil, :m, :y, :z],
1442
1444
  ]
1443
1445
  arrays_goals = goals[0...arrays.size]
1444
1446
 
1445
- merged, unifications = unify_arrays_with_some_tails(arrays, arrays_goals, [])
1447
+ merged, unifications = Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, [])
1446
1448
 
1447
1449
  expected_merged = [1, 2, nil, 4, g3[:z]]
1448
1450
  expected_unifications = [
@@ -1459,16 +1461,16 @@ describe 'Porolog' do
1459
1461
 
1460
1462
  it 'should handle a range of cases' do
1461
1463
  [
1462
- [[[], [1,UNKNOWN_TAIL] ], nil, ['Cannot unify enough elements: [] with [Goal2.1, ...]']],
1463
- [[[]/:t, [1] ], [[1], [[g1.variable(:t), [1], g1, g2]]]],
1464
- [[[], [1,2]/:s ], nil, ['Cannot unify enough elements: [] with [Goal2.1, Goal2.2, *Goal2.:s]']],
1465
- [[[]/:t, [1,2] ], [[1,2], [[g1.variable(:t), [1,2], g1, g2]]]],
1466
- [[[1,2,3], [1,UNKNOWN_TAIL] ], [[1,2,3],[]]],
1467
- [[[1,2,3,UNKNOWN_TAIL], [1] ], nil, ['Cannot unify enough elements: [Goal1.1, Goal1.2, Goal1.3, ...] with [Goal2.1]']],
1468
- [[[1], [1,2,3,UNKNOWN_TAIL] ], nil, ['Cannot unify enough elements: [Goal1.1] with [Goal2.1, Goal2.2, Goal2.3, ...]']],
1469
- [[[1]/:z, [1,2,3] ], [[1,2,3], [[g1.variable(:z), [2, 3], g1, g2]]]],
1470
- [[[:x,:y,:z], [1,2,3,4,UNKNOWN_TAIL]], nil, ['Cannot unify enough elements: [Goal1.:x, Goal1.:y, Goal1.:z] with [Goal2.1, Goal2.2, Goal2.3, Goal2.4, ...]']],
1471
- [[[:x,:y,:z,UNKNOWN_TAIL], [1,2,3,4] ], [
1464
+ [[[], [1,Porolog::UNKNOWN_TAIL] ], nil, ['Cannot unify enough elements: [] with [Goal2.1, ...]']],
1465
+ [[[]/:t, [1] ], [[1], [[g1.variable(:t), [1], g1, g2]]]],
1466
+ [[[], [1,2]/:s ], nil, ['Cannot unify enough elements: [] with [Goal2.1, Goal2.2, *Goal2.:s]']],
1467
+ [[[]/:t, [1,2] ], [[1,2], [[g1.variable(:t), [1,2], g1, g2]]]],
1468
+ [[[1,2,3], [1,Porolog::UNKNOWN_TAIL] ], [[1,2,3],[]]],
1469
+ [[[1,2,3,Porolog::UNKNOWN_TAIL], [1] ], nil, ['Cannot unify enough elements: [Goal1.1, Goal1.2, Goal1.3, ...] with [Goal2.1]']],
1470
+ [[[1], [1,2,3,Porolog::UNKNOWN_TAIL] ], nil, ['Cannot unify enough elements: [Goal1.1] with [Goal2.1, Goal2.2, Goal2.3, ...]']],
1471
+ [[[1]/:z, [1,2,3] ], [[1,2,3], [[g1.variable(:z), [2, 3], g1, g2]]]],
1472
+ [[[:x,:y,:z], [1,2,3,4,Porolog::UNKNOWN_TAIL]], nil, ['Cannot unify enough elements: [Goal1.:x, Goal1.:y, Goal1.:z] with [Goal2.1, Goal2.2, Goal2.3, Goal2.4, ...]']],
1473
+ [[[:x,:y,:z,Porolog::UNKNOWN_TAIL], [1,2,3,4] ], [
1472
1474
  [1,2,3,4],
1473
1475
  [
1474
1476
  [g1.variable(:x), g2.value(1), g1, g2],
@@ -1479,7 +1481,7 @@ describe 'Porolog' do
1479
1481
  ].each do |arrays, expected, expected_log|
1480
1482
  arrays_goals = goals[0...arrays.size]
1481
1483
 
1482
- result = unify_arrays_with_some_tails(arrays, arrays_goals, [])
1484
+ result = Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, [])
1483
1485
 
1484
1486
  if expected.nil?
1485
1487
  assert_nil result
@@ -1496,13 +1498,13 @@ describe 'Porolog' do
1496
1498
 
1497
1499
  it 'should raise a no goal error when no goals are supplied and the arrays have no embedded goals' do
1498
1500
  arrays = [
1499
- [nil, nil, nil, nil, UNKNOWN_TAIL],
1501
+ [nil, nil, nil, nil, Porolog::UNKNOWN_TAIL],
1500
1502
  [1, 2, 3]
1501
1503
  ]
1502
1504
  arrays_goals = [nil] * arrays.size
1503
1505
 
1504
1506
  error = assert_raises Porolog::NoGoalError do
1505
- unify_arrays_with_some_tails(arrays, arrays_goals, [])
1507
+ Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, [])
1506
1508
  end
1507
1509
 
1508
1510
  assert_equal '[nil, nil, nil, nil, ...] has no associated goal! Cannot variablise!', error.message
@@ -1511,14 +1513,14 @@ describe 'Porolog' do
1511
1513
  it 'should derive goals from embedded goals when the goals are not supplied' do
1512
1514
  arrays_goals = [g1, nil]
1513
1515
  arrays = [
1514
- [nil, nil, nil, nil, UNKNOWN_TAIL],
1516
+ [nil, nil, nil, nil, Porolog::UNKNOWN_TAIL],
1515
1517
  [1, 2, g2[3], 4]
1516
1518
  ]
1517
1519
 
1518
- refute arrays.all?{|array| has_tail?(array, false) }, "not all arrays should have a tail"
1519
- refute arrays.all?{|array| !has_tail?(array, false) }, "not all arrays should not have a tail"
1520
+ refute arrays.all?{|array| Porolog::has_tail?(array, false) }, "not all arrays should have a tail"
1521
+ refute arrays.all?{|array| !Porolog::has_tail?(array, false) }, "not all arrays should not have a tail"
1520
1522
 
1521
- merged, unifications = unify_arrays_with_some_tails(arrays, arrays_goals, [])
1523
+ merged, unifications = Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, [])
1522
1524
 
1523
1525
  expected_merged = [1,2,3,4]
1524
1526
  expected_unifications = [
@@ -1535,10 +1537,10 @@ describe 'Porolog' do
1535
1537
  ]
1536
1538
  arrays_goals = goals[0...arrays.size]
1537
1539
 
1538
- refute arrays.all?{|array| has_tail?(array, false) }, "not all arrays should have a tail"
1539
- refute arrays.all?{|array| !has_tail?(array, false) }, "not all arrays should not have a tail"
1540
+ refute arrays.all?{|array| Porolog::has_tail?(array, false) }, "not all arrays should have a tail"
1541
+ refute arrays.all?{|array| !Porolog::has_tail?(array, false) }, "not all arrays should not have a tail"
1540
1542
 
1541
- merged, unifications = unify_arrays_with_some_tails(arrays, arrays_goals, [])
1543
+ merged, unifications = Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, [])
1542
1544
 
1543
1545
  expected_merged = [1,2,3,4,5]
1544
1546
  expected_unifications = [
@@ -1558,10 +1560,10 @@ describe 'Porolog' do
1558
1560
  ]
1559
1561
  arrays_goals = goals[0...arrays.size]
1560
1562
 
1561
- refute arrays.all?{|array| has_tail?(array, false) }, "not all arrays should have a tail"
1562
- refute arrays.all?{|array| !has_tail?(array, false) }, "not all arrays should not have a tail"
1563
+ refute arrays.all?{|array| Porolog::has_tail?(array, false) }, "not all arrays should have a tail"
1564
+ refute arrays.all?{|array| !Porolog::has_tail?(array, false) }, "not all arrays should not have a tail"
1563
1565
 
1564
- merged, unifications = unify_arrays_with_some_tails(arrays, arrays_goals, [])
1566
+ merged, unifications = Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, [])
1565
1567
 
1566
1568
  expected_merged = [1,2,3,4,5,6,7]
1567
1569
  expected_unifications = [
@@ -1583,10 +1585,10 @@ describe 'Porolog' do
1583
1585
  ]
1584
1586
  arrays_goals = goals[0...arrays.size]
1585
1587
 
1586
- refute arrays.all?{|array| has_tail?(array, false) }, "not all arrays should have a tail"
1587
- refute arrays.all?{|array| !has_tail?(array, false) }, "not all arrays should not have a tail"
1588
+ refute arrays.all?{|array| Porolog::has_tail?(array, false) }, "not all arrays should have a tail"
1589
+ refute arrays.all?{|array| !Porolog::has_tail?(array, false) }, "not all arrays should not have a tail"
1588
1590
 
1589
- assert_nil unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1591
+ assert_nil Porolog::unify_arrays_with_some_tails(arrays, arrays_goals, []), name
1590
1592
 
1591
1593
  assert_equal [
1592
1594
  'Cannot unify non-variables: 2 with 3'
@@ -1610,17 +1612,17 @@ describe 'Porolog' do
1610
1612
  let(:g3) { new_goal(:r, :s, :t) }
1611
1613
  let(:goals) { [g1, g2, g3] }
1612
1614
 
1613
- let(:array_with_tail_1) { [1, 2, Tail.new(:h)] }
1615
+ let(:array_with_tail_1) { [1, 2, Porolog::Tail.new(:h)] }
1614
1616
  let(:array_with_tail_2) { [:h, :b]/:t }
1615
- let(:array_with_tail_3) { [:x, :y, UNKNOWN_TAIL] }
1616
- let(:head_and_tail_1) { [1, Tail.new([2,3])] }
1617
+ let(:array_with_tail_3) { [:x, :y, Porolog::UNKNOWN_TAIL] }
1618
+ let(:head_and_tail_1) { [1, Porolog::Tail.new([2,3])] }
1617
1619
  let(:head_and_tail_2) { [:h]/:t }
1618
- let(:head_and_tail_3) { [:x, UNKNOWN_TAIL] }
1620
+ let(:head_and_tail_3) { [:x, Porolog::UNKNOWN_TAIL] }
1619
1621
 
1620
1622
  it 'should call unify_tail_with_tail when no array is headtail' do
1621
- expects(:unify_tail_with_tail).times(1)
1622
- expects(:unify_headtail_with_tail).times(0)
1623
- expects(:unify_headtail_with_headtail).times(0)
1623
+ Porolog::expects(:unify_tail_with_tail).times(1)
1624
+ Porolog::expects(:unify_headtail_with_tail).times(0)
1625
+ Porolog::expects(:unify_headtail_with_headtail).times(0)
1624
1626
 
1625
1627
  arrays = [
1626
1628
  array_with_tail_1,
@@ -1629,13 +1631,13 @@ describe 'Porolog' do
1629
1631
  ]
1630
1632
  arrays_goals = goals[0...arrays.size]
1631
1633
 
1632
- unify_arrays_with_all_tails(arrays, arrays_goals, [])
1634
+ Porolog::unify_arrays_with_all_tails(arrays, arrays_goals, [])
1633
1635
  end
1634
1636
 
1635
1637
  it 'should call unify_headtail_with_tail when all arrays but one are headtail' do
1636
- expects(:unify_tail_with_tail).times(0)
1637
- expects(:unify_headtail_with_tail).times(1)
1638
- expects(:unify_headtail_with_headtail).times(0)
1638
+ Porolog::expects(:unify_tail_with_tail).times(0)
1639
+ Porolog::expects(:unify_headtail_with_tail).times(1)
1640
+ Porolog::expects(:unify_headtail_with_headtail).times(0)
1639
1641
 
1640
1642
  arrays = [
1641
1643
  array_with_tail_1,
@@ -1644,20 +1646,20 @@ describe 'Porolog' do
1644
1646
  ]
1645
1647
  arrays_goals = goals[0...arrays.size]
1646
1648
 
1647
- unify_arrays_with_all_tails(arrays, arrays_goals, [])
1649
+ Porolog::unify_arrays_with_all_tails(arrays, arrays_goals, [])
1648
1650
  end
1649
1651
 
1650
1652
  it 'should include unifications of variables in a tail' do
1651
1653
  arrays = [
1652
1654
  [nil, nil, nil]/:list,
1653
- [1, 2, 3, nil, :y, UNKNOWN_TAIL],
1654
- [nil, :x, nil, 4, Tail.new([nil,6])],
1655
+ [1, 2, 3, nil, :y, Porolog::UNKNOWN_TAIL],
1656
+ [nil, :x, nil, 4, Porolog::Tail.new([nil,6])],
1655
1657
  ]
1656
1658
  arrays_goals = goals[0...arrays.size]
1657
1659
 
1658
1660
  g1.instantiate :list, [4,5,:z]
1659
1661
 
1660
- merged, unifications = unify_arrays_with_all_tails(arrays, arrays_goals, [])
1662
+ merged, unifications = Porolog::unify_arrays_with_all_tails(arrays, arrays_goals, [])
1661
1663
 
1662
1664
  expected_merged = [1,2,3,4,5,6]
1663
1665
  expected_unifications = [
@@ -1672,18 +1674,18 @@ describe 'Porolog' do
1672
1674
  end
1673
1675
 
1674
1676
  it 'should not unify arrays where one embedded variable cannot be unified' do
1675
- g1.instantiate(:a, [g1.value(1), g1.value(2), g1.value(3), UNKNOWN_TAIL])
1677
+ g1.instantiate(:a, [g1.value(1), g1.value(2), g1.value(3), Porolog::UNKNOWN_TAIL])
1676
1678
  g2.instantiate(:a, :b)
1677
1679
  g3.instantiate(:a, :b)
1678
1680
 
1679
1681
  arrays = [
1680
1682
  :a,
1681
- [:a,Tail.new([1])],
1682
- [:a, UNKNOWN_TAIL],
1683
+ [:a, Porolog::Tail.new([1])],
1684
+ [:a, Porolog::UNKNOWN_TAIL],
1683
1685
  ]
1684
1686
  arrays_goals = goals[0...arrays.size]
1685
1687
 
1686
- assert_nil unify_arrays_with_all_tails(arrays, arrays_goals, []), name
1688
+ assert_nil Porolog::unify_arrays_with_all_tails(arrays, arrays_goals, []), name
1687
1689
 
1688
1690
  assert_equal [
1689
1691
  'Cannot unify enough elements: Goal1.[Goal1.1, Goal1.2, Goal1.3, ...] with [Goal2.:a, Goal2.1]',
@@ -1705,8 +1707,8 @@ describe 'Porolog' do
1705
1707
  it 'should unify arrays where all embedded variables can be unified' do
1706
1708
  arrays = [
1707
1709
  [g1.variable(:a), g1.value(2), g1.variable(:c), g1.value(4)],
1708
- [g2.value(1), g1.variable(:b), g2.value(3), UNKNOWN_TAIL],
1709
- [:a, :b, Tail.new([3,:d])],
1710
+ [g2.value(1), g1.variable(:b), g2.value(3), Porolog::UNKNOWN_TAIL],
1711
+ [:a, :b, Porolog::Tail.new([3,:d])],
1710
1712
  ]
1711
1713
  arrays_goals = goals[0...arrays.size]
1712
1714
 
@@ -1724,7 +1726,7 @@ describe 'Porolog' do
1724
1726
  [g1.variable(:c), g3.value(3), g1, g3],
1725
1727
  [g3.variable(:d), g1.value(4), g3, g1]
1726
1728
  ]
1727
- merged, unifications = unify_arrays_with_all_tails(arrays, arrays_goals, [])
1729
+ merged, unifications = Porolog::unify_arrays_with_all_tails(arrays, arrays_goals, [])
1728
1730
 
1729
1731
  assert_equal [], g1.log
1730
1732
  assert_equal [], g2.log
@@ -1748,7 +1750,7 @@ describe 'Porolog' do
1748
1750
  expected_unifications = [
1749
1751
  [:e, [[1], [2], [3], [4]], g1, g2]
1750
1752
  ]
1751
- merged, unifications = unify_arrays_with_all_tails(arrays, arrays_goals, [])
1753
+ merged, unifications = Porolog::unify_arrays_with_all_tails(arrays, arrays_goals, [])
1752
1754
 
1753
1755
  assert_equal [], g1.log
1754
1756
  assert_equal [], g2.log
@@ -1770,15 +1772,15 @@ describe 'Porolog' do
1770
1772
 
1771
1773
  it 'should reject a non-headtail array' do
1772
1774
  arrays = [
1773
- [1,Tail.new([2,3])],
1775
+ [1, Porolog::Tail.new([2,3])],
1774
1776
  [4],
1775
- [7,UNKNOWN_TAIL],
1777
+ [7, Porolog::UNKNOWN_TAIL],
1776
1778
  ]
1777
1779
  arrays_goals = goals[0...arrays.size]
1778
1780
 
1779
1781
  refute arrays.all?(&:headtail?)
1780
1782
 
1781
- assert_nil unify_tail_with_tail(arrays, arrays_goals, [])
1783
+ assert_nil Porolog::unify_tail_with_tail(arrays, arrays_goals, [])
1782
1784
 
1783
1785
  msg = 'Wrong method called to unify [[1, *[2, 3]], [4], [7, ...]]'
1784
1786
 
@@ -1789,16 +1791,16 @@ describe 'Porolog' do
1789
1791
 
1790
1792
  it 'should process more than two arrays that are a non-headtail' do
1791
1793
  arrays = [
1792
- [1, 2, Tail.new([3,4])],
1794
+ [1, 2, Porolog::Tail.new([3,4])],
1793
1795
  [:a, :b]/:c,
1794
- [:d, :e, UNKNOWN_TAIL],
1796
+ [:d, :e, Porolog::UNKNOWN_TAIL],
1795
1797
  ]
1796
1798
  arrays_goals = goals[0...arrays.size]
1797
1799
 
1798
- assert arrays.all?{|array| has_tail?(array, false) }
1800
+ assert arrays.all?{|array| Porolog::has_tail?(array, false) }
1799
1801
  assert arrays.map(&:headtail?).map(&:!).all?
1800
1802
 
1801
- merged, unifications = unify_tail_with_tail(arrays, arrays_goals, [])
1803
+ merged, unifications = Porolog::unify_tail_with_tail(arrays, arrays_goals, [])
1802
1804
 
1803
1805
  expected_merged = [1,2,3,4]
1804
1806
 
@@ -1818,16 +1820,16 @@ describe 'Porolog' do
1818
1820
 
1819
1821
  it 'should unify arrays of different lengths' do
1820
1822
  arrays = [
1821
- [1, 2, UNKNOWN_TAIL],
1822
- [nil, nil, 3, 4, UNKNOWN_TAIL],
1823
- [nil, nil, nil, nil, 5, 6, UNKNOWN_TAIL],
1823
+ [1, 2, Porolog::UNKNOWN_TAIL],
1824
+ [nil, nil, 3, 4, Porolog::UNKNOWN_TAIL],
1825
+ [nil, nil, nil, nil, 5, 6, Porolog::UNKNOWN_TAIL],
1824
1826
  ]
1825
1827
  arrays_goals = goals[0...arrays.size]
1826
1828
 
1827
- assert arrays.all?{|array| has_tail?(array) }
1829
+ assert arrays.all?{|array| Porolog::has_tail?(array) }
1828
1830
  assert arrays.map(&:headtail?).map(&:!).all?
1829
1831
 
1830
- merged, unifications = unify_tail_with_tail(arrays, arrays_goals, [])
1832
+ merged, unifications = Porolog::unify_tail_with_tail(arrays, arrays_goals, [])
1831
1833
 
1832
1834
  expected_merged = [
1833
1835
  g1.value(1),
@@ -1836,7 +1838,7 @@ describe 'Porolog' do
1836
1838
  g2.value(4),
1837
1839
  g3.value(5),
1838
1840
  g3.value(6),
1839
- UNKNOWN_TAIL,
1841
+ Porolog::UNKNOWN_TAIL,
1840
1842
  ]
1841
1843
 
1842
1844
  expected_unifications = [
@@ -1855,12 +1857,12 @@ describe 'Porolog' do
1855
1857
  ]
1856
1858
  arrays_goals = goals[0...arrays.size]
1857
1859
 
1858
- assert arrays.all?{|array| has_tail?(array) }
1860
+ assert arrays.all?{|array| Porolog::has_tail?(array) }
1859
1861
  assert arrays.map(&:headtail?).map(&:!).all?
1860
1862
 
1861
- merged, unifications = unify_tail_with_tail(arrays, arrays_goals, [])
1863
+ merged, unifications = Porolog::unify_tail_with_tail(arrays, arrays_goals, [])
1862
1864
 
1863
- expected_merged = [nil, nil, UNKNOWN_TAIL]
1865
+ expected_merged = [nil, nil, Porolog::UNKNOWN_TAIL]
1864
1866
 
1865
1867
  expected_unifications = [
1866
1868
  [g1[:a], g2[:d], g1, g2],
@@ -1889,15 +1891,15 @@ describe 'Porolog' do
1889
1891
 
1890
1892
  it 'should not unify ununifiable arrays' do
1891
1893
  arrays = [
1892
- [1,2,3,4,UNKNOWN_TAIL],
1893
- [1,4,3,2,UNKNOWN_TAIL],
1894
+ [1, 2, 3, 4, Porolog::UNKNOWN_TAIL],
1895
+ [1, 4, 3, 2, Porolog::UNKNOWN_TAIL],
1894
1896
  ]
1895
1897
  arrays_goals = goals[0...arrays.size]
1896
1898
 
1897
- assert arrays.all?{|array| has_tail?(array) }
1899
+ assert arrays.all?{|array| Porolog::has_tail?(array) }
1898
1900
  assert arrays.map(&:headtail?).map(&:!).all?
1899
1901
 
1900
- assert_nil unify_tail_with_tail(arrays, arrays_goals, []), name
1902
+ assert_nil Porolog::unify_tail_with_tail(arrays, arrays_goals, []), name
1901
1903
 
1902
1904
  expected_log = [
1903
1905
  'Cannot unify incompatible values: 2 with 4',
@@ -1921,15 +1923,15 @@ describe 'Porolog' do
1921
1923
 
1922
1924
  it 'should reject a non-tail array' do
1923
1925
  arrays = [
1924
- [1,Tail.new([2,3])],
1926
+ [1, Porolog::Tail.new([2,3])],
1925
1927
  [4],
1926
- [1,2,3,7,UNKNOWN_TAIL],
1928
+ [1, 2, 3, 7, Porolog::UNKNOWN_TAIL],
1927
1929
  ]
1928
1930
  arrays_goals = goals[0...arrays.size]
1929
1931
 
1930
- refute arrays.all?{|array| has_tail?(array) }
1932
+ refute arrays.all?{|array| Porolog::has_tail?(array) }
1931
1933
 
1932
- assert_nil unify_headtail_with_tail(arrays, arrays_goals, [])
1934
+ assert_nil Porolog::unify_headtail_with_tail(arrays, arrays_goals, [])
1933
1935
 
1934
1936
  msg = 'Wrong method called to unify [[1, *[2, 3]], [4], [1, 2, 3, 7, ...]]'
1935
1937
 
@@ -1940,16 +1942,16 @@ describe 'Porolog' do
1940
1942
 
1941
1943
  it 'should unify more than two arrays that have a tail' do
1942
1944
  arrays = [
1943
- [1, Tail.new([2,3])],
1945
+ [1, Porolog::Tail.new([2,3])],
1944
1946
  [:a, :b]/:f,
1945
- [:c, UNKNOWN_TAIL],
1946
- [:d, :e, UNKNOWN_TAIL]
1947
+ [:c, Porolog::UNKNOWN_TAIL],
1948
+ [:d, :e, Porolog::UNKNOWN_TAIL]
1947
1949
  ]
1948
1950
  arrays_goals = goals[0...arrays.size]
1949
1951
 
1950
- assert arrays.all?{|array| has_tail?(array, false) }
1952
+ assert arrays.all?{|array| Porolog::has_tail?(array, false) }
1951
1953
 
1952
- merged, unifications = unify_headtail_with_tail(arrays, arrays_goals, [])
1954
+ merged, unifications = Porolog::unify_headtail_with_tail(arrays, arrays_goals, [])
1953
1955
 
1954
1956
  expected_merged = [1,2,3]
1955
1957
 
@@ -1972,18 +1974,18 @@ describe 'Porolog' do
1972
1974
 
1973
1975
  it 'should unify unifiable arrays with different length tails' do
1974
1976
  arrays = [
1975
- [1, UNKNOWN_TAIL],
1977
+ [1, Porolog::UNKNOWN_TAIL],
1976
1978
  [:a, :b, :c, :d]/:f,
1977
- [:c, UNKNOWN_TAIL],
1978
- [:d, 2, UNKNOWN_TAIL]
1979
+ [:c, Porolog::UNKNOWN_TAIL],
1980
+ [:d, 2, Porolog::UNKNOWN_TAIL]
1979
1981
  ]
1980
1982
  arrays_goals = goals[0...arrays.size]
1981
1983
 
1982
- assert arrays.all?{|array| has_tail?(array, false) }
1984
+ assert arrays.all?{|array| Porolog::has_tail?(array, false) }
1983
1985
 
1984
- merged, unifications = unify_headtail_with_tail(arrays, arrays_goals, [])
1986
+ merged, unifications = Porolog::unify_headtail_with_tail(arrays, arrays_goals, [])
1985
1987
 
1986
- expected_merged = [1,2,nil,nil,UNKNOWN_TAIL]
1988
+ expected_merged = [1, 2, nil, nil, Porolog::UNKNOWN_TAIL]
1987
1989
 
1988
1990
  expected_unifications = [
1989
1991
  [g3[:c], g1[1], g3, g1],
@@ -2010,11 +2012,11 @@ describe 'Porolog' do
2010
2012
  ]
2011
2013
  arrays_goals = goals[0...arrays.size]
2012
2014
 
2013
- assert arrays.all?{|array| has_tail?(array, false) }, 'all arrays should have a tail'
2014
- refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2015
- refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2015
+ assert arrays.all?{|array| Porolog::has_tail?(array, false) }, 'all arrays should have a tail'
2016
+ refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2017
+ refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2016
2018
 
2017
- assert_nil unify_headtail_with_tail(arrays, arrays_goals, []), name
2019
+ assert_nil Porolog::unify_headtail_with_tail(arrays, arrays_goals, []), name
2018
2020
 
2019
2021
  assert_equal [
2020
2022
  'Cannot unify because 1 != 2 (variable != variable)',
@@ -2042,11 +2044,11 @@ describe 'Porolog' do
2042
2044
  ]
2043
2045
  arrays_goals = goals[0...arrays.size]
2044
2046
 
2045
- assert arrays.all?{|array| has_tail?(array, false) }, 'all arrays should have a tail'
2046
- refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2047
- refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2047
+ assert arrays.all?{|array| Porolog::has_tail?(array, false) }, 'all arrays should have a tail'
2048
+ refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2049
+ refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2048
2050
 
2049
- assert_nil unify_headtail_with_tail(arrays, arrays_goals, []), name
2051
+ assert_nil Porolog::unify_headtail_with_tail(arrays, arrays_goals, []), name
2050
2052
 
2051
2053
  assert_equal [
2052
2054
  'Cannot unify because [2, 3] != [2, 4] (variable != variable)',
@@ -2077,11 +2079,11 @@ describe 'Porolog' do
2077
2079
  ]
2078
2080
  arrays_goals = goals[0...arrays.size]
2079
2081
 
2080
- assert arrays.all?{|array| has_tail?(array, false) }, 'all arrays should have a tail'
2081
- refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2082
- refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2082
+ assert arrays.all?{|array| Porolog::has_tail?(array, false) }, 'all arrays should have a tail'
2083
+ refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2084
+ refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2083
2085
 
2084
- assert_nil unify_headtail_with_tail(arrays, arrays_goals, []), name
2086
+ assert_nil Porolog::unify_headtail_with_tail(arrays, arrays_goals, []), name
2085
2087
 
2086
2088
  assert_equal [
2087
2089
  ], g1.log
@@ -2107,11 +2109,11 @@ describe 'Porolog' do
2107
2109
  ]
2108
2110
  arrays_goals = goals[0...arrays.size]
2109
2111
 
2110
- assert arrays.all?{|array| has_tail?(array, false) }, 'all arrays should have a tail'
2111
- refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2112
- refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2112
+ assert arrays.all?{|array| Porolog::has_tail?(array, false) }, 'all arrays should have a tail'
2113
+ refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2114
+ refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2113
2115
 
2114
- assert_nil unify_headtail_with_tail(arrays, arrays_goals, []), name
2116
+ assert_nil Porolog::unify_headtail_with_tail(arrays, arrays_goals, []), name
2115
2117
 
2116
2118
  assert_equal [
2117
2119
  ], g1.log
@@ -2139,11 +2141,11 @@ describe 'Porolog' do
2139
2141
  ]
2140
2142
  arrays_goals = goals[0...arrays.size]
2141
2143
 
2142
- assert arrays.all?{|array| has_tail?(array, false) }, 'all arrays should have a tail'
2143
- refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2144
- refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2144
+ assert arrays.all?{|array| Porolog::has_tail?(array, false) }, 'all arrays should have a tail'
2145
+ refute arrays.map(&:headtail?).all?, 'not all arrays should be a headtail array'
2146
+ refute arrays.map(&:headtail?).map(&:!).all?, 'not all arrays should be an array with a tail'
2145
2147
 
2146
- assert_nil unify_headtail_with_tail(arrays, arrays_goals, []), name
2148
+ assert_nil Porolog::unify_headtail_with_tail(arrays, arrays_goals, []), name
2147
2149
 
2148
2150
  assert_equal [
2149
2151
  'Cannot unify incompatible values: 3 with 2',
@@ -2173,11 +2175,11 @@ describe 'Porolog' do
2173
2175
  g1.instantiate :t, [1,2,3]
2174
2176
  arrays = [
2175
2177
  :h/:t,
2176
- UNKNOWN_ARRAY,
2178
+ Porolog::UNKNOWN_ARRAY,
2177
2179
  ]
2178
2180
  arrays_goals = goals[0...arrays.size]
2179
2181
 
2180
- merged, unifications = unify_headtail_with_tail(arrays, arrays_goals, [])
2182
+ merged, unifications = Porolog::unify_headtail_with_tail(arrays, arrays_goals, [])
2181
2183
 
2182
2184
  expected_merged = [nil, 1, 2, 3]
2183
2185
  expected_unifications = []
@@ -2198,15 +2200,15 @@ describe 'Porolog' do
2198
2200
 
2199
2201
  it 'should reject a non-headtail array' do
2200
2202
  arrays = [
2201
- [1,Tail.new([2,3])],
2203
+ [1, Porolog::Tail.new([2,3])],
2202
2204
  [4],
2203
- [7,UNKNOWN_TAIL],
2205
+ [7, Porolog::UNKNOWN_TAIL],
2204
2206
  ]
2205
2207
  arrays_goals = goals[0...arrays.size]
2206
2208
 
2207
2209
  refute arrays.all?(&:headtail?)
2208
2210
 
2209
- assert_nil unify_headtail_with_headtail(arrays, arrays_goals, [])
2211
+ assert_nil Porolog::unify_headtail_with_headtail(arrays, arrays_goals, [])
2210
2212
 
2211
2213
  msg = 'Wrong method called to unify [[1, *[2, 3]], [4], [7, ...]]'
2212
2214
 
@@ -2217,15 +2219,15 @@ describe 'Porolog' do
2217
2219
 
2218
2220
  it 'should not unify unequal heads' do
2219
2221
  arrays = [
2220
- [1,Tail.new([2,3])],
2222
+ [1, Porolog::Tail.new([2,3])],
2221
2223
  [4]/:y,
2222
- [7,UNKNOWN_TAIL],
2224
+ [7, Porolog::UNKNOWN_TAIL],
2223
2225
  ]
2224
2226
  arrays_goals = goals[0...arrays.size]
2225
2227
 
2226
2228
  assert arrays.all?(&:headtail?), "arrays should all be headtails: #{arrays.reject(&:headtail?).map(&:inspect).join(' and ')}"
2227
2229
 
2228
- assert_nil unify_headtail_with_headtail(arrays, arrays_goals, [])
2230
+ assert_nil Porolog::unify_headtail_with_headtail(arrays, arrays_goals, [])
2229
2231
 
2230
2232
  assert_equal [
2231
2233
  'Cannot unify because 1 != 4 (atomic != atomic)',
@@ -2241,24 +2243,24 @@ describe 'Porolog' do
2241
2243
 
2242
2244
  it 'should process more than two arrays that are a headtail' do
2243
2245
  arrays = [
2244
- [1, Tail.new([2,3])],
2246
+ [1, Porolog::Tail.new([2,3])],
2245
2247
  [:a]/:f,
2246
- [:c, UNKNOWN_TAIL],
2248
+ [:c, Porolog::UNKNOWN_TAIL],
2247
2249
  ]
2248
2250
  arrays_goals = goals[0...arrays.size]
2249
2251
 
2250
2252
  assert arrays.all?(&:headtail?)
2251
2253
 
2252
- merged, unifications = unify_headtail_with_headtail(arrays, arrays_goals, [])
2254
+ merged, unifications = Porolog::unify_headtail_with_headtail(arrays, arrays_goals, [])
2253
2255
 
2254
2256
  expected_merged = [1,2,3]
2255
2257
 
2256
2258
  expected_unifications = [
2257
- [:a, 1, g2, g1],
2258
- [:f, [2,3], g2, g1],
2259
- [:c, 1, g3, g1],
2260
- [:a, :c, g2, g3],
2261
- [:f, UNKNOWN_TAIL, g2, g3],
2259
+ [:a, 1, g2, g1],
2260
+ [:f, [2,3], g2, g1],
2261
+ [:c, 1, g3, g1],
2262
+ [:a, :c, g2, g3],
2263
+ [:f, Porolog::UNKNOWN_TAIL, g2, g3],
2262
2264
  ]
2263
2265
 
2264
2266
  assert_equal expected_merged, merged
@@ -2280,9 +2282,9 @@ describe 'Porolog' do
2280
2282
 
2281
2283
  assert arrays.all?(&:headtail?)
2282
2284
 
2283
- merged, unifications = unify_headtail_with_headtail(arrays, arrays_goals, [])
2285
+ merged, unifications = Porolog::unify_headtail_with_headtail(arrays, arrays_goals, [])
2284
2286
 
2285
- expected_merged = [nil, UNKNOWN_TAIL]
2287
+ expected_merged = [nil, Porolog::UNKNOWN_TAIL]
2286
2288
 
2287
2289
  expected_unifications = [
2288
2290
  [:a, :c, g1, g2],
@@ -2313,14 +2315,14 @@ describe 'Porolog' do
2313
2315
 
2314
2316
  it 'should create a Predicate' do
2315
2317
  # -- Precondition Baseline --
2316
- assert_equal 0, Scope[:default].predicates.size
2318
+ assert_equal 0, Porolog::Scope[:default].predicates.size
2317
2319
 
2318
2320
  # -- Test --
2319
- single_predicate = builtin :member
2321
+ single_predicate = Porolog::builtin :member
2320
2322
 
2321
2323
  # -- Compare Result Against Baseline --
2322
- assert_equal 1, Scope[:default].predicates.size
2323
- assert_equal :member, Scope[:default].predicates.first.name
2324
+ assert_equal 1, Porolog::Scope[:default].predicates.size
2325
+ assert_equal :member, Porolog::Scope[:default].predicates.first.name
2324
2326
  assert_Predicate single_predicate, :member, []
2325
2327
  end
2326
2328
 
@@ -2331,7 +2333,7 @@ describe 'Porolog' do
2331
2333
 
2332
2334
  refute respond_to?(:member)
2333
2335
 
2334
- builtin :member
2336
+ Porolog::builtin :member
2335
2337
 
2336
2338
  assert respond_to?(:member)
2337
2339
  assert_Arguments member(:X, ['left','right']), :member, [:X, ['left','right']]
@@ -2340,14 +2342,14 @@ describe 'Porolog' do
2340
2342
  end
2341
2343
 
2342
2344
  it 'should create multiple Predicates' do
2343
- assert_equal 0, Scope[:default].predicates.size
2345
+ assert_equal 0, Porolog::Scope[:default].predicates.size
2344
2346
 
2345
- multiple_predicates = builtin :member, :append, :is
2347
+ multiple_predicates = Porolog::builtin :member, :append, :is
2346
2348
 
2347
- assert_equal 3, Scope[:default].predicates.size
2348
- assert_equal :member, Scope[:default].predicates[0].name
2349
- assert_equal :append, Scope[:default].predicates[1].name
2350
- assert_equal :is, Scope[:default].predicates[2].name
2349
+ assert_equal 3, Porolog::Scope[:default].predicates.size
2350
+ assert_equal :member, Porolog::Scope[:default].predicates[0].name
2351
+ assert_equal :append, Porolog::Scope[:default].predicates[1].name
2352
+ assert_equal :is, Porolog::Scope[:default].predicates[2].name
2351
2353
  assert_instance_of Array, multiple_predicates
2352
2354
  assert_equal 3, multiple_predicates.size
2353
2355
  assert_Predicate multiple_predicates[0], :member, []
@@ -2364,7 +2366,7 @@ describe 'Porolog' do
2364
2366
  refute respond_to?(:member)
2365
2367
  refute respond_to?(:append)
2366
2368
 
2367
- builtin :member, :append
2369
+ Porolog::builtin :member, :append
2368
2370
 
2369
2371
  assert respond_to?(:member)
2370
2372
  assert respond_to?(:append)
@@ -2382,7 +2384,7 @@ describe 'Porolog' do
2382
2384
  refute_includes Base2.methods, :member
2383
2385
  refute_includes Base2.instance_methods, :member
2384
2386
 
2385
- builtin :member, class_base: Base2
2387
+ Porolog::builtin :member, class_base: Base2
2386
2388
 
2387
2389
  assert_includes Base2.methods, :member
2388
2390
  assert_includes Base2.instance_methods, :member
@@ -2412,9 +2414,9 @@ describe 'Porolog' do
2412
2414
 
2413
2415
  it 'should return a different variable on each call' do
2414
2416
  # _ is overridden by MiniTest
2415
- variable1 = Porolog._
2416
- variable2 = Porolog._
2417
- variable3 = Porolog._
2417
+ variable1 = Porolog::_
2418
+ variable2 = Porolog::_
2419
+ variable3 = Porolog::_
2418
2420
 
2419
2421
  assert_equal :_a, variable1
2420
2422
  assert_equal :_b, variable2