cauldron 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -1
- data/.rspec +1 -0
- data/Gemfile +16 -9
- data/Gemfile.lock +134 -64
- data/README.md +26 -0
- data/Rakefile +24 -99
- data/build_sandbox.rb +41 -0
- data/cucumber.yml +8 -0
- data/features/chop.feature +23 -0
- data/features/create_dynamic_statements.feature +14 -0
- data/features/generate_known_solution.feature +42 -0
- data/features/generate_new_statement.feature +20 -0
- data/features/step_definitions/cauldron_steps.rb +47 -0
- data/features/support/env.rb +1 -1
- data/features/use_existing_statements.feature +23 -0
- data/lib/cauldron.rb +41 -5
- data/lib/cauldron/actualized_composite.rb +35 -0
- data/lib/cauldron/array_collect_template/default.rb +95 -0
- data/lib/cauldron/array_collect_template/template.rb +57 -0
- data/lib/cauldron/builder.rb +60 -0
- data/lib/cauldron/caret.rb +50 -0
- data/lib/cauldron/dynamic_operator.rb +90 -0
- data/lib/cauldron/dynamic_operator_module.rb +140 -0
- data/lib/cauldron/example.rb +18 -0
- data/lib/cauldron/example_set.rb +36 -0
- data/lib/cauldron/histories.rb +53 -0
- data/lib/cauldron/history.rb +34 -0
- data/lib/cauldron/if_relationship.rb +4 -6
- data/lib/cauldron/number_addition_template/add_five.rb +71 -0
- data/lib/cauldron/number_addition_template/template.rb +56 -0
- data/lib/cauldron/operator.rb +62 -0
- data/lib/cauldron/operator/array_reverse_operator.rb +160 -0
- data/lib/cauldron/operator/concat_operator.rb +72 -0
- data/lib/cauldron/operator/hash_key_value_operator.rb +74 -0
- data/lib/cauldron/operator/numeric_operator.rb +115 -0
- data/lib/cauldron/operator/string_asterisk_operator.rb +131 -0
- data/lib/cauldron/operator/to_s_operator.rb +18 -0
- data/lib/cauldron/operator/var_collect_operator.rb +29 -0
- data/lib/cauldron/pot.rb +136 -26
- data/lib/cauldron/scope.rb +24 -0
- data/lib/cauldron/solution/composite.rb +236 -0
- data/lib/cauldron/solution/one.rb +49 -0
- data/lib/cauldron/statement_generator.rb +298 -0
- data/lib/cauldron/template_base.rb +14 -0
- data/lib/cauldron/tracer.rb +55 -0
- data/lib/cauldron/version.rb +1 -1
- data/lib/pry_tester.rb +76 -0
- data/ruby_to_sexp.rb +74 -0
- data/sandbox.rb +7 -0
- data/sexp_to_ruby.rb +150 -0
- data/spec/cauldron/actualized_composite_spec.rb +140 -0
- data/spec/cauldron/array_collect_template/default_spec.rb +41 -0
- data/spec/cauldron/builder_spec.rb +186 -0
- data/spec/cauldron/dynamic/add_number_template_spec.rb +30 -0
- data/spec/cauldron/dynamic_operator_spec.rb +416 -0
- data/spec/cauldron/example_set_spec.rb +49 -0
- data/spec/cauldron/example_spec.rb +33 -0
- data/spec/cauldron/histories_spec.rb +135 -0
- data/spec/cauldron/history_spec.rb +118 -0
- data/spec/cauldron/if_relationship_spec.rb +1 -1
- data/spec/cauldron/operator/array_reverse_operator_spec.rb +73 -0
- data/spec/cauldron/{concat_operator_spec.rb → operator/concat_operator_spec.rb} +30 -12
- data/spec/cauldron/operator/hash_key_value_operator_spec.rb +98 -0
- data/spec/cauldron/operator/numeric_operator_spec.rb +110 -0
- data/spec/cauldron/operator/string_asterisk_operator_spec.rb +196 -0
- data/spec/cauldron/operator/var_collect_operator_spec.rb +38 -0
- data/spec/cauldron/pot_spec.rb +176 -14
- data/spec/cauldron/solution/composite_spec.rb +421 -0
- data/spec/cauldron/solution/one_spec.rb +24 -0
- data/spec/cauldron/statement_generator_spec.rb +211 -0
- data/spec/cauldron/terminal_spec.rb +2 -2
- data/spec/spec_helper.rb +5 -1
- data/spec/support/code_matcher.rb +55 -0
- data/spec/support/include_instance_of_matcher.rb +9 -0
- data/spec/support/shared_examples_for_leaf_operators.rb +22 -0
- data/spec/support/shared_examples_for_operators.rb +23 -0
- data/syntax_spec.txt +2 -0
- metadata +104 -41
- data/README +0 -1
- data/README.rdoc +0 -19
- data/VERSION +0 -1
- data/features/cauldron_new_approach.feature +0 -46
- data/lib/cauldron/array_reverse_operator.rb +0 -39
- data/lib/cauldron/concat_operator.rb +0 -34
- data/lib/cauldron/numeric_operator.rb +0 -45
- data/lib/cauldron/relationship.rb +0 -5
- data/spec/cauldron/array_reverse_operator_spec.rb +0 -59
- data/spec/cauldron/numeric_operator_spec.rb +0 -70
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Cauldron::ArrayCollectTemplate
|
4
|
+
|
5
|
+
describe Default do
|
6
|
+
|
7
|
+
describe '#context_realizable?' do
|
8
|
+
|
9
|
+
context 'var2 is "Sparky"' do
|
10
|
+
|
11
|
+
let(:context) do
|
12
|
+
{:var2=>"Sparky", :var0=>["Sparky", "Kels"], :var1=>nil, :line=>0, :depth=>1, :total_line=>2, :point=>[0, 0]}
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'using the index "2"' do
|
16
|
+
|
17
|
+
let(:subject) { Cauldron::ArrayCollectTemplate::Default.new([2]) }
|
18
|
+
|
19
|
+
it 'is false' do
|
20
|
+
subject.context_realizable?(context).should == false
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'using the index "0"' do
|
26
|
+
|
27
|
+
let(:subject) { Cauldron::ArrayCollectTemplate::Default.new([0]) }
|
28
|
+
|
29
|
+
it 'is true' do
|
30
|
+
subject.context_realizable?(context).should == true
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Cauldron
|
4
|
+
|
5
|
+
describe 'Builder' do
|
6
|
+
|
7
|
+
describe '#insertable_operators' do
|
8
|
+
|
9
|
+
context %q{with history "line: 0, depth:0, var0: ['Sparky','Kel'] "} do
|
10
|
+
|
11
|
+
let(:history) do
|
12
|
+
[
|
13
|
+
{ :params => [['Sparky', 'Kel']], :solution => ['Spark','Ke'],
|
14
|
+
:history => [
|
15
|
+
{ line: 0, depth: 0, total_line: 0, var0: ['Sparky', 'Kel'] }
|
16
|
+
]
|
17
|
+
}
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:examples) do
|
22
|
+
Cauldron::ExampleSet.new(
|
23
|
+
[Example.new({ :arguments => [['Sparky', 'Kel']], :response => ['Spark','Ke'] })]
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:composite) { Cauldron::Solution::Composite.new([]) }
|
28
|
+
|
29
|
+
let(:builder) { Cauldron::Builder.new(composite) }
|
30
|
+
|
31
|
+
it 'results include array ActualizedComposite' do
|
32
|
+
builder.insertable_operators(examples).should include_an_instance_of(Cauldron::ActualizedComposite)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'results do not include a string asterisk' do
|
36
|
+
builder.insertable_operators(examples).should_not include_an_instance_of(StringAsteriskOperator)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context %q{with history "line: 0, depth:0, var0: 'Sparky' "} do
|
42
|
+
|
43
|
+
let(:history) do
|
44
|
+
[
|
45
|
+
{ :params => ['Sparky'], :solution => 'Spark',
|
46
|
+
:history => [
|
47
|
+
{ line: 0, depth: 0, total_line: 0, var0: 'Sparky' }
|
48
|
+
]
|
49
|
+
}
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:examples) do
|
54
|
+
Cauldron::ExampleSet.new(
|
55
|
+
[ Example.new({ :arguments => ['Sparky'], :response => 'Spark' })]
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:composite) { Cauldron::Solution::Composite.new([]) }
|
60
|
+
|
61
|
+
let(:builder) { Cauldron::Builder.new(composite) }
|
62
|
+
|
63
|
+
it 'results do not include array collect' do
|
64
|
+
builder.insertable_operators(examples).should_not include_an_instance_of(Cauldron::ArrayCollectTemplate::Default)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
# describe '#insert_points' do
|
72
|
+
|
73
|
+
# let(:builder) { Cauldron::Builder.new(composite) }
|
74
|
+
|
75
|
+
# context 'empty method' do
|
76
|
+
|
77
|
+
# let(:composite) do
|
78
|
+
# Cauldron::Solution::Composite.new([])
|
79
|
+
# end
|
80
|
+
|
81
|
+
# it 'has 1' do
|
82
|
+
# builder.insert_points.length.should == 1
|
83
|
+
# end
|
84
|
+
|
85
|
+
# it 'is line 0 depth 0' do
|
86
|
+
# builder.insert_points.first.should == [0,0]
|
87
|
+
# end
|
88
|
+
|
89
|
+
# end
|
90
|
+
|
91
|
+
# context 'has line "var0 = 5"' do
|
92
|
+
|
93
|
+
# let(:composite) do
|
94
|
+
# Cauldron::Solution::Composite.new(
|
95
|
+
# [Tree::TreeNode.new('CHILD', NumericOperator.new([0],4))]
|
96
|
+
# )
|
97
|
+
# end
|
98
|
+
|
99
|
+
# it 'has 1' do
|
100
|
+
# builder.insert_points.length.should == 1
|
101
|
+
# end
|
102
|
+
|
103
|
+
# it 'is line 1 depth 0' do
|
104
|
+
# builder.insert_points.first.should == [1,0]
|
105
|
+
# end
|
106
|
+
|
107
|
+
# end
|
108
|
+
|
109
|
+
# context 'has line var0.collect {|x| x }' do
|
110
|
+
|
111
|
+
# let(:composite) do
|
112
|
+
# Cauldron::Solution::Composite.new(
|
113
|
+
# [Tree::TreeNode.new('CHILD', ArrayCollect.new([0]) )]
|
114
|
+
# )
|
115
|
+
# end
|
116
|
+
|
117
|
+
# it 'has 2' do
|
118
|
+
# builder.insert_points.length.should == 2
|
119
|
+
# end
|
120
|
+
|
121
|
+
# it 'has one point at line 1 depth 0' do
|
122
|
+
# builder.insert_points.should include([1,0])
|
123
|
+
# end
|
124
|
+
|
125
|
+
# it 'has one point at line 1 depth 1' do
|
126
|
+
# builder.insert_points.should include([1,1])
|
127
|
+
# end
|
128
|
+
|
129
|
+
# context 'has line "var1 = 6" at line 1 depth 0' do
|
130
|
+
|
131
|
+
# let(:composite) do
|
132
|
+
# Cauldron::Solution::Composite.new(
|
133
|
+
# [
|
134
|
+
# Tree::TreeNode.new('CHILD1', ArrayCollect.new([0]) ),
|
135
|
+
# Tree::TreeNode.new('CHILD2', NumericOperator.new([0],6) )
|
136
|
+
# ]
|
137
|
+
# )
|
138
|
+
# end
|
139
|
+
|
140
|
+
# it 'has 2' do
|
141
|
+
# builder.insert_points.length.should == 2
|
142
|
+
# end
|
143
|
+
|
144
|
+
# it 'has one point at line 2 depth 0' do
|
145
|
+
# builder.insert_points.should include([2,0])
|
146
|
+
# end
|
147
|
+
|
148
|
+
# it 'has one point at line 1 depth 1' do
|
149
|
+
# builder.insert_points.should include([1,1])
|
150
|
+
# end
|
151
|
+
|
152
|
+
# end
|
153
|
+
|
154
|
+
# context 'has line "var2 = 7" at line 2 depth 0' do
|
155
|
+
|
156
|
+
# let(:composite) do
|
157
|
+
# Cauldron::Solution::Composite.new(
|
158
|
+
# [
|
159
|
+
# Tree::TreeNode.new('CHILD1', ArrayCollect.new([0]) ),
|
160
|
+
# Tree::TreeNode.new('CHILD2', NumericOperator.new([0],6) ),
|
161
|
+
# Tree::TreeNode.new('CHILD3', NumericOperator.new([0],7) )
|
162
|
+
# ]
|
163
|
+
# )
|
164
|
+
# end
|
165
|
+
|
166
|
+
# it 'has 2' do
|
167
|
+
# builder.insert_points.length.should == 2
|
168
|
+
# end
|
169
|
+
|
170
|
+
# it 'has one point at line 3 depth 0' do
|
171
|
+
# builder.insert_points.should include([3,0])
|
172
|
+
# end
|
173
|
+
|
174
|
+
# it 'has one point at line 1 depth 1' do
|
175
|
+
# builder.insert_points.should include([1,1])
|
176
|
+
# end
|
177
|
+
|
178
|
+
# end
|
179
|
+
|
180
|
+
# end
|
181
|
+
|
182
|
+
# end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Cauldron
|
4
|
+
|
5
|
+
describe 'DynamicNumberAddition' do
|
6
|
+
|
7
|
+
let(:generator) do
|
8
|
+
Cauldron::StatementGenerator.new.build_template(4, '+')
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'given the example a = 4; return 6' do
|
12
|
+
|
13
|
+
let(:examples) do
|
14
|
+
Cauldron::ExampleSet.new(
|
15
|
+
[
|
16
|
+
Cauldron::Example.new({arguments: [4], response: 6}),
|
17
|
+
]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'generates a statement a + 2' do
|
22
|
+
pending
|
23
|
+
generator.statement_classes(examples).should include_statement("a + 2")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,416 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Cauldron
|
4
|
+
|
5
|
+
describe DynamicOperator do
|
6
|
+
|
7
|
+
describe '#extend_validation' do
|
8
|
+
|
9
|
+
# PENDING - it should add more tracking as sexp
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#branch?' do
|
13
|
+
|
14
|
+
context 'var0.chop' do
|
15
|
+
|
16
|
+
let(:dynamic_operator) do
|
17
|
+
StatementGenerator.new.default_template('string',:chop).new([0])
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'is false' do
|
21
|
+
dynamic_operator.branch?.should == false
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'var1 = var0.collect { |var2| var2}' do
|
27
|
+
|
28
|
+
let(:dynamic_operator) do
|
29
|
+
StatementGenerator.new.default_template(
|
30
|
+
['00sjack00','RowIAGE', 'iNathalie'],
|
31
|
+
:collect
|
32
|
+
).new([0])
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'is true' do
|
36
|
+
dynamic_operator.branch?.should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#to_sexp' do
|
44
|
+
|
45
|
+
context 'var1 = var0.collect { |var2| var2}' do
|
46
|
+
|
47
|
+
let(:dynamic_operator) do
|
48
|
+
StatementGenerator.new.default_template(
|
49
|
+
['00sjack00','RowIAGE', 'iNathalie'],
|
50
|
+
:collect
|
51
|
+
).new([0])
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:scope) { Cauldron::Scope.new(['var0']) }
|
55
|
+
|
56
|
+
it 'is var1 = var0.collect { |var2| var2}' do
|
57
|
+
dynamic_operator.to_sexp(scope,[]).should match_code_of(%q{
|
58
|
+
var1 = var0.collect do |var2|
|
59
|
+
end
|
60
|
+
}
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'scope contains two parameters' do
|
65
|
+
|
66
|
+
let(:scope) { Cauldron::Scope.new(['var0', 'var1']) }
|
67
|
+
|
68
|
+
it 'is var1 = var0.collect { |var2| var2}' do
|
69
|
+
dynamic_operator.to_sexp(scope,[]).should match_code_of(%q{
|
70
|
+
var2 = var0.collect do |var3|
|
71
|
+
|
72
|
+
end
|
73
|
+
}
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#realizable?' do
|
84
|
+
|
85
|
+
context 'var1 = var0.collect { |var2| var2}' do
|
86
|
+
|
87
|
+
let(:dynamic_operator) do
|
88
|
+
StatementGenerator.new.default_template(['a','b','c'],:collect).new([0])
|
89
|
+
end
|
90
|
+
|
91
|
+
context "when var0 only value is ['a','b','c']" do
|
92
|
+
|
93
|
+
let(:histories) do
|
94
|
+
Cauldron::Histories.new([Cauldron::History.new([{var0: ['a','b','c']}])])
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'is true' do
|
98
|
+
dynamic_operator.realizable?(histories, [0,0]).should == true
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when var0 only value "string"' do
|
104
|
+
|
105
|
+
let(:histories) do
|
106
|
+
Cauldron::Histories.new([Cauldron::History.new([{var0: "string"}])])
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'is false' do
|
110
|
+
dynamic_operator.realizable?(histories, [0,0]).should == false
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
context %q{adding statement inside:
|
116
|
+
var1 = var0.collect do |var2|
|
117
|
+
end
|
118
|
+
} do
|
119
|
+
|
120
|
+
let(:containing_statement) do
|
121
|
+
StatementGenerator.new.default_template(['a','b','c'],:collect).new([0])
|
122
|
+
end
|
123
|
+
|
124
|
+
let(:examples) do
|
125
|
+
Cauldron::ExampleSet.new(
|
126
|
+
[Cauldron::Example.new({ arguments: [["lion", "bear"]], response: ["bear", "lion"]})]
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
let(:composite) do
|
131
|
+
Cauldron::Solution::Composite.new(
|
132
|
+
[Tree::TreeNode.new("CHILD1", containing_statement )]
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
let(:histories) do
|
137
|
+
Cauldron::ActualizedComposite.new(composite,examples).histories
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'adding statement "var3 = var2.collect { |var4| var4}"' do
|
141
|
+
|
142
|
+
let(:dynamic_operator) do
|
143
|
+
StatementGenerator.new.default_template(['a','b','c'],:collect).new([2])
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'is false' do
|
147
|
+
dynamic_operator.realizable?(histories, [0,1]).should == false
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'inserting statement "var3 = var1.collect { |var4| var4}"' do
|
153
|
+
|
154
|
+
let(:dynamic_operator) do
|
155
|
+
StatementGenerator.new.default_template(['a','b','c'],:collect).new([1])
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'is false' do
|
159
|
+
dynamic_operator.realizable?(histories, [0,1]).should == false
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'var0.chop' do
|
169
|
+
|
170
|
+
let(:dynamic_operator) do
|
171
|
+
StatementGenerator.new.default_template('string',:chop).new([0])
|
172
|
+
end
|
173
|
+
|
174
|
+
let(:composite) do
|
175
|
+
Cauldron::Solution::Composite.new(
|
176
|
+
[ Tree::TreeNode.new("CHILD1", dynamic_operator ) ]
|
177
|
+
)
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#context_instances' do
|
181
|
+
|
182
|
+
context %q{describe using [:var0 => 'asdas', :var1 => '3232']} do
|
183
|
+
|
184
|
+
let(:dynamic_operator_class) { StatementGenerator.new.default_template('string',:chop) }
|
185
|
+
|
186
|
+
it 'returns 2 instances' do
|
187
|
+
expect(dynamic_operator_class.context_instances(
|
188
|
+
[
|
189
|
+
{:var0=>["Sparky", "Kels"], :var1=>nil, :line=>0, :depth=>1, :total_line=>3, :point=>[0, 0]},
|
190
|
+
]
|
191
|
+
).length).to eql(2)
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
describe '#context_realizable?' do
|
199
|
+
|
200
|
+
let(:dynamic_operator_class) { StatementGenerator.new.default_template('string',:chop) }
|
201
|
+
|
202
|
+
context 'using var 0' do
|
203
|
+
|
204
|
+
context 'with context "{:var0=>["Sparky", "Kels"], :point=>[0, 0]}"' do
|
205
|
+
|
206
|
+
let(:context) do
|
207
|
+
{:var0=>["Sparky", "Kels"], :point=>[0, 0]}
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'returns false' do
|
211
|
+
expect(dynamic_operator_class.new([0]).context_realizable?(context)).to be false
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'var2 is "Sparky"' do
|
219
|
+
|
220
|
+
let(:context) do
|
221
|
+
{:var2=>"Sparky", :var0=>["Sparky", "Kels"], :var1=>nil, :line=>0, :depth=>1, :total_line=>2, :point=>[0, 0]}
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'using the index "2"' do
|
225
|
+
|
226
|
+
it 'returns true' do
|
227
|
+
expect(dynamic_operator_class.new([2]).context_realizable?(context)).to be true
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
context 'using the index "0"' do
|
233
|
+
|
234
|
+
it 'returns true' do
|
235
|
+
expect(dynamic_operator_class.new([0]).context_realizable?(context)).to be false
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
context %q{adding statement inside:
|
245
|
+
var1 = var0.collect do |var2|
|
246
|
+
end
|
247
|
+
} do
|
248
|
+
|
249
|
+
let(:containing_statement) do
|
250
|
+
StatementGenerator.new.default_template(['lion','bear'],:collect).new([0])
|
251
|
+
end
|
252
|
+
|
253
|
+
context %q{var0 is ["lion", "bear"]} do
|
254
|
+
|
255
|
+
let(:examples) do
|
256
|
+
Cauldron::ExampleSet.new(
|
257
|
+
[Cauldron::Example.new({ arguments: [["lion", "bear"]], response: ["bear", "lion"]})]
|
258
|
+
)
|
259
|
+
end
|
260
|
+
|
261
|
+
let(:examples) do
|
262
|
+
Cauldron::ExampleSet.new(
|
263
|
+
[Cauldron::Example.new({ arguments: [["lion", "bear"]], response: ["bear", "lion"]})]
|
264
|
+
)
|
265
|
+
end
|
266
|
+
|
267
|
+
let(:composite) do
|
268
|
+
Cauldron::Solution::Composite.new(
|
269
|
+
[Tree::TreeNode.new("CHILD1", containing_statement )]
|
270
|
+
)
|
271
|
+
end
|
272
|
+
|
273
|
+
let(:histories) do
|
274
|
+
Cauldron::ActualizedComposite.new(composite,examples).histories
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
describe 'using incompatible variable' do
|
282
|
+
|
283
|
+
context 'when var0 is 8' do
|
284
|
+
|
285
|
+
let(:histories) do
|
286
|
+
Cauldron::Histories.new([Cauldron::History.new([{var0: 8}])])
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'saves the failed example' do
|
290
|
+
expect{
|
291
|
+
dynamic_operator.realizable?(histories, [0,0])
|
292
|
+
}.to change{
|
293
|
+
dynamic_operator.failed_uses.length
|
294
|
+
}.from(0).to(1)
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
context 'when var0 is 8' do
|
302
|
+
|
303
|
+
let(:scope) { Cauldron::Scope.new(['var0']) }
|
304
|
+
|
305
|
+
let(:examples) do
|
306
|
+
Cauldron::ExampleSet.new(
|
307
|
+
[
|
308
|
+
Cauldron::Example.new({arguments: [8], response: 8}),
|
309
|
+
]
|
310
|
+
)
|
311
|
+
end
|
312
|
+
|
313
|
+
let(:histories) do
|
314
|
+
Cauldron::Histories.new(
|
315
|
+
[Cauldron::History.new([{var0: 8}])]
|
316
|
+
)
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'returns false' do
|
320
|
+
dynamic_operator.should_not be_realizable(histories, [0,0])
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
context 'when var0 is "test"' do
|
326
|
+
|
327
|
+
let(:scope) { Cauldron::Scope.new(['var0']) }
|
328
|
+
|
329
|
+
let(:examples) do
|
330
|
+
Cauldron::ExampleSet.new(
|
331
|
+
[
|
332
|
+
Cauldron::Example.new({arguments: ['test'], response: 'sdsas'}),
|
333
|
+
]
|
334
|
+
)
|
335
|
+
end
|
336
|
+
|
337
|
+
let(:histories) do
|
338
|
+
Cauldron::Histories.new(
|
339
|
+
[Cauldron::History.new([{var0: 'test'}])]
|
340
|
+
)
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'returns true' do
|
344
|
+
dynamic_operator.should be_realizable(histories,[0,0])
|
345
|
+
end
|
346
|
+
|
347
|
+
context 'when the history has "Sparky", "Kel"' do
|
348
|
+
|
349
|
+
let(:histories) do
|
350
|
+
Cauldron::Histories.new(
|
351
|
+
[
|
352
|
+
Cauldron::History.new([{:var0=>"Sparky", :line=>0, :depth=>0, :total_line=>0}]),
|
353
|
+
Cauldron::History.new([{:var0=>"Kel", :line=>0, :depth=>0, :total_line=>0}])
|
354
|
+
]
|
355
|
+
)
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'returns true' do
|
359
|
+
dynamic_operator.should be_realizable(histories,[0,0])
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|
365
|
+
|
366
|
+
end
|
367
|
+
|
368
|
+
end
|
369
|
+
|
370
|
+
describe '#write_to_file' do
|
371
|
+
|
372
|
+
let(:filename) { 'temp.rb' }
|
373
|
+
|
374
|
+
let(:sexp) do
|
375
|
+
[:program,
|
376
|
+
[:stmts_add,
|
377
|
+
[:stmts_new],
|
378
|
+
[:def,
|
379
|
+
[:@ident, "test", [2, 4]],
|
380
|
+
[:paren,
|
381
|
+
[:params, [[:@ident, "var0", [2, 9]]], nil, nil, nil, nil, nil, nil]],
|
382
|
+
[:bodystmt,
|
383
|
+
[:stmts_add,
|
384
|
+
[:stmts_new],
|
385
|
+
[:call,
|
386
|
+
[:var_ref, [:@ident, "var0", [3, 2]]],
|
387
|
+
:".",
|
388
|
+
[:@ident, "bounce", [3, 7]]]],
|
389
|
+
nil,
|
390
|
+
nil,
|
391
|
+
nil]]]]
|
392
|
+
end
|
393
|
+
|
394
|
+
let(:dynamic_operator) do
|
395
|
+
DynamicOperator.new({}, sexp)
|
396
|
+
end
|
397
|
+
|
398
|
+
before(:each) do
|
399
|
+
if File.exists? File.join('tmp', 'temp.rb')
|
400
|
+
FileUtils.rm File.join('tmp', 'temp.rb')
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'creates a file "tmp/temp.rb"' do
|
405
|
+
expect{
|
406
|
+
dynamic_operator.write_to_file('temp.rb')
|
407
|
+
}.to change{
|
408
|
+
File.exists?( File.join('tmp', 'temp.rb') )
|
409
|
+
}.from(false).to(true)
|
410
|
+
end
|
411
|
+
|
412
|
+
end
|
413
|
+
|
414
|
+
end
|
415
|
+
|
416
|
+
end
|