mini_kraken 0.1.03 → 0.1.08

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -1
  3. data/CHANGELOG.md +54 -3
  4. data/Gemfile +3 -1
  5. data/README.md +22 -1
  6. data/Rakefile +5 -3
  7. data/lib/mini_kraken.rb +3 -1
  8. data/lib/mini_kraken/core/any_value.rb +9 -7
  9. data/lib/mini_kraken/core/association.rb +20 -7
  10. data/lib/mini_kraken/core/association_walker.rb +5 -1
  11. data/lib/mini_kraken/core/atomic_term.rb +5 -3
  12. data/lib/mini_kraken/core/binary_relation.rb +8 -6
  13. data/lib/mini_kraken/core/composite_goal.rb +46 -0
  14. data/lib/mini_kraken/core/composite_term.rb +7 -20
  15. data/lib/mini_kraken/core/conj2.rb +77 -0
  16. data/lib/mini_kraken/core/cons_cell.rb +51 -41
  17. data/lib/mini_kraken/core/designation.rb +55 -0
  18. data/lib/mini_kraken/core/disj2.rb +71 -0
  19. data/lib/mini_kraken/core/duck_fiber.rb +4 -2
  20. data/lib/mini_kraken/core/environment.rb +25 -11
  21. data/lib/mini_kraken/core/equals.rb +128 -189
  22. data/lib/mini_kraken/core/fail.rb +20 -14
  23. data/lib/mini_kraken/core/freshness.rb +11 -8
  24. data/lib/mini_kraken/core/goal.rb +8 -4
  25. data/lib/mini_kraken/core/goal_arg.rb +10 -0
  26. data/lib/mini_kraken/core/goal_relation.rb +28 -0
  27. data/lib/mini_kraken/core/k_integer.rb +4 -3
  28. data/lib/mini_kraken/core/k_symbol.rb +4 -3
  29. data/lib/mini_kraken/core/nullary_relation.rb +3 -1
  30. data/lib/mini_kraken/core/outcome.rb +29 -25
  31. data/lib/mini_kraken/core/relation.rb +4 -18
  32. data/lib/mini_kraken/core/succeed.rb +20 -14
  33. data/lib/mini_kraken/core/term.rb +7 -2
  34. data/lib/mini_kraken/core/variable.rb +11 -25
  35. data/lib/mini_kraken/core/variable_ref.rb +12 -59
  36. data/lib/mini_kraken/core/vocabulary.rb +267 -48
  37. data/lib/mini_kraken/glue/fresh_env.rb +5 -3
  38. data/lib/mini_kraken/glue/run_star_expression.rb +18 -8
  39. data/lib/mini_kraken/version.rb +3 -1
  40. data/mini_kraken.gemspec +15 -13
  41. data/spec/core/association_spec.rb +4 -4
  42. data/spec/core/association_walker_spec.rb +25 -24
  43. data/spec/core/conj2_spec.rb +114 -0
  44. data/spec/core/cons_cell_spec.rb +12 -3
  45. data/spec/core/disj2_spec.rb +99 -0
  46. data/spec/core/duck_fiber_spec.rb +22 -12
  47. data/spec/core/environment_spec.rb +16 -28
  48. data/spec/core/equals_spec.rb +7 -7
  49. data/spec/core/fail_spec.rb +7 -7
  50. data/spec/core/goal_spec.rb +10 -10
  51. data/spec/core/k_symbol_spec.rb +5 -6
  52. data/spec/core/succeed_spec.rb +4 -4
  53. data/spec/core/variable_ref_spec.rb +0 -4
  54. data/spec/core/vocabulary_spec.rb +33 -27
  55. data/spec/glue/fresh_env_spec.rb +1 -1
  56. data/spec/glue/run_star_expression_spec.rb +213 -60
  57. data/spec/mini_kraken_spec.rb +4 -0
  58. data/spec/spec_helper.rb +3 -2
  59. data/spec/support/factory_methods.rb +20 -2
  60. metadata +12 -2
