mini_kraken 0.2.03 → 0.3.03

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 (136) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +378 -333
  3. data/CHANGELOG.md +48 -0
  4. data/README.md +29 -21
  5. data/lib/mini_kraken/atomic/all_atomic.rb +5 -0
  6. data/lib/mini_kraken/atomic/atomic_term.rb +96 -0
  7. data/lib/mini_kraken/atomic/k_boolean.rb +42 -0
  8. data/lib/mini_kraken/{core → atomic}/k_integer.rb +2 -5
  9. data/lib/mini_kraken/atomic/k_string.rb +17 -0
  10. data/lib/mini_kraken/{core → atomic}/k_symbol.rb +4 -8
  11. data/lib/mini_kraken/composite/all_composite.rb +4 -0
  12. data/lib/mini_kraken/composite/composite_term.rb +27 -0
  13. data/lib/mini_kraken/composite/cons_cell.rb +301 -0
  14. data/lib/mini_kraken/composite/cons_cell_visitor.rb +50 -0
  15. data/lib/mini_kraken/composite/list.rb +32 -0
  16. data/lib/mini_kraken/core/all_core.rb +8 -0
  17. data/lib/mini_kraken/core/any_value.rb +31 -7
  18. data/lib/mini_kraken/core/arity.rb +69 -0
  19. data/lib/mini_kraken/core/association.rb +29 -4
  20. data/lib/mini_kraken/core/association_copy.rb +50 -0
  21. data/lib/mini_kraken/core/base_term.rb +13 -0
  22. data/lib/mini_kraken/core/blackboard.rb +315 -0
  23. data/lib/mini_kraken/core/bookmark.rb +46 -0
  24. data/lib/mini_kraken/core/context.rb +492 -0
  25. data/lib/mini_kraken/core/duck_fiber.rb +21 -19
  26. data/lib/mini_kraken/core/entry.rb +40 -0
  27. data/lib/mini_kraken/core/fail.rb +20 -18
  28. data/lib/mini_kraken/core/fusion.rb +29 -0
  29. data/lib/mini_kraken/core/goal.rb +20 -29
  30. data/lib/mini_kraken/core/log_var.rb +22 -0
  31. data/lib/mini_kraken/core/log_var_ref.rb +108 -0
  32. data/lib/mini_kraken/core/nullary_relation.rb +2 -9
  33. data/lib/mini_kraken/core/parametrized_term.rb +68 -0
  34. data/lib/mini_kraken/core/relation.rb +14 -28
  35. data/lib/mini_kraken/core/scope.rb +67 -0
  36. data/lib/mini_kraken/core/solver_adapter.rb +58 -0
  37. data/lib/mini_kraken/core/specification.rb +48 -0
  38. data/lib/mini_kraken/core/succeed.rb +21 -17
  39. data/lib/mini_kraken/core/symbol_table.rb +137 -0
  40. data/lib/mini_kraken/core/term.rb +15 -4
  41. data/lib/mini_kraken/glue/dsl.rb +44 -88
  42. data/lib/mini_kraken/glue/run_star_expression.rb +28 -30
  43. data/lib/mini_kraken/rela/all_rela.rb +8 -0
  44. data/lib/mini_kraken/rela/binary_relation.rb +30 -0
  45. data/lib/mini_kraken/rela/conde.rb +143 -0
  46. data/lib/mini_kraken/rela/conj2.rb +65 -0
  47. data/lib/mini_kraken/rela/def_relation.rb +93 -0
  48. data/lib/mini_kraken/rela/disj2.rb +70 -0
  49. data/lib/mini_kraken/rela/fresh.rb +98 -0
  50. data/lib/mini_kraken/{core → rela}/goal_relation.rb +7 -9
  51. data/lib/mini_kraken/rela/unify.rb +265 -0
  52. data/lib/mini_kraken/version.rb +1 -1
  53. data/mini_kraken.gemspec +2 -2
  54. data/spec/.rubocop.yml +1 -1
  55. data/spec/atomic/atomic_term_spec.rb +98 -0
  56. data/spec/{core → atomic}/k_boolean_spec.rb +19 -34
  57. data/spec/{core → atomic}/k_symbol_spec.rb +3 -16
  58. data/spec/composite/cons_cell_spec.rb +225 -0
  59. data/spec/{core → composite}/cons_cell_visitor_spec.rb +36 -20
  60. data/spec/composite/list_spec.rb +50 -0
  61. data/spec/core/any_value_spec.rb +52 -0
  62. data/spec/core/arity_spec.rb +92 -0
  63. data/spec/core/association_copy_spec.rb +69 -0
  64. data/spec/core/association_spec.rb +31 -4
  65. data/spec/core/blackboard_spec.rb +287 -0
  66. data/spec/core/bookmark_spec.rb +40 -0
  67. data/spec/core/context_spec.rb +245 -0
  68. data/spec/core/core_spec.rb +40 -0
  69. data/spec/core/duck_fiber_spec.rb +16 -46
  70. data/spec/core/fail_spec.rb +5 -6
  71. data/spec/core/goal_spec.rb +22 -12
  72. data/spec/core/log_var_ref_spec.rb +105 -0
  73. data/spec/core/log_var_spec.rb +64 -0
  74. data/spec/core/nullary_relation_spec.rb +33 -0
  75. data/spec/core/parametrized_tem_spec.rb +39 -0
  76. data/spec/core/relation_spec.rb +33 -0
  77. data/spec/core/scope_spec.rb +73 -0
  78. data/spec/core/solver_adapter_spec.rb +70 -0
  79. data/spec/core/specification_spec.rb +43 -0
  80. data/spec/core/succeed_spec.rb +5 -5
  81. data/spec/core/symbol_table_spec.rb +142 -0
  82. data/spec/glue/dsl_chap1_spec.rb +88 -144
  83. data/spec/glue/dsl_chap2_spec.rb +454 -19
  84. data/spec/glue/run_star_expression_spec.rb +81 -906
  85. data/spec/rela/conde_spec.rb +153 -0
  86. data/spec/rela/conj2_spec.rb +123 -0
  87. data/spec/rela/def_relation_spec.rb +119 -0
  88. data/spec/rela/disj2_spec.rb +117 -0
  89. data/spec/rela/fresh_spec.rb +147 -0
  90. data/spec/rela/unify_spec.rb +369 -0
  91. data/spec/support/factory_atomic.rb +29 -0
  92. data/spec/support/factory_composite.rb +21 -0
  93. data/spec/support/factory_methods.rb +11 -26
  94. metadata +98 -70
  95. data/lib/mini_kraken/core/association_walker.rb +0 -183
  96. data/lib/mini_kraken/core/atomic_term.rb +0 -67
  97. data/lib/mini_kraken/core/base_arg.rb +0 -10
  98. data/lib/mini_kraken/core/binary_relation.rb +0 -63
  99. data/lib/mini_kraken/core/composite_goal.rb +0 -46
  100. data/lib/mini_kraken/core/composite_term.rb +0 -41
  101. data/lib/mini_kraken/core/conde.rb +0 -143
  102. data/lib/mini_kraken/core/conj2.rb +0 -79
  103. data/lib/mini_kraken/core/cons_cell.rb +0 -82
  104. data/lib/mini_kraken/core/cons_cell_visitor.rb +0 -102
  105. data/lib/mini_kraken/core/def_relation.rb +0 -53
  106. data/lib/mini_kraken/core/designation.rb +0 -55
  107. data/lib/mini_kraken/core/disj2.rb +0 -72
  108. data/lib/mini_kraken/core/environment.rb +0 -73
  109. data/lib/mini_kraken/core/equals.rb +0 -193
  110. data/lib/mini_kraken/core/formal_arg.rb +0 -22
  111. data/lib/mini_kraken/core/formal_ref.rb +0 -25
  112. data/lib/mini_kraken/core/freshness.rb +0 -45
  113. data/lib/mini_kraken/core/goal_arg.rb +0 -12
  114. data/lib/mini_kraken/core/goal_template.rb +0 -102
  115. data/lib/mini_kraken/core/k_boolean.rb +0 -35
  116. data/lib/mini_kraken/core/outcome.rb +0 -63
  117. data/lib/mini_kraken/core/variable.rb +0 -41
  118. data/lib/mini_kraken/core/variable_ref.rb +0 -84
  119. data/lib/mini_kraken/core/vocabulary.rb +0 -446
  120. data/lib/mini_kraken/glue/fresh_env.rb +0 -103
  121. data/lib/mini_kraken/glue/fresh_env_factory.rb +0 -83
  122. data/spec/core/association_walker_spec.rb +0 -192
  123. data/spec/core/conde_spec.rb +0 -147
  124. data/spec/core/conj2_spec.rb +0 -114
  125. data/spec/core/cons_cell_spec.rb +0 -107
  126. data/spec/core/def_relation_spec.rb +0 -97
  127. data/spec/core/disj2_spec.rb +0 -99
  128. data/spec/core/environment_spec.rb +0 -142
  129. data/spec/core/equals_spec.rb +0 -317
  130. data/spec/core/goal_template_spec.rb +0 -74
  131. data/spec/core/outcome_spec.rb +0 -56
  132. data/spec/core/variable_ref_spec.rb +0 -30
  133. data/spec/core/variable_spec.rb +0 -35
  134. data/spec/core/vocabulary_spec.rb +0 -219
  135. data/spec/glue/fresh_env_factory_spec.rb +0 -97
  136. data/spec/glue/fresh_env_spec.rb +0 -62
