mini_kraken 0.2.02 → 0.3.02
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +378 -333
- data/CHANGELOG.md +52 -0
- data/README.md +19 -19
- data/lib/mini_kraken.rb +0 -1
- data/lib/mini_kraken/atomic/all_atomic.rb +5 -0
- data/lib/mini_kraken/atomic/atomic_term.rb +96 -0
- data/lib/mini_kraken/atomic/k_boolean.rb +42 -0
- data/lib/mini_kraken/{core → atomic}/k_integer.rb +2 -5
- data/lib/mini_kraken/atomic/k_string.rb +17 -0
- data/lib/mini_kraken/{core → atomic}/k_symbol.rb +4 -8
- data/lib/mini_kraken/composite/all_composite.rb +4 -0
- data/lib/mini_kraken/composite/composite_term.rb +27 -0
- data/lib/mini_kraken/composite/cons_cell.rb +299 -0
- data/lib/mini_kraken/composite/cons_cell_visitor.rb +50 -0
- data/lib/mini_kraken/composite/list.rb +32 -0
- data/lib/mini_kraken/core/all_core.rb +8 -0
- data/lib/mini_kraken/core/any_value.rb +31 -7
- data/lib/mini_kraken/core/arity.rb +69 -0
- data/lib/mini_kraken/core/association.rb +29 -4
- data/lib/mini_kraken/core/association_copy.rb +50 -0
- data/lib/mini_kraken/core/base_term.rb +13 -0
- data/lib/mini_kraken/core/blackboard.rb +315 -0
- data/lib/mini_kraken/core/bookmark.rb +46 -0
- data/lib/mini_kraken/core/context.rb +492 -0
- data/lib/mini_kraken/core/duck_fiber.rb +21 -19
- data/lib/mini_kraken/core/entry.rb +40 -0
- data/lib/mini_kraken/core/fail.rb +20 -18
- data/lib/mini_kraken/core/fusion.rb +29 -0
- data/lib/mini_kraken/core/goal.rb +20 -29
- data/lib/mini_kraken/core/log_var.rb +22 -0
- data/lib/mini_kraken/core/log_var_ref.rb +108 -0
- data/lib/mini_kraken/core/nullary_relation.rb +2 -9
- data/lib/mini_kraken/core/parametrized_term.rb +61 -0
- data/lib/mini_kraken/core/relation.rb +14 -28
- data/lib/mini_kraken/core/scope.rb +67 -0
- data/lib/mini_kraken/core/solver_adapter.rb +58 -0
- data/lib/mini_kraken/core/specification.rb +48 -0
- data/lib/mini_kraken/core/succeed.rb +21 -17
- data/lib/mini_kraken/core/symbol_table.rb +137 -0
- data/lib/mini_kraken/core/term.rb +15 -4
- data/lib/mini_kraken/glue/dsl.rb +45 -81
- data/lib/mini_kraken/glue/run_star_expression.rb +28 -30
- data/lib/mini_kraken/rela/all_rela.rb +8 -0
- data/lib/mini_kraken/rela/binary_relation.rb +30 -0
- data/lib/mini_kraken/rela/conde.rb +143 -0
- data/lib/mini_kraken/rela/conj2.rb +65 -0
- data/lib/mini_kraken/rela/def_relation.rb +93 -0
- data/lib/mini_kraken/rela/disj2.rb +70 -0
- data/lib/mini_kraken/rela/fresh.rb +98 -0
- data/lib/mini_kraken/{core → rela}/goal_relation.rb +7 -9
- data/lib/mini_kraken/rela/unify.rb +258 -0
- data/lib/mini_kraken/version.rb +1 -1
- data/mini_kraken.gemspec +2 -2
- data/spec/.rubocop.yml +1 -1
- data/spec/atomic/atomic_term_spec.rb +98 -0
- data/spec/{core → atomic}/k_boolean_spec.rb +19 -34
- data/spec/{core → atomic}/k_symbol_spec.rb +3 -16
- data/spec/composite/cons_cell_spec.rb +225 -0
- data/spec/composite/cons_cell_visitor_spec.rb +158 -0
- data/spec/composite/list_spec.rb +50 -0
- data/spec/core/any_value_spec.rb +52 -0
- data/spec/core/arity_spec.rb +92 -0
- data/spec/core/association_copy_spec.rb +69 -0
- data/spec/core/association_spec.rb +31 -4
- data/spec/core/blackboard_spec.rb +287 -0
- data/spec/core/bookmark_spec.rb +40 -0
- data/spec/core/context_spec.rb +245 -0
- data/spec/core/core_spec.rb +40 -0
- data/spec/core/duck_fiber_spec.rb +16 -46
- data/spec/core/fail_spec.rb +5 -6
- data/spec/core/goal_spec.rb +24 -14
- data/spec/core/log_var_ref_spec.rb +105 -0
- data/spec/core/log_var_spec.rb +64 -0
- data/spec/core/nullary_relation_spec.rb +33 -0
- data/spec/core/parametrized_tem_spec.rb +39 -0
- data/spec/core/relation_spec.rb +33 -0
- data/spec/core/scope_spec.rb +73 -0
- data/spec/core/solver_adapter_spec.rb +70 -0
- data/spec/core/specification_spec.rb +43 -0
- data/spec/core/succeed_spec.rb +5 -5
- data/spec/core/symbol_table_spec.rb +142 -0
- data/spec/glue/dsl_chap1_spec.rb +96 -144
- data/spec/glue/dsl_chap2_spec.rb +350 -0
- data/spec/glue/run_star_expression_spec.rb +82 -906
- data/spec/rela/conde_spec.rb +153 -0
- data/spec/rela/conj2_spec.rb +123 -0
- data/spec/rela/def_relation_spec.rb +119 -0
- data/spec/rela/disj2_spec.rb +117 -0
- data/spec/rela/fresh_spec.rb +147 -0
- data/spec/rela/unify_spec.rb +369 -0
- data/spec/support/factory_atomic.rb +29 -0
- data/spec/support/factory_composite.rb +21 -0
- data/spec/support/factory_methods.rb +11 -26
- metadata +100 -64
- data/lib/mini_kraken/core/association_walker.rb +0 -183
- data/lib/mini_kraken/core/atomic_term.rb +0 -67
- data/lib/mini_kraken/core/base_arg.rb +0 -10
- data/lib/mini_kraken/core/binary_relation.rb +0 -63
- data/lib/mini_kraken/core/composite_goal.rb +0 -46
- data/lib/mini_kraken/core/composite_term.rb +0 -41
- data/lib/mini_kraken/core/conde.rb +0 -143
- data/lib/mini_kraken/core/conj2.rb +0 -79
- data/lib/mini_kraken/core/cons_cell.rb +0 -82
- data/lib/mini_kraken/core/def_relation.rb +0 -50
- data/lib/mini_kraken/core/designation.rb +0 -55
- data/lib/mini_kraken/core/disj2.rb +0 -72
- data/lib/mini_kraken/core/environment.rb +0 -73
- data/lib/mini_kraken/core/equals.rb +0 -156
- data/lib/mini_kraken/core/formal_arg.rb +0 -22
- data/lib/mini_kraken/core/formal_ref.rb +0 -25
- data/lib/mini_kraken/core/freshness.rb +0 -45
- data/lib/mini_kraken/core/goal_arg.rb +0 -12
- data/lib/mini_kraken/core/goal_template.rb +0 -62
- data/lib/mini_kraken/core/k_boolean.rb +0 -35
- data/lib/mini_kraken/core/outcome.rb +0 -53
- data/lib/mini_kraken/core/variable.rb +0 -41
- data/lib/mini_kraken/core/variable_ref.rb +0 -78
- data/lib/mini_kraken/core/vocabulary.rb +0 -442
- data/lib/mini_kraken/glue/fresh_env.rb +0 -75
- data/spec/core/association_walker_spec.rb +0 -192
- data/spec/core/conde_spec.rb +0 -147
- data/spec/core/conj2_spec.rb +0 -114
- data/spec/core/cons_cell_spec.rb +0 -107
- data/spec/core/def_relation_spec.rb +0 -96
- data/spec/core/disj2_spec.rb +0 -99
- data/spec/core/environment_spec.rb +0 -142
- data/spec/core/equals_spec.rb +0 -304
- data/spec/core/goal_template_spec.rb +0 -74
- data/spec/core/outcome_spec.rb +0 -48
- data/spec/core/variable_ref_spec.rb +0 -27
- data/spec/core/variable_spec.rb +0 -35
- data/spec/core/vocabulary_spec.rb +0 -219
- data/spec/glue/fresh_env_spec.rb +0 -62
@@ -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
|
data/spec/core/outcome_spec.rb
DELETED
@@ -1,48 +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 its parent' do
|
29
|
-
expect(subject.parent).to eq(voc)
|
30
|
-
end
|
31
|
-
end # context
|
32
|
-
|
33
|
-
context 'Provided services:' do
|
34
|
-
it 'should have a factory for failing outcome' do
|
35
|
-
instance = Outcome.failure(voc)
|
36
|
-
expect(instance.resultant).to eq(:"#u")
|
37
|
-
expect(instance.parent).to eq(voc)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should have a factory for succeeding outcome' do
|
41
|
-
instance = Outcome.success(voc)
|
42
|
-
expect(instance.resultant).to eq(:"#s")
|
43
|
-
expect(instance.parent).to eq(voc)
|
44
|
-
end
|
45
|
-
end # context
|
46
|
-
end # describe
|
47
|
-
end # module
|
48
|
-
end # module
|
@@ -1,27 +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
|
-
end # context
|
25
|
-
end # describe
|
26
|
-
end # module
|
27
|
-
end # module
|
data/spec/core/variable_spec.rb
DELETED
@@ -1,35 +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
|
-
# Load the class under test
|
7
|
-
require_relative '../../lib/mini_kraken/core/variable'
|
8
|
-
|
9
|
-
|
10
|
-
module MiniKraken
|
11
|
-
module Core
|
12
|
-
describe Variable do
|
13
|
-
let(:env) { Environment.new }
|
14
|
-
subject { Variable.new('q') }
|
15
|
-
|
16
|
-
context 'Initialization:' do
|
17
|
-
it 'should be initialized with a name' do
|
18
|
-
expect { Variable.new('q') }.not_to raise_error
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should know its name' do
|
22
|
-
expect(subject.name).to eq('q')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should be fresh by default' do
|
26
|
-
env.add_var(subject)
|
27
|
-
expect(subject.fresh?(env)).to be_truthy
|
28
|
-
end
|
29
|
-
end # context
|
30
|
-
|
31
|
-
context 'Provided services:' do
|
32
|
-
end # context
|
33
|
-
end # describe
|
34
|
-
end # module
|
35
|
-
end # module
|
@@ -1,219 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../spec_helper' # Use the RSpec framework
|
4
|
-
require_relative '../../lib/mini_kraken/core/k_symbol'
|
5
|
-
require_relative '../../lib/mini_kraken/core/variable'
|
6
|
-
require_relative '../../lib/mini_kraken/core/variable_ref'
|
7
|
-
require_relative '../support/factory_methods'
|
8
|
-
|
9
|
-
# Load the class under test
|
10
|
-
# frozen_string_literal: true
|
11
|
-
|
12
|
-
require_relative '../../lib/mini_kraken/core/vocabulary'
|
13
|
-
|
14
|
-
module MiniKraken
|
15
|
-
module Core
|
16
|
-
class TestVocabulary
|
17
|
-
include Vocabulary
|
18
|
-
|
19
|
-
def initialize(aParent = nil)
|
20
|
-
init_vocabulary(aParent)
|
21
|
-
end
|
22
|
-
end # class
|
23
|
-
|
24
|
-
# Helper module that simulates an environment-like object.
|
25
|
-
module VariableBearer
|
26
|
-
attr_reader :vars
|
27
|
-
attr_accessor :ivars
|
28
|
-
|
29
|
-
def init_var_bearer
|
30
|
-
@vars = {}
|
31
|
-
@ivars = {}
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def add_var(aVarName)
|
36
|
-
vars[aVarName] = Variable.new(aVarName)
|
37
|
-
ivars[aVarName] = Set.new([aVarName])
|
38
|
-
end
|
39
|
-
end # module
|
40
|
-
|
41
|
-
describe Vocabulary do
|
42
|
-
include FactoryMethods
|
43
|
-
|
44
|
-
let(:parent) { TestVocabulary.new }
|
45
|
-
subject { TestVocabulary.new }
|
46
|
-
|
47
|
-
context 'Initialization:' do
|
48
|
-
it 'could be initialized without a parent' do
|
49
|
-
expect { TestVocabulary.new }.not_to raise_error
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'could be initialized with a parent' do
|
53
|
-
expect { TestVocabulary.new(parent) }.not_to raise_error
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should know its parent (if any)' do
|
57
|
-
expect(subject.parent).to be_nil
|
58
|
-
instance = TestVocabulary.new(parent)
|
59
|
-
expect(instance.parent).to eq(parent)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should have no associations at initialization' do
|
63
|
-
expect(subject.associations).to be_empty
|
64
|
-
end
|
65
|
-
end # context
|
66
|
-
|
67
|
-
context 'Provided services:' do
|
68
|
-
let(:pea) { KSymbol.new(:pea) }
|
69
|
-
let(:pod) { KSymbol.new(:pod) }
|
70
|
-
let(:ref_q) { VariableRef.new('q') }
|
71
|
-
let(:ref_x) { VariableRef.new('x') }
|
72
|
-
let(:grandma) do
|
73
|
-
voc = TestVocabulary.new
|
74
|
-
voc.extend(VariableBearer)
|
75
|
-
voc.init_var_bearer
|
76
|
-
end
|
77
|
-
let(:mother) { TestVocabulary.new(grandma) }
|
78
|
-
subject { TestVocabulary.new(mother) }
|
79
|
-
|
80
|
-
it 'should provide a walker over ancestors' do
|
81
|
-
walker = subject.ancestor_walker
|
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
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should know if a variable is defined' do
|
90
|
-
expect(subject.include?('q')).to be_falsey
|
91
|
-
grandma.add_var('x')
|
92
|
-
expect(subject.include?('q')).to be_falsey
|
93
|
-
expect(grandma.include?('x')).to be_truthy
|
94
|
-
expect(mother.include?('x')).to be_truthy
|
95
|
-
expect(subject.include?('x')).to be_truthy
|
96
|
-
subject.extend(VariableBearer)
|
97
|
-
subject.init_var_bearer
|
98
|
-
subject.add_var('y')
|
99
|
-
expect(subject.include?('y')).to be_truthy
|
100
|
-
expect(mother.include?('y')).to be_falsey
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should allow the addition of associations' do
|
104
|
-
grandma.add_var('q')
|
105
|
-
expect(subject['q']).to be_empty
|
106
|
-
res_add = mother.add_assoc('q', pea)
|
107
|
-
expect(res_add).to be_kind_of(Association)
|
108
|
-
expect(subject['q'].size).to eq(1)
|
109
|
-
expect(subject['q'].first.value).to eq(pea)
|
110
|
-
|
111
|
-
subject.add_assoc('q', ref_x)
|
112
|
-
expect(subject['q'].size).to eq(2)
|
113
|
-
expect(subject['q'].first.value).to eq(ref_x)
|
114
|
-
expect(subject['q'].last.value).to eq(pea)
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'should allow the deletion of associations' do
|
118
|
-
grandma.add_var('q')
|
119
|
-
mother.add_assoc('q', pea)
|
120
|
-
subject.add_assoc('q', ref_x)
|
121
|
-
expect(mother.associations.size).to eq(1)
|
122
|
-
expect(subject.associations.size).to eq(1)
|
123
|
-
|
124
|
-
subject.clear
|
125
|
-
expect(subject.associations).to be_empty
|
126
|
-
|
127
|
-
mother.clear
|
128
|
-
expect(mother.associations).to be_empty
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'should say fresh when a variable has no association at all' do
|
132
|
-
grandma.add_var('q')
|
133
|
-
grandma.add_var('x')
|
134
|
-
expect(subject.fresh?(ref_q)).to be_truthy
|
135
|
-
subject.add_assoc('q', ref_x) # Dependency: q --> x
|
136
|
-
expect(subject.fresh?(ref_x)).to be_truthy
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'should say not fresh when variable --> atomic value' do
|
140
|
-
grandma.add_var('q')
|
141
|
-
grandma.add_var('x')
|
142
|
-
subject.add_assoc('q', ref_x) # Dependency: q --> x
|
143
|
-
expect(subject.fresh?(ref_q)).to be_truthy
|
144
|
-
|
145
|
-
# Associate with an atomic term
|
146
|
-
subject.add_assoc('q', pea)
|
147
|
-
expect(subject.fresh?(ref_q)).to be_falsey
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'should say not fresh when variable --> composite of atomics' do
|
151
|
-
grandma.add_var('q')
|
152
|
-
|
153
|
-
# Composite having only atomic terms as leaf elements
|
154
|
-
expr = cons(pea, cons(pod))
|
155
|
-
subject.add_assoc('q', expr)
|
156
|
-
expect(subject.fresh?(ref_q)).to be_falsey
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'say not fresh when variable --> composite of atomics & bound var' do
|
160
|
-
grandma.add_var('q')
|
161
|
-
grandma.add_var('x')
|
162
|
-
subject.add_assoc('x', pea) # Dependency: x --> pea
|
163
|
-
expr = cons(pea, cons(pod, cons(ref_x)))
|
164
|
-
subject.add_assoc('q', expr)
|
165
|
-
expect(subject.fresh?(ref_q)).to be_falsey
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'say not fresh when variable --> composite of atomics & fresh var' do
|
169
|
-
grandma.add_var('q')
|
170
|
-
grandma.add_var('x')
|
171
|
-
expr = cons(pea, cons(pod, cons(ref_x)))
|
172
|
-
subject.add_assoc('q', expr)
|
173
|
-
expect(subject.fresh?(ref_q)).to be_truthy
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'say not fresh when variables are fused & one is ground' do
|
177
|
-
grandma.add_var('q')
|
178
|
-
grandma.add_var('x')
|
179
|
-
|
180
|
-
# Beware of cyclic structure
|
181
|
-
subject.add_assoc('q', ref_x) # Dependency: q --> x
|
182
|
-
subject.add_assoc('x', ref_q) # Dependency: x --> q
|
183
|
-
expect(subject.fresh?(ref_x)).to be_truthy
|
184
|
-
expect(subject.fresh?(ref_q)).to be_truthy
|
185
|
-
expect(subject.associations).to be_empty
|
186
|
-
|
187
|
-
# Associate with an atomic term
|
188
|
-
subject.add_assoc('x', pea)
|
189
|
-
expect(subject.fresh?(ref_q)).to be_falsey
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'should rank names sequentially' do
|
193
|
-
2.times do
|
194
|
-
expect(subject.get_rank('a')).to eq(0)
|
195
|
-
expect(subject.get_rank('z')).to eq(1)
|
196
|
-
expect(subject.get_rank('c')).to eq(2)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'should clear the rankings' do
|
201
|
-
expect(subject.get_rank('a')).to eq(0)
|
202
|
-
expect(subject.get_rank('z')).to eq(1)
|
203
|
-
|
204
|
-
subject.clear_rankings
|
205
|
-
expect(grandma.rankings).to be_empty
|
206
|
-
|
207
|
-
expect(subject.get_rank('z')).to eq(0)
|
208
|
-
expect(subject.get_rank('a')).to eq(1)
|
209
|
-
end
|
210
|
-
|
211
|
-
it 'should provide a String representation of itself' do
|
212
|
-
expectation = +"#<#{subject.class}:#{subject.object_id.to_s(16)} @parent="
|
213
|
-
expectation << "#<#{subject.parent.class}:#{subject.parent.object_id.to_s(16)}>>"
|
214
|
-
expect(subject.inspect).to eq(expectation)
|
215
|
-
end
|
216
|
-
end # context
|
217
|
-
end # describe
|
218
|
-
end # module
|
219
|
-
end # module
|
data/spec/glue/fresh_env_spec.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../spec_helper' # Use the RSpec framework
|
4
|
-
require_relative '../../lib/mini_kraken/core/goal'
|
5
|
-
require_relative '../../lib/mini_kraken/core/equals'
|
6
|
-
require_relative '../../lib/mini_kraken/core/fail'
|
7
|
-
require_relative '../../lib/mini_kraken/core/k_symbol'
|
8
|
-
require_relative '../../lib/mini_kraken/core/succeed'
|
9
|
-
|
10
|
-
# Load the class under test
|
11
|
-
require_relative '../../lib/mini_kraken/glue/fresh_env'
|
12
|
-
|
13
|
-
|
14
|
-
module MiniKraken
|
15
|
-
module Glue
|
16
|
-
describe FreshEnv do
|
17
|
-
let(:pea) { Core::KSymbol.new(:pea) }
|
18
|
-
let(:pod) { Core::KSymbol.new(:pod) }
|
19
|
-
let(:sample_goal) do
|
20
|
-
Core::Goal.new(Core::Equals.instance, [pea, pod])
|
21
|
-
end
|
22
|
-
let(:pea_goal) do
|
23
|
-
Core::Goal.new(Core::Equals.instance, [pea, pea])
|
24
|
-
end
|
25
|
-
let(:goal_succeeds) { Core::Goal.new(Core::Succeed.instance, []) }
|
26
|
-
let(:goal_fails) { Core::Goal.new(Core::Fail.instance, []) }
|
27
|
-
subject { FreshEnv.new(['q'], sample_goal) }
|
28
|
-
|
29
|
-
context 'Initialization:' do
|
30
|
-
it 'could be initialized with names and a goal' do
|
31
|
-
expect { FreshEnv.new(['q'], sample_goal) }.not_to raise_error
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'could be initialized with names and goals' do
|
35
|
-
expect { FreshEnv.new(%w[x y], [pea_goal, goal_succeeds]) }.not_to raise_error
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should know its variables' do
|
39
|
-
expect(subject.vars['q']).not_to be_nil
|
40
|
-
|
41
|
-
instance = FreshEnv.new(%w[x y], sample_goal)
|
42
|
-
expect(instance.vars['x']).not_to be_nil
|
43
|
-
expect(instance.vars['y']).not_to be_nil
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should know its goal' do
|
47
|
-
# Single goal at initialization
|
48
|
-
expect(subject.goal).to eq(sample_goal)
|
49
|
-
|
50
|
-
# Multiple goals at initialization
|
51
|
-
instance = FreshEnv.new(['q'], [pea_goal, goal_succeeds])
|
52
|
-
expect(instance.goal.relation.name).to eq('conj2')
|
53
|
-
expect(instance.goal.actuals[0]).to eq(pea_goal)
|
54
|
-
expect(instance.goal.actuals[1]).to eq(goal_succeeds)
|
55
|
-
end
|
56
|
-
end # context
|
57
|
-
|
58
|
-
context 'Provided services:' do
|
59
|
-
end # context
|
60
|
-
end # describe
|
61
|
-
end # module
|
62
|
-
end # module
|