@@ -25,37 +25,47 @@ module MiniKraken
25
25
 
26
26
  context 'Provided services:' do
27
27
  let(:parent) { Environment.new }
28
-
28
+
29
29
  it 'should behave like a Fiber yielding a failure' do
30
30
  failing = DuckFiber.new(:failure)
31
31
  outcome = nil
32
32
  expect { outcome = failing.resume }.not_to raise_error
33
33
  expect(outcome).to eq(Failure)
34
-
34
+
35
35
  # Only one result should be yielded
36
- expect(failing.resume).to be_nil
36
+ expect(failing.resume).to be_nil
37
37
  end
38
-
38
+
39
39
  it 'should behave like a Fiber yielding a basic success' do
40
40
  succeeding = DuckFiber.new(:success)
41
41
  outcome = nil
42
42
  expect { outcome = succeeding.resume }.not_to raise_error
43
- expect(outcome).to eq(BasicSuccess)
44
-
43
+ expect(outcome).to be_successful
44
+ expect(outcome.parent).to be_nil
45
+
45
46
  # Only one result should be yielded
46
47
  expect(succeeding.resume).to be_nil
47
- end
48
+ end
49
+
50
+ it 'should yield a distinct success object' do
51
+ instance1 = DuckFiber.new(:success)
52
+ outcome1 = instance1.resume
53
+
54
+ instance2 = DuckFiber.new(:success)
55
+ outcome2 = instance1.resume
56
+
57
+ expect(outcome1).not_to be_equal(outcome2)
58
+ end
48
59
 
49
60
  it 'should behave like a Fiber yielding a custom outcome' do
50
-
51
- tailored = DuckFiber.new(:custom) { Outcome.new(:"#s", parent) }
61
+ tailored = DuckFiber.new(:custom) { Outcome.new(:"#s", parent) }
52
62
  outcome = nil
53
63
  expect { outcome = tailored.resume }.not_to raise_error
54
64
  expect(outcome).to eq(Outcome.new(:"#s", parent))
55
-
65
+
56
66
  # Only one result should be yielded
57
- expect(tailored.resume).to be_nil
58
- end
67
+ expect(tailored.resume).to be_nil
68
+ end
59
69
  end # context
60
70
  end # describe
61
71
  end # module
@@ -4,7 +4,6 @@ require_relative '../spec_helper' # Use the RSpec framework
4
4
  require_relative '../../lib/mini_kraken/core/k_symbol'
5
5
  require_relative '../../lib/mini_kraken/core/variable'
6
6
  require_relative '../../lib/mini_kraken/core/variable_ref'
7
- require_relative '../../lib/mini_kraken/core/association'
8
7
  require_relative '../../lib/mini_kraken/core/outcome'
9
8
 
10
9
  # Load the class under test
@@ -38,7 +37,6 @@ module MiniKraken
38
37
  child = Environment.new(subject)
39
38
  expect(child.parent).to eq(subject)
40
39
  end
41
-
42
40
  end # context
43
41
 
44
42
  context 'Provided services:' do
@@ -66,8 +64,7 @@ module MiniKraken
66
64
 
67
65
  it 'should accept the addition of an association' do
68
66
  subject.add_var(var_a)
69
- assoc = Association.new('a', pea)
70
- subject.add_assoc(assoc)
67
+ assoc = subject.add_assoc('a', pea)
71
68
  expect(subject.associations.size).to eq(1)
72
69
  expect(subject.associations['a']).to eq([assoc])
73
70
  end
@@ -83,25 +80,21 @@ module MiniKraken
83
80
  subject.add_var(var_a)
84
81
 
85
82
  # Let's associate an atomic term...
86
- assoc = Association.new('a', pea)
87
- subject.add_assoc(assoc)
83
+ subject.add_assoc('a', pea)
88
84
 
89
85
  expect(subject.fresh?(var_a)).to be_falsey