@@ -1,317 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
- require_relative '../../lib/mini_kraken/core/environment'
5
-
6
- require_relative '../support/factory_methods'
7
- # Load the class under test
8
- require_relative '../../lib/mini_kraken/core/equals'
9
-
10
- module MiniKraken
11
- module Core
12
- describe Equals do
13
- include FactoryMethods
14
-
15
- subject { Equals.instance }
16
-
17
- context 'Initialization:' do
18
- it 'should be created without argument' do
19
- expect { Equals.instance }.not_to raise_error
20
- end
21
-
22
- it 'should know its name' do
23
- expect(subject.name).to eq('equals')
24
- end
25
- end # context
26
-
27
- context 'Provided services:' do
28
- def build_var(aName)
29
- new_var = Variable.new(aName)
30
- env.add_var(new_var)
31
- new_var
32
- end
33
-
34
- def build_var_ref(aName)
35
- VariableRef.new(aName)
36
- end
37
-
38
- def solve_for(arg1, arg2)
39
- solver = subject.solver_for([arg1, arg2], env)
40
- outcome = solver.resume
41
- env.propagate(outcome)
42
- outcome
43
- end
44
-
45
- let(:pea) { KSymbol.new(:pea) }
46
- let(:pod) { KSymbol.new(:pod) }
47
- let(:sample_cons) { ConsCell.new(pea) }
48
- let(:a_composite) { ConsCell.new(pod) }
49
- let(:env) { Environment.new }
50
- let(:var_q) { build_var('q') }
51
- let(:ref_q) do
52
- var_q # Force dependency
53
- build_var_ref('q')
54
- end
55
- let(:ref_q_bis) do
56
- var_q # Force dependency
57
- build_var_ref('q')
58
- end
59
- let(:var_x) { build_var('x') }
60
- let(:ref_x) do
61
- var_x # Force dependency
62
- build_var_ref('x')
63
- end
64
- let(:var_y) { build_var('y') }
65
- let(:ref_y) do
66
- var_y # Force dependency
67
- build_var_ref('y')
68
- end
69
-
70
-
71
- it 'should succeed for equal literal arguments' do
72
- result = solve_for(pea, pea)
73
-
74
- expect(result).to be_kind_of(Outcome)
75
- expect(result.resultant).to eq(:"#s")
76
- expect(result.associations).to be_empty
77
- expect(var_q.fresh?(env)).to be_truthy
78
- end
79
-
80
- it 'should fail for inequal literal arguments' do
81
- result = solve_for(pea, pod)
82
-
83
- expect(result.resultant).to eq(:"#u")
84
- expect(result.associations).to be_empty
85
- expect(var_q.fresh?(env)).to be_truthy
86
- end
87
-
88
- it 'should fail for one left literal and one composite arguments' do
89
- result = solve_for(pea, sample_cons)
90
-
91
- expect(result.resultant).to eq(:"#u")
92
- expect(result.associations).to be_empty
93
- expect(var_q.fresh?(env)).to be_truthy
94
- end
95
-
96
- it 'should fail for one right literal and one composite arguments' do
97
- # Reasoned S2, frame 1:44
98
- # (== '(pea) 'pea) ;; => #u
99
- result = solve_for(sample_cons, pea)
100
-
101
- expect(result.resultant).to eq(:"#u")
102
- expect(result.associations).to be_empty
103
- expect(var_q.fresh?(env)).to be_truthy
104
- end
105
-
106
- it 'should succeed for a right-handed fresh argument' do
107
- result = solve_for(pea, ref_q)
108
-
109
- expect(result).to be_success
110
- expect(env.associations.size).to eq(1)
111
- expect(env.associations['q'].first.value).to eq(pea)
112
- expect(var_q.fresh?(result)).to be_falsey
113
- expect(ref_q.values(result).first).to eq(pea)
114
- end
115
-
116
- it 'should succeed for a left-handed fresh argument' do
117
- result = solve_for(ref_q, pea)
118
-
119
- expect(result).to be_success
120
- expect(env.associations.size).to eq(1)
121
- expect(env.associations['q'].first.value).to eq(pea)
122
- expect(var_q.fresh?(result)).to be_falsey
123
- expect(ref_q.values(result).first).to eq(pea)
124
- end
125
-
126
- it 'should succeed for a right-handed bound argument equal constant' do
127
- ref_q.associate(pod, env)
128
-
129
- result = solve_for(pod, ref_q)
130
- expect(result).to be_success
131
- expect(env.associations.size).to eq(1) # No new association
132
- expect(ref_q.fresh?(result)).not_to be_truthy
133
- expect(ref_q.values(result).first).to eq(pod)
134
- end
135
-
136
- it 'should succeed for a left-handed bound argument equal constant' do
137
- ref_q.associate(pod, env)
138
-
139
- result = solve_for(ref_q, pod)
140
- expect(result).to be_success
141
- expect(result.associations).to be_empty
142
- expect(ref_q.fresh?(result)).to be_falsey
143
- expect(ref_q.values(result).first).to eq(pod)
144
- end
145
-
146
- it 'should fail for a right-handed bound argument to a distinct literal' do
147
- ref_q.associate(pod, env)
148
-
149
- result = solve_for(pea, ref_q)
150
- expect(result).not_to be_success
151
- expect(result.associations).to be_empty
152
- expect(ref_q.fresh?(result)).to be_falsey
153
- expect(ref_q.values(result).first).to eq(pod)
154
- end
155
-
156
- it 'should fail for a left-handed bound argument to a distinct literal' do
157
- ref_q.associate(pod, env)
158
-
159
- result = solve_for(ref_q, pea)
160
- expect(result).not_to be_success
161
- expect(result.associations).to be_empty
162
- expect(ref_q.fresh?(result)).to be_falsey
163
- expect(ref_q.values(result).first).to eq(pod)
164
- end
165
-
166
- it 'should succeed for a composite and right-handed fresh argument' do
167
- result = solve_for(sample_cons, ref_q)
168
-
169
- expect(result).to be_success
170
- expect(env.associations.size).to eq(1)
171
- expect(ref_q.fresh?(result)).to be_falsey
172
- expect(ref_q.values(result).first).to eq(sample_cons)
173
- end
174
-
175
- it 'should succeed for composite and left-handed fresh argument' do
176
- result = solve_for(ref_q, sample_cons)
177
-
178
- expect(result).to be_success
179
- expect(env.associations.size).to eq(1)
180
- expect(ref_q.fresh?(result)).to be_falsey
181
- expect(ref_q.values(result).first).to eq(sample_cons)
182
- end
183
-
184
- it 'should succeed for a right-handed bound equal argument' do
185
- ref_q.associate(sample_cons, env)
186
- composite = ConsCell.new(pea)
187
- result = solve_for(composite, ref_q)
188
-
189
- expect(result).to be_success
190
- expect(result.associations).to be_empty
191
- expect(ref_q.fresh?(result)).not_to be_truthy
192
- expect(ref_q.values(result).first).to eq(sample_cons)
193
- end
194
-
195
- it 'should succeed for a left-handed bound equal argument' do
196
- ref_q.associate(sample_cons, env)
197
- composite = ConsCell.new(pea)
198
- result = solve_for(ref_q, composite)
199
-
200
- expect(result).to be_success
201
- expect(result.associations).to be_empty
202
- expect(ref_q.fresh?(result)).not_to be_truthy
203
- expect(ref_q.values(result).first).to eq(sample_cons)
204
- end
205
-
206
- it 'should succeed for a right-handed bound unequal argument' do
207
- ref_q.associate(sample_cons, env)
208
- composite = ConsCell.new(pod)
209
- result = solve_for(composite, ref_q)
210
-
211
- expect(result).to be_failure
212
- expect(result.associations).to be_empty
213
- expect(ref_q.fresh?(result)).not_to be_truthy
214
- expect(ref_q.values(result).first).to eq(sample_cons)
215
- end
216
-
217
- it 'should succeed for a left-handed bound unequal argument' do
218
- ref_q.associate(sample_cons, env)
219
- composite = ConsCell.new(pod)
220
- result = solve_for(ref_q, composite)
221
-
222
- expect(result).not_to be_success
223
- expect(result.associations).to be_empty
224
- expect(ref_q.fresh?(result)).not_to be_truthy
225
- expect(ref_q.values(result).first).to eq(sample_cons)
226
- end
227
-
228
- it 'should succeed for both identical fresh arguments' do
229
- result = solve_for(ref_q, ref_q)
230
-
231
- expect(result).to be_success
232
- expect(result.associations).to be_empty
233
- expect(ref_q.fresh?(result)).to be_truthy
234
- end
235
-
236
- it 'should succeed for both same fresh arguments' do
237
- result = solve_for(ref_q, ref_q_bis)
238
-
239
- expect(result).to be_success
240
- expect(result.associations).to be_empty
241
- expect(ref_q.fresh?(result)).to be_truthy
242
- expect(ref_q_bis.fresh?(result)).to be_truthy
243
- end
244
-
245
- it 'should succeed for both distinct fresh arguments' do
246
- result = solve_for(ref_x, ref_y)
247
-
248
- expect(result).to be_success
249
- expect(env.associations).to be_empty # Symmetric association
250
- expect(ref_x.fresh?(result)).to be_truthy
251
- expect(ref_y.fresh?(result)).to be_truthy
252
- end
253
-
254
- it 'should succeed for arguments bound to equal values' do
255
- ref_x.associate(pea, env)
256
- ref_y.associate(pea, env)
257
- expect(ref_x.fresh?(env)).to be_falsey
258
- expect(ref_y.fresh?(env)).to be_falsey
259
-
260
- result = solve_for(ref_x, ref_y)
261
- expect(result).to be_success
262
- expect(result.associations).to be_empty
263
- end
264
-
265
- it 'should fail for arguments bound unequal values' do
266
- ref_x.associate(pea, env)
267
- ref_y.associate(pod, env)
268
- expect(ref_x.fresh?(env)).to be_falsey
269
- expect(ref_y.fresh?(env)).to be_falsey
270
-
271
- result = solve_for(ref_x, ref_y)
272
- expect(result).not_to be_success
273
- expect(result.associations).to be_empty
274
- end
275
-
276
- it 'should unify composite terms with variables' do
277
- # Reasoned S2, frame 1:36
278
- # (run* q (fresh (x) (== '(((,q)) ,x) `(((,x)) pod)))) ;; => ('pod)
279
- expr1 = cons(cons(cons(ref_q)), cons(ref_x))
280
- expect(expr1.to_s).to eq('(((q)) x)')
281
- expr2 = cons(cons(cons(ref_x)), cons(pod))
282
- expect(expr2.to_s).to eq('(((x)) :pod)')
283
-
284
- result = solve_for(expr1, expr2)
285
- expect(result).to be_success
286
- expect(ref_x.fresh?(env)).to be_falsey
287
- expect(ref_q.fresh?(env)).to be_falsey
288
- end
289
-
290
- it 'should fail for one right literal and one composite arguments' do
291
- # Reasoned S2, frame 1:46
292
- # x associated to ('pea 'pod)
293
- # (== '(,x) x) ;; => #u
294
- expr1 = cons(pea, cons(pod))
295
- ref_x.associate(expr1, env)
296
- expr2 = cons(ref_x)
297
- result = solve_for(expr2, ref_x)
298
-
299
- expect(result.resultant).to eq(:"#u")
300
- expect(result.associations).to be_empty
301
- end
302
-
303
- it 'should unify variables with a list' do
304
- # Variant of Reasoned S2, frame 2:3
305
- # (== (cons q x) '(a c o r n)) ;; q => :a, x => '(c o r n)
306
- expr1 = cons(ref_q, ref_x)
307
- acorn = cons(k_symbol(:a), cons(k_symbol(:c),
308
- cons(k_symbol(:o), cons(k_symbol(:r), cons(k_symbol(:n))))))
309
- result = solve_for(expr1, acorn)
310
- expect(result.resultant).to eq(:"#s")
311
- q_value = env.associations['q'].first.value
312
- expect(q_value).to eq(:a)
313
- end
314
- end # context
315
- end # describe
316
- end # module
317
- end # module
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
- require_relative '../../lib/mini_kraken/core/disj2'
5
- require_relative '../../lib/mini_kraken/core/equals'
6
- require_relative '../../lib/mini_kraken/core/formal_arg'
7
- require_relative '../../lib/mini_kraken/core/formal_ref'
8
- require_relative '../../lib/mini_kraken/core/goal'
9
- require_relative '../../lib/mini_kraken/core/k_symbol'
10
- require_relative '../../lib/mini_kraken/core/variable_ref'
11
- # require_relative '../../lib/mini_kraken/core/environment'
12
-
13
- # Load the class under test
14
- require_relative '../../lib/mini_kraken/core/goal_template'
15
-
16
-
17
- module MiniKraken
18
- module Core
19
- describe GoalTemplate do
20
- let(:tea) { KSymbol.new(:tea) }
21
- let(:t_ref) { FormalRef.new('t') }
22
- subject { GoalTemplate.new(Equals.instance, [tea, t_ref]) }
23
-
24
- context 'Initialization:' do
25
- it 'should be initialized with a relation and args' do
26
- expect { GoalTemplate.new(Equals.instance, [tea, t_ref]) }.not_to raise_error
27
- end
28
-
29
- it 'should know its relation' do
30
- expect(subject.relation).to eq(Equals.instance)
31
- end
32
-
33
- it 'should know its arguments' do
34
- expect(subject.args[0]).to eq(tea)
35
- expect(subject.args[1]).to eq(t_ref)
36
- end
37
- end # context
38
-
39
- context 'Provided services:' do
40
- let(:formal_t) { FormalArg.new('t') }
41
- let(:cup) { KSymbol.new(:cup) }
42
- let(:ref_x) { VariableRef.new('x') }
43
- # let(:env) { Environment.new }
44
-
45
- it 'should instantiate a single-node goal' do
46
- expect(subject.instantiate([formal_t], [cup])).to be_kind_of(Goal)
47
- goal = subject.instantiate([formal_t], [cup])
48
- expect(goal.relation).to eq(Equals.instance)
49
- expect(goal.actuals[0]).to eq(tea)
50
- expect(goal.actuals[1]).to eq(cup)
51
- end
52
-
53
- it 'should instantiate a multiple-nodes goal' do
54
- sub_tmp1 = GoalTemplate.new(Equals.instance, [tea, t_ref])
55
- sub_tmp2 = GoalTemplate.new(Equals.instance, [cup, t_ref])
56
- template = GoalTemplate.new(Disj2.instance, [sub_tmp1, sub_tmp2])
57
-
58
- goal = template.instantiate([formal_t], [ref_x])
59
- expect(goal.relation).to eq(Disj2.instance)
60
- subgoal1 = goal.actuals[0]
61
- expect(subgoal1).to be_kind_of(Goal)
62
- expect(subgoal1.relation).to eq(Equals.instance)
63
- expect(subgoal1.actuals[0]).to eq(tea)
64
- expect(subgoal1.actuals[1]).to eq(ref_x)
65
- subgoal2 = goal.actuals[1]
66
- expect(subgoal2).to be_kind_of(Goal)
67
- expect(subgoal2.relation).to eq(Equals.instance)
68
- expect(subgoal2.actuals[0]).to eq(cup)
69
- expect(subgoal2.actuals[1]).to eq(ref_x)
70
- end
71
- end # context
72
- end # describe
73
- end # module
74
- end # module
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
- require_relative '../../lib/mini_kraken/core/vocabulary'
5
-
6
- # Load the class under test
7
- require_relative '../../lib/mini_kraken/core/outcome'
8
-
9
- module MiniKraken
10
- module Core
11
- describe Outcome do
12
- let(:voc) do
13
- obj = Object.new
14
- obj.extend(Vocabulary)
15
- obj
16
- end
17
- subject { Outcome.new(:"#s", voc) }
18
-
19
- context 'Initialization:' do
20
- it 'should be created with a symbol and a vocabulary' do
21
- expect { Outcome.new(:"#s", voc) }.not_to raise_error
22
- end
23
-
24
- it 'should know its resultant' do
25
- expect(subject.resultant).to eq(:"#s")
26
- end
27
-
28
- it 'should know whether it represents a failure' do
29
- expect(Outcome.new(:"#u")).to be_failure
30
- end
31
-
32
- it 'should know whether it represents a success' do
33
- expect(subject).to be_success
34
- end
35
-
36
- it 'should know its parent' do
37
- expect(subject.parent).to eq(voc)
38
- end
39
- end # context
40
-
41
- context 'Provided services:' do
42
- it 'should have a factory for failing outcome' do
43
- instance = Outcome.failure(voc)
44
- expect(instance.resultant).to eq(:"#u")
45
- expect(instance.parent).to eq(voc)
46
- end
47
-
48
- it 'should have a factory for succeeding outcome' do
49
- instance = Outcome.success(voc)
50
- expect(instance.resultant).to eq(:"#s")
51
- expect(instance.parent).to eq(voc)
52
- end
53
- end # context
54
- end # describe
55
- end # module
56
- end # module
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
-
5
- # Load the class under test
6
- require_relative '../../lib/mini_kraken/core/variable_ref'
7
-
8
- module MiniKraken
9
- module Core
10
- describe VariableRef do
11
- subject { VariableRef.new('q') }
12
-
13
- context 'Initialization:' do
14
- it 'should be initialized with the name of variable' do
15
- expect { VariableRef.new('q') }.not_to raise_error
16
- end
17
-
18
- it 'should know the name of a variable' do
19
- expect(subject.var_name).to eq('q')
20
- end
21
- end # context
22
-
23
- context 'Provided services:' do
24
- it 'knows its text representation' do
25
- expect(subject.to_s).to eq('q')
26
- end
27
- end # context
28
- end # describe
29
- end # module
30
- end # module