cauldron 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Rakefile +7 -0
- data/VERSION +1 -1
- data/features/cauldron_generates_runtime_method.feature +3 -2
- data/features/step_definitions/cauldron_steps.rb +0 -1
- data/features/support/method_1.example +3 -0
- data/features/support/method_2.example +6 -0
- data/lib/Chain.rb +140 -264
- data/lib/CodeHandler.rb +0 -4
- data/lib/ScopeDependencies.rb +1 -0
- data/lib/Theory.rb +12 -15
- data/lib/UnifiedChain.rb +265 -8
- data/lib/cauldron.rb +1 -1
- data/lib/cauldron/demos.rb +280 -0
- data/lib/cauldron/pot.rb +56 -30
- data/lib/cauldron/sexp2cauldron.rb +109 -126
- data/lib/cauldron/terminal.rb +5 -74
- data/lib/core/ClassMethodCallContainer.rb +14 -0
- data/lib/core/Container.rb +12 -2
- data/lib/core/InstanceCallContainer.rb +30 -4
- data/lib/core/TheoryGenerator.rb +2 -9
- data/lib/core/assignment/Equal.rb +1 -1
- data/lib/core/assignment/Equivalent.rb +1 -1
- data/lib/core/assignment/NotEqual.rb +1 -1
- data/lib/core/call_container/CallContainer.rb +7 -1
- data/lib/core/instance_call/Chop.rb +0 -9
- data/lib/core/instance_call/instance_calls.rb +8 -0
- data/lib/core/instance_call/length_equal.rb +1 -1
- data/lib/core/requirement/Requirement.rb +1 -0
- data/lib/core/runtime_class/class_names.rb +12 -12
- data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +0 -7
- data/lib/core/runtime_method/RuntimeMethod.rb +59 -45
- data/lib/core/statement/ActsAsStatement.rb +1 -1
- data/lib/core/statement/ArrayAccess.rb +28 -2
- data/lib/core/statement/OpenStatement.rb +7 -0
- data/lib/core/statement/Statement.rb +22 -18
- data/lib/core/statement/TheoryStatement.rb +8 -1
- data/lib/core/syntax/Addition.rb +3 -2
- data/lib/core/syntax/If.rb +8 -0
- data/lib/core/syntax/Return.rb +1 -1
- data/lib/core/variable/BaseVariable.rb +0 -2
- data/lib/core/variable/MethodParameter.rb +4 -31
- data/lib/core/variable/Unknown.rb +1 -5
- data/lib/implemented_chain.rb +3 -2
- data/lib/required.rb +0 -1
- data/lib/ruby_code/String.rb +0 -17
- data/lib/theories.rb +25 -1
- data/lib/theory/TheoryAction.rb +35 -5
- data/lib/theory/TheoryChainValidator.rb +10 -8
- data/lib/theory/TheoryComponent.rb +17 -0
- data/lib/theory/TheoryConnector.rb +76 -9
- data/lib/theory/TheoryDependent.rb +2 -2
- data/lib/theory/TheoryImplementation.rb +7 -7
- data/lib/util/ClassEvaluation.rb +2 -7
- data/lib/util/MethodValidation.rb +10 -6
- data/lib/util/Parser.rb +26 -20
- data/lib/util/StringToTheory.rb +27 -3
- data/spec/cauldron/chain_spec.rb +24 -0
- data/spec/cauldron/demos_spec.rb +30 -0
- data/spec/cauldron/pot_spec.rb +66 -0
- data/spec/cauldron/runtime_method_spec.rb +47 -5
- data/spec/cauldron/sexp_2_cauldron_spec.rb +92 -0
- data/spec/cauldron/terminal_spec.rb +1 -1
- data/spec/cauldron/theory_action_spec.rb +20 -0
- data/spec/cauldron/theory_connector_spec.rb +52 -0
- data/spec/cauldron/theory_spec.rb +59 -0
- data/spec/cauldron/unified_chain_spec.rb +102 -0
- data/spec/spec_helper.rb +10 -1
- data/tasks/theory_tasks.rake +274 -0
- data/test/fixtures/implementation_results/0/dump +0 -0
- data/test/fixtures/theories/0/dump +0 -0
- data/test/fixtures/theories/1/dump +0 -0
- data/test/fixtures/theories/10/dump +0 -0
- data/test/fixtures/theories/11/dump +0 -0
- data/test/fixtures/theories/12/dump +0 -0
- data/test/fixtures/theories/13/declaration.txt +1 -1
- data/test/fixtures/theories/13/desc +1 -1
- data/test/fixtures/theories/13/dump +0 -0
- data/test/fixtures/theories/14/dump +0 -0
- data/test/fixtures/theories/15/dump +0 -0
- data/test/fixtures/theories/16/dump +0 -0
- data/test/fixtures/theories/17/dump +0 -0
- data/test/fixtures/theories/18/dump +0 -0
- data/test/fixtures/theories/19/dump +0 -0
- data/test/fixtures/theories/2/dump +0 -0
- data/test/fixtures/theories/20/declaration.txt +1 -1
- data/test/fixtures/theories/20/desc +1 -1
- data/test/fixtures/theories/20/dump +0 -0
- data/test/fixtures/theories/3/dump +0 -0
- data/test/fixtures/theories/4/dump +0 -0
- data/test/fixtures/theories/5/dump +0 -0
- data/test/fixtures/theories/6/dump +0 -0
- data/test/fixtures/theories/7/dump +0 -0
- data/test/fixtures/theories/8/dump +0 -0
- data/test/fixtures/theories/9/dump +0 -0
- data/test/fixtures/theory_implementations/0/declaration.txt +1 -1
- data/test/fixtures/theory_implementations/0/dump +0 -0
- data/test/fixtures/theory_implementations/1/declaration.txt +11 -0
- data/test/fixtures/theory_implementations/1/dump +0 -0
- data/test/fixtures/theory_implementations/2/declaration.txt +11 -0
- data/test/fixtures/theory_implementations/2/dump +0 -0
- data/test/output/simple_method.txt +0 -1
- data/test/tc_contextual_variables.rb +2 -41
- data/test/tc_describe.rb +1 -2
- data/test/tc_method.rb +2 -5
- data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +5 -3
- data/test/unit/core/runtime_method/tc_runtime_method.rb +34 -56
- data/test/unit/core/statement/tc_block_statement.rb +2 -0
- data/test/unit/core/statement/tc_open_statement.rb +15 -6
- data/test/unit/core/statement/tc_statement.rb +4 -5
- data/test/unit/core/statement/tc_statement_dependencies.rb +1 -0
- data/test/unit/core/statement/tc_theory_statement.rb +2 -0
- data/test/unit/core/syntax/tc_if_container.rb +5 -5
- data/test/unit/core/tc_theory_generator_heavy.rb +1 -1
- data/test/unit/core/tracking/tc_history.rb +3 -1
- data/test/unit/core/variable/tc_method_parameter_variable.rb +2 -2
- data/test/unit/tc_chain_with_case_1.rb +1 -1
- data/test/unit/tc_method_usage.rb +1 -1
- data/test/unit/tc_theory.rb +8 -2
- data/test/unit/theory/tc_theory_action.rb +37 -5
- data/test/unit/theory/tc_theory_chain_validator.rb +3 -3
- data/test/unit/theory/tc_theory_connector.rb +2 -37
- data/test/unit/theory/tc_theory_dependent.rb +2 -0
- data/test/unit/theory/tc_theory_implementation.rb +5 -1
- data/test/unit/theory/tc_theory_result.rb +3 -2
- data/test/unit/util/tc_method_validation.rb +4 -1
- data/test/unit/util/tc_parser.rb +2 -0
- data/test/unit/util/tc_string_to_theory.rb +3 -2
- data/tmp/runtime_method_evaluation.rb +7 -4
- metadata +59 -13
- data/lib/core/syntax/IfContainer.rb +0 -100
data/spec/cauldron/pot_spec.rb
CHANGED
@@ -2,5 +2,71 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Cauldron
|
4
4
|
|
5
|
+
describe 'Pot' do
|
6
|
+
|
7
|
+
describe '#simmer' do
|
8
|
+
it 'can simmer with demo one' do
|
9
|
+
pot = Cauldron::Pot.new
|
10
|
+
pot.clear
|
11
|
+
lambda {pot.simmer(demo_one)}.should_not raise_error
|
12
|
+
end
|
13
|
+
it 'can simmer with demo two' do
|
14
|
+
pot = Cauldron::Pot.new
|
15
|
+
pot.clear
|
16
|
+
lambda {pot.simmer(demo_two)}.should_not raise_error
|
17
|
+
end
|
18
|
+
it 'can simmer with both demo one and two' do
|
19
|
+
pot = Cauldron::Pot.new
|
20
|
+
pot.clear
|
21
|
+
lambda {pot.simmer(demo_one)}.should_not raise_error
|
22
|
+
lambda {pot.simmer(demo_two)}.should_not raise_error
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#brew' do
|
27
|
+
it 'can come up with a solution after it has been given demo_one' do
|
28
|
+
pot = Cauldron::Pot.new
|
29
|
+
pot.clear
|
30
|
+
pot.simmer(demo_one)
|
31
|
+
cases = []
|
32
|
+
cases << convert_to_example(separate_values("'sparky','sparky'"))
|
33
|
+
cases << convert_to_example(separate_values("'kel','kel'"))
|
34
|
+
|
35
|
+
ruby = "
|
36
|
+
def method_0(var_0)
|
37
|
+
\treturn var_0
|
38
|
+
end
|
39
|
+
"
|
40
|
+
parser = RubyParser.new
|
41
|
+
sexp = parser.process(ruby)
|
42
|
+
sexp2cauldron = Sexp2Cauldron.new
|
43
|
+
pot.brew(cases).reset_ids!.basic_write.should == sexp2cauldron.process(sexp).basic_write
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'can come up with a solution that fits demo two' do
|
47
|
+
pot = Cauldron::Pot.new
|
48
|
+
pot.clear
|
49
|
+
pot.simmer(demo_two)
|
50
|
+
cases = []
|
51
|
+
cases << convert_to_example(separate_values("'carrot','vegtable'"))
|
52
|
+
cases << convert_to_example(separate_values("'fish','animal'"))
|
53
|
+
|
54
|
+
ruby = "
|
55
|
+
def method_0(var_0)
|
56
|
+
\tif(var_0 == 'carrot')
|
57
|
+
\t\treturn 'vegtable'
|
58
|
+
\tend
|
59
|
+
\treturn 'animal'
|
60
|
+
end
|
61
|
+
"
|
62
|
+
parser = RubyParser.new
|
63
|
+
sexp = parser.process(ruby)
|
64
|
+
sexp2cauldron = Sexp2Cauldron.new
|
65
|
+
pot.brew(cases).reset_ids!.basic_write.should == sexp2cauldron.process(sexp).basic_write
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
5
71
|
|
6
72
|
end
|
@@ -7,10 +7,8 @@ def fetch_runtime
|
|
7
7
|
return var_2
|
8
8
|
end
|
9
9
|
!
|
10
|
-
puts basic_runtime
|
11
10
|
res = eval(basic_runtime)
|
12
11
|
sexp = RubyParser.new.process(basic_runtime)
|
13
|
-
p Ruby2Ruby.new.process(sexp)
|
14
12
|
|
15
13
|
end
|
16
14
|
|
@@ -20,15 +18,59 @@ module Cauldron
|
|
20
18
|
describe 'RuntimeMethod' do
|
21
19
|
|
22
20
|
describe '#basic_write' do
|
23
|
-
|
24
21
|
# => TODO I need a factory or better way to write the runtime methods
|
25
22
|
it 'should return a string of the built method without comment information' do
|
26
23
|
method_param = MethodParameter.new
|
27
24
|
temporary_runtime_method = RuntimeMethod.new(MethodUsage.new(method_param))
|
28
25
|
temporary_runtime_method << Statement.new(Return.new,method_param)
|
29
|
-
temporary_runtime_method.basic_write.should == "def
|
26
|
+
temporary_runtime_method.reset_ids!.basic_write.should == "def method_0(var_0)\n\treturn var_0\nend\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#reset_ids!' do
|
31
|
+
context 'runtime method is empty' do
|
32
|
+
it 'should return a new runtime method with the method id and variables starting from 0(this is for comparision)' do
|
33
|
+
parser = RubyParser.new
|
34
|
+
ruby = "
|
35
|
+
def method_8
|
36
|
+
end
|
37
|
+
"
|
38
|
+
sexp = parser.process(ruby)
|
39
|
+
sexp2cauldron = Sexp2Cauldron.new
|
40
|
+
unprocessed_runtime_method = sexp2cauldron.process(sexp)
|
41
|
+
reset_runtime_method = unprocessed_runtime_method.reset_ids!
|
42
|
+
reset_runtime_method.method_id.should == '0'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context 'using runtime method with if statement' do
|
46
|
+
it 'it should reset all the ids to 0 and count up' do
|
47
|
+
parser = RubyParser.new
|
48
|
+
ruby = "
|
49
|
+
def method_3(var_8)
|
50
|
+
\tif(var_8 == 'apple')
|
51
|
+
\t\treturn 'fruit'
|
52
|
+
\tend
|
53
|
+
\treturn 'vegetable'
|
54
|
+
end
|
55
|
+
"
|
56
|
+
sexp = parser.process(ruby)
|
57
|
+
sexp2cauldron = Sexp2Cauldron.new
|
58
|
+
unprocessed_runtime_method = sexp2cauldron.process(sexp)
|
59
|
+
reset_runtime_method = unprocessed_runtime_method.reset_ids!
|
60
|
+
reset_runtime_method.method_id.should == '0'
|
61
|
+
reset_runtime_method.variables.length.should == 1
|
62
|
+
|
63
|
+
ruby_reset = "
|
64
|
+
def method_0(var_0)
|
65
|
+
\tif(var_0 == 'apple')
|
66
|
+
\t\treturn 'fruit'
|
67
|
+
\tend
|
68
|
+
\treturn 'vegetable'
|
69
|
+
end
|
70
|
+
"
|
71
|
+
reset_runtime_method.basic_write.should == strip_whitespace(ruby_reset)+"\n"
|
72
|
+
end
|
30
73
|
end
|
31
|
-
|
32
74
|
end
|
33
75
|
|
34
76
|
end
|
@@ -20,6 +20,98 @@ module Cauldron
|
|
20
20
|
sexp2cauldron.process(sexp).write.should == Statement.new(Unknown.new(4),Equal.new,Literal.new(9)).write
|
21
21
|
end
|
22
22
|
|
23
|
+
it 'generates a basic if container' do
|
24
|
+
parser = RubyParser.new
|
25
|
+
ruby = %q!
|
26
|
+
if(var5 == 6)
|
27
|
+
end
|
28
|
+
!
|
29
|
+
sexp = parser.process(ruby)
|
30
|
+
sexp2cauldron = Sexp2Cauldron.new
|
31
|
+
sexp = parser.process(ruby)
|
32
|
+
sexp2cauldron.process(sexp).write.should == "if(var_5 == 6)\nend"
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'generates an empty runtime method' do
|
36
|
+
parser = RubyParser.new
|
37
|
+
ruby = %q!
|
38
|
+
def method_4
|
39
|
+
end
|
40
|
+
!
|
41
|
+
sexp = parser.process(ruby)
|
42
|
+
sexp2cauldron = Sexp2Cauldron.new
|
43
|
+
sexp2cauldron.process(sexp).basic_write.should == strip_whitespace(ruby)+"\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'generates a method with a simple statement' do
|
47
|
+
parser = RubyParser.new
|
48
|
+
ruby = "
|
49
|
+
def method_3
|
50
|
+
\tvar_8 = 9
|
51
|
+
end
|
52
|
+
"
|
53
|
+
sexp = parser.process(ruby)
|
54
|
+
sexp2cauldron = Sexp2Cauldron.new
|
55
|
+
a = sexp2cauldron.process(sexp)
|
56
|
+
a.basic_write.should == strip_whitespace(ruby)+"\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'generates a method with a simple if statement' do
|
60
|
+
parser = RubyParser.new
|
61
|
+
ruby = "
|
62
|
+
def method_6
|
63
|
+
\tif(var_8 == 9)
|
64
|
+
\t\treturn var_8
|
65
|
+
\tend
|
66
|
+
end
|
67
|
+
"
|
68
|
+
sexp2cauldron = Sexp2Cauldron.new
|
69
|
+
sexp = parser.process(ruby)
|
70
|
+
sexp2cauldron.process(sexp).basic_write.should == strip_whitespace(ruby)+"\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'generates a method with an if statement and two exit points' do
|
74
|
+
parser = RubyParser.new
|
75
|
+
ruby = "
|
76
|
+
def method_3(var_0)
|
77
|
+
\tif(var_0 == 'apple')
|
78
|
+
\t\treturn 'fruit'
|
79
|
+
\tend
|
80
|
+
\treturn 'vegetable'
|
81
|
+
end
|
82
|
+
"
|
83
|
+
sexp2cauldron = Sexp2Cauldron.new
|
84
|
+
sexp = parser.process(ruby)
|
85
|
+
sexp2cauldron.process(sexp).basic_write.should == strip_whitespace(ruby)+"\n"
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'generates the solution to demo 1' do
|
89
|
+
parser = RubyParser.new
|
90
|
+
ruby = "
|
91
|
+
def method_0(var_0)
|
92
|
+
\treturn var_0
|
93
|
+
end
|
94
|
+
"
|
95
|
+
sexp2cauldron = Sexp2Cauldron.new
|
96
|
+
sexp = parser.process(ruby)
|
97
|
+
sexp2cauldron.process(sexp).basic_write.should == strip_whitespace(ruby)+"\n"
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'can parse the solution to demo 2' do
|
101
|
+
parser = RubyParser.new
|
102
|
+
ruby = "
|
103
|
+
def method_0(var_0)
|
104
|
+
\tif(var_0 == 'fish')
|
105
|
+
\t\treturn 'animal'
|
106
|
+
\tend
|
107
|
+
\treturn 'vegtable'
|
108
|
+
end
|
109
|
+
"
|
110
|
+
sexp2cauldron = Sexp2Cauldron.new
|
111
|
+
sexp = parser.process(ruby)
|
112
|
+
sexp2cauldron.process(sexp).basic_write.should == strip_whitespace(ruby)+"\n"
|
113
|
+
end
|
114
|
+
|
23
115
|
end
|
24
116
|
end
|
25
117
|
|
@@ -2,4 +2,24 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Cauldron
|
4
4
|
|
5
|
+
describe 'TheoryAction' do
|
6
|
+
|
7
|
+
describe '#statements_with_variable' do
|
8
|
+
|
9
|
+
it 'should return two statements for the action "Statement.new(Return.new, var0.params[var2]),var0.statement_id"' do
|
10
|
+
link_one_action = TheoryAction.new(
|
11
|
+
TheoryStatement.new(StringToTheory.run('Statement.new(Return.new,var1.params[var3])')),
|
12
|
+
StringToTheory.run('var1.statement_id')
|
13
|
+
)
|
14
|
+
link_one_action.statements_with_variable(1).length.should == 3
|
15
|
+
res = link_one_action.statements_with_variable(1).collect {|x| x.write }
|
16
|
+
res.should include('var1.statement_id')
|
17
|
+
res.should include('var1.params')
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
5
25
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
StandardLogger.instance.level = Logger::FATAL
|
4
|
+
|
5
|
+
module Cauldron
|
6
|
+
|
7
|
+
describe TheoryConnector do
|
8
|
+
|
9
|
+
describe '#generate_chains' do
|
10
|
+
context 'when it has demo 1 theories' do
|
11
|
+
it 'will generate just one chain' do
|
12
|
+
theories = demo_one[:chain].collect {|x| x}
|
13
|
+
runtime_method = demo_one[:initial_method]
|
14
|
+
test_cases = demo_one[:test_cases]
|
15
|
+
|
16
|
+
connector = TheoryConnector.new(demo_one[:values])
|
17
|
+
connector.generate_chains(runtime_method,test_cases,theories).length.should == 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context "when it has demo two's theories" do
|
21
|
+
it 'will generate just one chain' do
|
22
|
+
theories = demo_two[:chain].collect {|x| x}
|
23
|
+
runtime_method = demo_two[:initial_method]
|
24
|
+
test_cases = demo_two[:test_cases]
|
25
|
+
|
26
|
+
connector = TheoryConnector.new(demo_two[:values])
|
27
|
+
connector.generate_chains(runtime_method,test_cases,theories).length.should == 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context "when it has both demo one and two's theories" do
|
31
|
+
it 'will generate just one chain' do
|
32
|
+
@theories = demo_one[:chain].collect {|x| x} + demo_two[:chain].collect {|x| x}
|
33
|
+
runtime_method = demo_one[:initial_method]
|
34
|
+
test_cases = demo_one[:test_cases]
|
35
|
+
|
36
|
+
connector = TheoryConnector.new(demo_one[:values])
|
37
|
+
connector.generate_chains(runtime_method,test_cases,@theories).length.should == 1
|
38
|
+
end
|
39
|
+
it 'will generate two chains when given demo two test cases' do
|
40
|
+
@theories = demo_one[:chain].collect {|x| x} + demo_two[:chain].collect {|x| x}
|
41
|
+
runtime_method = demo_two[:initial_method]
|
42
|
+
test_cases = demo_two[:test_cases]
|
43
|
+
|
44
|
+
connector = TheoryConnector.new(demo_one[:values])
|
45
|
+
connector.generate_chains(runtime_method,test_cases,@theories).length.should == 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Cauldron
|
4
|
+
|
5
|
+
describe 'Theory' do
|
6
|
+
|
7
|
+
describe '#map_to' do
|
8
|
+
it 'can map a simple theory to new values' do
|
9
|
+
link_one_action = TheoryAction.new(
|
10
|
+
TheoryStatement.new(StringToTheory.run('Statement.new(Return.new,var2.params[var3])')),
|
11
|
+
StringToTheory.run('var1.statement_id')
|
12
|
+
)
|
13
|
+
link_one_result = TheoryResult.new(StringToTheory.run("if(var1.all_pass?(var2))\nreturn true\nend"))
|
14
|
+
theory = Theory.new([],link_one_action,[link_one_result])
|
15
|
+
|
16
|
+
# Create the mapping for the theory
|
17
|
+
mapping = Mapping.new({
|
18
|
+
1=>IntrinsicRuntimeMethod.new,
|
19
|
+
2=>IntrinsicTestCases.new,
|
20
|
+
3=>IntrinsicLiteral.new(0)
|
21
|
+
})
|
22
|
+
# => TODO Why doesn't the tab character appear - or appear as a space
|
23
|
+
result = "
|
24
|
+
if:
|
25
|
+
|
26
|
+
action:
|
27
|
+
\truntime_method.add_statement_at(Statement.new(Return.new, test_cases.params[0]),runtime_method.statement_id)
|
28
|
+
result:
|
29
|
+
\tif(runtime_method.all_pass?(test_cases))
|
30
|
+
\t\treturn true
|
31
|
+
\tend
|
32
|
+
"
|
33
|
+
theory.map_to(mapping).write.strip.should == result.strip
|
34
|
+
|
35
|
+
end
|
36
|
+
it 'can map a theory with an if statement' do
|
37
|
+
|
38
|
+
link_one_action = TheoryAction.new(
|
39
|
+
TheoryStatement.new(StringToTheory.run(
|
40
|
+
'OpenStatement.new(If.new,Container.new(var1.params[var3],Equivalent.new,var2[var4][:params][var5]))')
|
41
|
+
),
|
42
|
+
StringToTheory.run('var1.statement_id')
|
43
|
+
)
|
44
|
+
theory = Theory.new([],link_one_action,[])
|
45
|
+
mapping = Mapping.new({
|
46
|
+
1=>IntrinsicRuntimeMethod.new,
|
47
|
+
2=>IntrinsicTestCases.new,
|
48
|
+
3=>IntrinsicLiteral.new(0),
|
49
|
+
4=>IntrinsicLiteral.new(0),
|
50
|
+
5=>IntrinsicLiteral.new(0)
|
51
|
+
})
|
52
|
+
puts theory.map_to(mapping).describe
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Cauldron
|
4
|
+
|
5
|
+
describe 'UnifiedChain' do
|
6
|
+
|
7
|
+
describe '#theory_variables' do
|
8
|
+
it 'gets the correct number of variables for demo 1' do
|
9
|
+
temp = Object.new
|
10
|
+
temp.extend(Cauldron::Demos)
|
11
|
+
demo = temp.demo_one
|
12
|
+
# => TODO Demos should probably only save unified chains
|
13
|
+
unified_chain = demo[:chain].unify_chain
|
14
|
+
unified_chain.theory_variables.length.should == 3
|
15
|
+
end
|
16
|
+
it 'gets the correct number of variables for demo 2' do
|
17
|
+
temp = Object.new
|
18
|
+
temp.extend(Cauldron::Demos)
|
19
|
+
demo = temp.demo_two
|
20
|
+
unified_chain = demo[:chain].unify_chain
|
21
|
+
unified_chain.theory_variables.length.should == 6
|
22
|
+
unified_chain.theory_variables.collect {|x| x.theory_variable_id}.uniq.length.should == 6
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#implementation_permuatations' do
|
27
|
+
context 'when using demo one chain' do
|
28
|
+
|
29
|
+
it 'creates just one implementation permutation' do
|
30
|
+
temp = Object.new
|
31
|
+
temp.extend(Cauldron::Demos)
|
32
|
+
demo = temp.demo_one
|
33
|
+
unified_chain = demo[:chain].unify_chain
|
34
|
+
test_cases = demo[:test_cases]
|
35
|
+
|
36
|
+
unified_chain.implementation_permuatations(
|
37
|
+
RuntimeMethod.new(MethodUsage.new(MethodParameter.new)),
|
38
|
+
test_cases,
|
39
|
+
Mapping.new
|
40
|
+
).length.should == 1
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'is a unified chain' do
|
44
|
+
temp = Object.new
|
45
|
+
temp.extend(Cauldron::Demos)
|
46
|
+
demo = temp.demo_one
|
47
|
+
unified_chain = demo[:chain].unify_chain
|
48
|
+
test_cases = demo[:test_cases]
|
49
|
+
|
50
|
+
unified_chain.implementation_permuatations(
|
51
|
+
RuntimeMethod.new(MethodUsage.new(MethodParameter.new)),
|
52
|
+
test_cases,
|
53
|
+
Mapping.new
|
54
|
+
)[0].should be_kind_of(ImplementedChain)
|
55
|
+
|
56
|
+
unified_chain.implementation_permuatations(
|
57
|
+
RuntimeMethod.new(MethodUsage.new(MethodParameter.new)),
|
58
|
+
test_cases,
|
59
|
+
Mapping.new
|
60
|
+
)[0].write.should_not include('var')
|
61
|
+
|
62
|
+
end
|
63
|
+
context 'when using demo two' do
|
64
|
+
it 'creates just one implementation permutation' do
|
65
|
+
temp = Object.new
|
66
|
+
temp.extend(Cauldron::Demos)
|
67
|
+
demo = temp.demo_two
|
68
|
+
unified_chain = demo[:chain].unify_chain
|
69
|
+
test_cases = demo[:test_cases]
|
70
|
+
|
71
|
+
unified_chain.implementation_permuatations(
|
72
|
+
RuntimeMethod.new(MethodUsage.new(MethodParameter.new)),
|
73
|
+
test_cases,
|
74
|
+
Mapping.new
|
75
|
+
).each {|chain| chain.write.should_not include('var')}
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#mapping_permutations' do
|
82
|
+
before(:each) {
|
83
|
+
temp = Object.new
|
84
|
+
temp.extend(Cauldron::Demos)
|
85
|
+
demo = temp.demo_one
|
86
|
+
@unified_chain = demo[:chain].unify_chain
|
87
|
+
}
|
88
|
+
it 'should create four permutations with one variable id and four values' do
|
89
|
+
values = [IntrinsicRuntimeMethod.new,IntrinsicTestCases.new,IntrinsicLiteral.new(0),IntrinsicLiteral.new(1)]
|
90
|
+
@unified_chain.mapping_permutations([0],values).length.should == 4
|
91
|
+
end
|
92
|
+
it 'should create 9 permutations with three variable id and three values' do
|
93
|
+
values = [IntrinsicRuntimeMethod.new,IntrinsicTestCases.new,IntrinsicLiteral.new(1)]
|
94
|
+
@unified_chain.mapping_permutations([0,1,2],values).length.should == 6
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|