90
86
  end
91
87
 
92
- it "should cope with a variable associated with another variable" do
88
+ it 'should cope with a variable associated with another variable' do
93
89
  subject.add_var(var_a)
94
90
  subject.add_var(var_b)
95
91
 
96
92
  # Let's associate a with (fresh) b
97
- assoc = Association.new(var_a, var_b)
98
- subject.add_assoc(assoc)
99
-
93
+ subject.add_assoc(var_a, var_b)
100
94
  expect(subject.fresh?(var_a)).to be_truthy
101
95
 
102
96
  # Now associate b with something ground...
103
- assoc_b = Association.new(var_b, pea)
104
- subject.add_assoc(assoc_b)
97
+ subject.add_assoc(var_b, pea)
105
98
 
106
99
  # b is no more fresh, so is ... a
107
100
  expect(subject.fresh?(var_b)).to be_falsey
@@ -110,12 +103,10 @@ module MiniKraken
110
103
 
111
104
  it 'should remove all associations' do
112
105
  subject.add_var(var_a)
113
- assoc = Association.new(var_a, pea)
114
- subject.add_assoc(assoc)
106
+ subject.add_assoc(var_a, pea)
115
107
 
116
108
  subject.add_var(var_b)
117
- assoc = Association.new(var_b, pod)
118
- subject.add_assoc(assoc)
109
+ subject.add_assoc(var_b, pod)
119
110
 
120
111
  subject.clear
121
112
  expect(subject.fresh?(var_a)).to be_truthy
@@ -125,30 +116,27 @@ module MiniKraken
125
116
  it 'should propagate associations up in the environment hierarchy' do
126
117
  parent = Environment.new
127
118
  parent.add_var(var_a)
128
- # parent.add_var(var_c)
129
119
  instance = Environment.new(parent)
130
120
  instance.add_var(var_b)
131
- # instance.add_var(var_c_bis) # Should shadow parent's c variable
132
121
 
133
122
  outcome = Outcome.new(:"#s", instance)
134
- outcome.add_assoc(Association.new(var_a, pea))
135
- outcome.add_assoc(Association.new(var_b, pod))
136
- # outcome.add_assoc(Association.new(var_c_bis, pad))
137
- expect(outcome.associations.size).to eq(2)
138
-
123
+ outcome.add_assoc(var_a, pea)
124
+ outcome.add_assoc(var_b, pod)
125
+ expect(outcome.associations.size).to eq(2)
126
+
139
127
  # Propagate: outcome -> .. -> instance
140
- instance.propagate(outcome)
128
+ instance.propagate(outcome)
141
129
  expect(outcome.associations.size).to eq(1)
142
130
  expect(instance.associations[var_b.name]).not_to be_nil
143
131
  expect(parent.associations[var_a.name]).to be_nil
144
-
132
+
145
133
  # Propagate: outcome -> .. -> parent
146
134
  parent.propagate(outcome)
147
- expect(outcome.associations).to be_empty
135
+ expect(outcome.associations).to be_empty
148
136
  expect(parent.associations[var_b.name]).to be_nil
149
- expect(parent.associations[var_a.name]).not_to be_nil
137
+ expect(parent.associations[var_a.name]).not_to be_nil
150
138
  end
151
139
  end # context
152
140
  end # describe
153
141
  end # module
154
- end # module
142
+ end # module
@@ -49,21 +49,21 @@ module MiniKraken
49
49
  let(:env) { Environment.new }
50
50
  let(:var_q) { build_var('q') }
51
51
  let(:ref_q) do
52
- dummy = var_q # Force dependency
52
+ var_q # Force dependency
53
53
  build_var_ref('q')
54
54
  end
55
55
  let(:ref_q_bis) do
56
- dummy = var_q # Force dependency
56
+ var_q # Force dependency
57
57
  build_var_ref('q')
58
58
  end
59
59
  let(:var_x) { build_var('x') }
60
60
  let(:ref_x) do
61
- dummy = var_x # Force dependency
61
+ var_x # Force dependency
62
62
  build_var_ref('x')
63
63
  end
64
64
  let(:var_y) { build_var('y') }
65
65
  let(:ref_y) do
66
- dummy = var_y # Force dependency
66
+ var_y # Force dependency
67
67
  build_var_ref('y')
68
68
  end
69
69
 
@@ -246,7 +246,7 @@ module MiniKraken
246
246
  result = solve_for(ref_x, ref_y)
247
247
 
248
248
  expect(result).to be_successful
249
- expect(env.associations.size).to eq(2) # Symmetric association
249
+ expect(env.associations).to be_empty # Symmetric association
250
250
  expect(ref_x.fresh?(result)).to be_truthy
251
251
  expect(ref_y.fresh?(result)).to be_truthy
252
252
  end
@@ -285,7 +285,7 @@ module MiniKraken
285
285
  expect(ref_x.fresh?(env)).to be_falsey
286
286
  expect(ref_q.fresh?(env)).to be_falsey
287
287
  end
288
-
288
+
289
289
  it 'should fail for one right literal and one composite arguments' do
290
290
  # Reasoned S2, frame 1:46
291
291
  # x associated to ('pea 'pod)
@@ -297,7 +297,7 @@ module MiniKraken
297
297
 
298
298
  expect(result.resultant).to eq(:"#u")
299
299
  expect(result.associations).to be_empty
300
- end
300
+ end
301
301
  end # context
302
302
  end # describe
303
303
  end # module
@@ -3,7 +3,7 @@
3
3
  require_relative '../spec_helper' # Use the RSpec framework
4
4
 
5
5
  # Load the class under test
6
- require_relative '../../lib/mini_kraken/core/fail'
6
+ require_relative '../../lib/mini_kraken/core/fail'
7
7
 
8
8
  module MiniKraken
9
9
  module Core
@@ -14,7 +14,7 @@ module MiniKraken
14
14
  it 'should have one instance' do
15
15
  expect { Fail.instance }.not_to raise_error
16
16
  end
17
-
17
+
18
18
  it 'should know its name' do
19
19
  expect(subject.name).to eq('fail')
20
20
  end
@@ -24,20 +24,20 @@ module MiniKraken
24
24
  it 'should unconditionally return a failure result' do
25
25
  args = double('fake-args')
26
26
  env = double('fake-env')
27
-
27
+
28
28
  solver = nil
29
29
  expect { solver = subject.solver_for(args, env) }.not_to raise_error
30
-
30
+
31
31
  # Solver should quack like a Fiber
32
32
  dummy_arg = double('dummy-stuff')
33
33
  result = solver.resume(dummy_arg)
34
34
  expect(result).to eq(Failure)
35
-
35
+
36
36
  # Only one "solution", next 'resume' call should return nil
37
37
  result = solver.resume(dummy_arg)
38
- expect(result).to be_nil
38
+ expect(result).to be_nil
39
39
  end
40
40
  end # context
41
41
  end # describe
42
42
  end # module
43
- end # module
43
+ end # module
@@ -22,15 +22,15 @@ module MiniKraken
22
22
  it 'should accept one nullary relation and empty argument array' do
23
23
  expect { Goal.new(nullary_relation, []) }.not_to raise_error
24
24
  end
25
-
25
+
26
26
  it 'should accept one binary relation and 2-elements array' do
27
27
  expect { Goal.new(binary_relation, [KSymbol.new(:pea), KSymbol.new(:pod)]) }.not_to raise_error
28
- end
28
+ end
29
29
 
30
30
  it 'should know its relation' do
31
31
  expect(subject.relation).to eq(binary_relation)
32
32
  end
33
-
33
+
34
34
  it 'should know its actual arguments' do
35
35
  expectations = [KSymbol.new(:pea), KSymbol.new(:pod)]
36
36
  expect(subject.actuals).to eq(expectations)
@@ -41,21 +41,21 @@ module MiniKraken
41
41
  it 'should fail if relation does not succeed' do
42
42
  solver = subject.attain(env)
43
43
  expect(solver.resume).not_to be_successful
44
-
44
+
45
45
  # No more solution...
46
46
  expect(solver.resume).to be_nil
47
47
  end
48
-
48
+
49
49
  it 'should succeed if relation succeeds' do
50
- instance = Goal.new(binary_relation, [KSymbol.new(:pea), KSymbol.new(:pea)])
51
-
50
+ instance = Goal.new(binary_relation, [KSymbol.new(:pea), KSymbol.new(:pea)])
51
+
52
52
  solver = instance.attain(env)
53
53
  expect(solver.resume).to be_successful
54
-
54
+
55
55
  # No more solution...
56
56
  expect(solver.resume).to be_nil
57
- end
57
+ end
58
58
  end # context
59
59
  end # describe
60
60
  end # module
61
- end # module
61
+ end # module
@@ -20,12 +20,11 @@ module MiniKraken
20
20
  it 'should know its value' do
21
21
  expect(subject.value).to eq(a_value)
22
22
  end
23
-
23
+
24
24
  it 'should know that it is a ground term' do
25
25
  env = double('mock-env')
26
- visitees = double('fake-visitees')
27
26
  expect(subject.ground?(env)).to be_truthy
28
- end
27
+ end
29
28
  end # context
30
29
 
31
30
  context 'Provided services:' do
@@ -39,7 +38,7 @@ module MiniKraken
39
38
  expect(subject).not_to be_eql(another)
40
39
 
41
40
  # Different type, same value
42
- yet_another = OpenStruct.new(:value => :pea)
41
+ yet_another = OpenStruct.new(value: :pea)
43
42
  expect(subject).not_to be_eql(yet_another)
44
43
  end
45
44
 
@@ -53,11 +52,11 @@ module MiniKraken
53
52
  expect(subject == another).to be_falsy
54
53
 
55
54
  # Same duck type, same value
56
- yet_another = OpenStruct.new(:value => :pea)
55
+ yet_another = OpenStruct.new(value: :pea)
57
56
  expect(subject == yet_another).to be_truthy
58
57
 
59
58
  # Different duck type, different value
60
- still_another = OpenStruct.new(:value => :pod)
59
+ still_another = OpenStruct.new(value: :pod)
61
60
  expect(subject == still_another).to be_falsy
62
61
 
63
62
  # Default Ruby representation, same value
@@ -24,18 +24,18 @@ module MiniKraken
24
24
  it 'should unconditionally return a success result' do
25
25
  args = double('fake-args')
26
26
  env = double('fake-env')
27
-
27
+
28
28
  solver = nil
29
29
  expect { solver = subject.solver_for(args, env) }.not_to raise_error
30
-
30
+
31
31
  # Solver should quack like a Fiber
32
32
  dummy_arg = double('dummy-stuff')
33
33
  result = solver.resume(dummy_arg)
34
34
  expect(result).to eq(BasicSuccess)
35
-
35
+
36
36
  # Only one "solution", next 'resume' call should return nil
37
37
  result = solver.resume(dummy_arg)
38
- expect(result).to be_nil
38
+ expect(result).to be_nil
39
39
  end
40
40
  end # context
41
41
  end # describe
@@ -18,10 +18,6 @@ module MiniKraken
18
18
  it 'should know the name of a variable' do
19
19
  expect(subject.var_name).to eq('q')
20
20
  end
21
-
22
- # it 'should be fresh by default' do
23
- # expect(subject).to be_fresh
24
- # end
25
21
  end # context
26
22
 
27
23
  context 'Provided services:' do
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../spec_helper' # Use the RSpec framework
4
- require_relative '../../lib/mini_kraken/core/association'
5
4
  require_relative '../../lib/mini_kraken/core/k_symbol'
5
+ require_relative '../../lib/mini_kraken/core/variable'
6
6
  require_relative '../../lib/mini_kraken/core/variable_ref'
7
7
  require_relative '../support/factory_methods'
8
8
 
9
9
  # Load the class under test
10
- require_relative '../../lib/mini_kraken/core/vocabulary'
10
+ # frozen_string_literal: true
11
11
 
12
+ require_relative '../../lib/mini_kraken/core/vocabulary'
12
13
 
13
14
  module MiniKraken
14
15
  module Core
15
-
16
16
  class TestVocabulary
17
17
  include Vocabulary
18
18
 
@@ -21,16 +21,20 @@ module MiniKraken
21
21
  end
22
22
  end # class
23
23
 
24
+ # Helper module that simulates an environment-like object.
24
25
  module VariableBearer
25
26
  attr_reader :vars
27
+ attr_accessor :ivars
26
28
 
27
29
  def init_var_bearer
28
30
  @vars = {}
31
+ @ivars = {}
29
32
  self
30
33
  end
31
34
 
32
35
  def add_var(aVarName)
33
- vars[aVarName] = aVarName.hash # Just for testing purposes
36
+ vars[aVarName] = Variable.new(aVarName)
37
+ ivars[aVarName] = Set.new([aVarName])
34
38
  end
35
39
  end # module
36
40
 
@@ -75,11 +79,11 @@ module MiniKraken
75
79
 
76
80
  it 'should provide a walker over ancestors' do
77
81
  walker = subject.ancestor_walker
78
- expect(walker).to be_kind_of(Fiber)
79
- expect(walker.resume).to eq(subject)
80
- expect(walker.resume).to eq(mother)
81
- expect(walker.resume).to eq(grandma)
82
- expect(walker.resume).to be_nil
82
+ expect(walker).to be_kind_of(Enumerator)
83
+ expect(walker.next).to eq(subject)
84
+ expect(walker.next).to eq(mother)
85
+ expect(walker.next).to eq(grandma)
86
+ expect(walker.next).to be_nil
83
87
  end
84
88
 
85
89
  it 'should know if a variable is defined' do
@@ -99,11 +103,12 @@ module MiniKraken
99
103
  it 'should allow the addition of associations' do
100
104
  grandma.add_var('q')
101
105
  expect(subject['q']).to be_empty
102
- mother.add_assoc(Association.new('q', pea))
106
+ res_add = mother.add_assoc('q', pea)
107
+ expect(res_add).to be_kind_of(Association)
103
108
  expect(subject['q'].size).to eq(1)
104
109
  expect(subject['q'].first.value).to eq(pea)
105
110
 
106
- subject.add_assoc(Association.new('q', ref_x))
111
+ subject.add_assoc('q', ref_x)
107
112
  expect(subject['q'].size).to eq(2)
108
113
  expect(subject['q'].first.value).to eq(ref_x)
109
114
  expect(subject['q'].last.value).to eq(pea)
@@ -111,8 +116,8 @@ module MiniKraken
111
116
 
112
117
  it 'should allow the deletion of associations' do
113
118
  grandma.add_var('q')
114
- mother.add_assoc(Association.new('q', pea))
115
- subject.add_assoc(Association.new('q', ref_x))
119
+ mother.add_assoc('q', pea)
120
+ subject.add_assoc('q', ref_x)
116
121
  expect(mother.associations.size).to eq(1)
117
122
  expect(subject.associations.size).to eq(1)
118
123
 
@@ -127,18 +132,18 @@ module MiniKraken
127
132
  grandma.add_var('q')
128
133
  grandma.add_var('x')
129
134
  expect(subject.fresh?(ref_q)).to be_truthy
130
- subject.add_assoc(Association.new('q', ref_x)) # Dependency: q --> x
135
+ subject.add_assoc('q', ref_x) # Dependency: q --> x
131
136
  expect(subject.fresh?(ref_x)).to be_truthy
132
137
  end
133
138
 
134
139
  it 'should say not fresh when variable --> atomic value' do
135
140
  grandma.add_var('q')
136
141
  grandma.add_var('x')
137
- subject.add_assoc(Association.new('q', ref_x)) # Dependency: q --> x
142
+ subject.add_assoc('q', ref_x) # Dependency: q --> x
138
143
  expect(subject.fresh?(ref_q)).to be_truthy
139
144
 
140
145
  # Associate with an atomic term
141
- subject.add_assoc(Association.new('q', pea))
146
+ subject.add_assoc('q', pea)
142
147
  expect(subject.fresh?(ref_q)).to be_falsey
143
148
  end
144
149
 
@@ -147,16 +152,16 @@ module MiniKraken
147
152
 
148
153
  # Composite having only atomic terms as leaf elements
149
154
  expr = cons(pea, cons(pod))
150
- subject.add_assoc(Association.new('q', expr))
155
+ subject.add_assoc('q', expr)
151
156
  expect(subject.fresh?(ref_q)).to be_falsey
152
157
  end
153
158
 
154
159
  it 'say not fresh when variable --> composite of atomics & bound var' do
155
160
  grandma.add_var('q')
156
161
  grandma.add_var('x')
157
- subject.add_assoc(Association.new('x', pea)) # Dependency: x --> pea
162
+ subject.add_assoc('x', pea) # Dependency: x --> pea
158
163
  expr = cons(pea, cons(pod, cons(ref_x)))
159
- subject.add_assoc(Association.new('q', expr))
164
+ subject.add_assoc('q', expr)
160
165
  expect(subject.fresh?(ref_q)).to be_falsey
161
166
  end
162
167
 
@@ -164,7 +169,7 @@ module MiniKraken
164
169
  grandma.add_var('q')
165
170
  grandma.add_var('x')
166
171
  expr = cons(pea, cons(pod, cons(ref_x)))
167
- subject.add_assoc(Association.new('q', expr))
172
+ subject.add_assoc('q', expr)
168
173
  expect(subject.fresh?(ref_q)).to be_truthy
169
174
  end
170
175
 
@@ -173,13 +178,14 @@ module MiniKraken
173
178
  grandma.add_var('x')
174
179
 
175
180
  # Beware of cyclic structure
176
- subject.add_assoc(Association.new('q', ref_x)) # Dependency: q --> x
177
- subject.add_assoc(Association.new('x', ref_q)) # Dependency: x --> q
181
+ subject.add_assoc('q', ref_x) # Dependency: q --> x
182
+ subject.add_assoc('x', ref_q) # Dependency: x --> q
178
183
  expect(subject.fresh?(ref_x)).to be_truthy
179
184
  expect(subject.fresh?(ref_q)).to be_truthy
185
+ expect(subject.associations).to be_empty
180
186
 
181
187
  # Associate with an atomic term
182
- subject.add_assoc(Association.new('x', pea))
188
+ subject.add_assoc('x', pea)
183
189
  expect(subject.fresh?(ref_q)).to be_falsey
184
190
  end
185
191
 
@@ -190,16 +196,16 @@ module MiniKraken
190
196
  expect(subject.get_rank('c')).to eq(2)
191
197
  end
192
198
  end
193
-
199
+
194
200
  it 'should clear the rankings' do
195
201
  expect(subject.get_rank('a')).to eq(0)
196
202
  expect(subject.get_rank('z')).to eq(1)
197
-
203
+
198
204
  subject.clear_rankings
199
205
  expect(grandma.rankings).to be_empty
200
206
 
201
- expect(subject.get_rank('z')).to eq(0)
202
- expect(subject.get_rank('a')).to eq(1)
207
+ expect(subject.get_rank('z')).to eq(0)
208
+ expect(subject.get_rank('a')).to eq(1)
203
209
  end
204
210
  end # context
205
211
  end # describe