cauldron 0.1.5 → 0.1.6

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 (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.rspec +1 -0
  4. data/Gemfile +16 -9
  5. data/Gemfile.lock +134 -64
  6. data/README.md +26 -0
  7. data/Rakefile +24 -99
  8. data/build_sandbox.rb +41 -0
  9. data/cucumber.yml +8 -0
  10. data/features/chop.feature +23 -0
  11. data/features/create_dynamic_statements.feature +14 -0
  12. data/features/generate_known_solution.feature +42 -0
  13. data/features/generate_new_statement.feature +20 -0
  14. data/features/step_definitions/cauldron_steps.rb +47 -0
  15. data/features/support/env.rb +1 -1
  16. data/features/use_existing_statements.feature +23 -0
  17. data/lib/cauldron.rb +41 -5
  18. data/lib/cauldron/actualized_composite.rb +35 -0
  19. data/lib/cauldron/array_collect_template/default.rb +95 -0
  20. data/lib/cauldron/array_collect_template/template.rb +57 -0
  21. data/lib/cauldron/builder.rb +60 -0
  22. data/lib/cauldron/caret.rb +50 -0
  23. data/lib/cauldron/dynamic_operator.rb +90 -0
  24. data/lib/cauldron/dynamic_operator_module.rb +140 -0
  25. data/lib/cauldron/example.rb +18 -0
  26. data/lib/cauldron/example_set.rb +36 -0
  27. data/lib/cauldron/histories.rb +53 -0
  28. data/lib/cauldron/history.rb +34 -0
  29. data/lib/cauldron/if_relationship.rb +4 -6
  30. data/lib/cauldron/number_addition_template/add_five.rb +71 -0
  31. data/lib/cauldron/number_addition_template/template.rb +56 -0
  32. data/lib/cauldron/operator.rb +62 -0
  33. data/lib/cauldron/operator/array_reverse_operator.rb +160 -0
  34. data/lib/cauldron/operator/concat_operator.rb +72 -0
  35. data/lib/cauldron/operator/hash_key_value_operator.rb +74 -0
  36. data/lib/cauldron/operator/numeric_operator.rb +115 -0
  37. data/lib/cauldron/operator/string_asterisk_operator.rb +131 -0
  38. data/lib/cauldron/operator/to_s_operator.rb +18 -0
  39. data/lib/cauldron/operator/var_collect_operator.rb +29 -0
  40. data/lib/cauldron/pot.rb +136 -26
  41. data/lib/cauldron/scope.rb +24 -0
  42. data/lib/cauldron/solution/composite.rb +236 -0
  43. data/lib/cauldron/solution/one.rb +49 -0
  44. data/lib/cauldron/statement_generator.rb +298 -0
  45. data/lib/cauldron/template_base.rb +14 -0
  46. data/lib/cauldron/tracer.rb +55 -0
  47. data/lib/cauldron/version.rb +1 -1
  48. data/lib/pry_tester.rb +76 -0
  49. data/ruby_to_sexp.rb +74 -0
  50. data/sandbox.rb +7 -0
  51. data/sexp_to_ruby.rb +150 -0
  52. data/spec/cauldron/actualized_composite_spec.rb +140 -0
  53. data/spec/cauldron/array_collect_template/default_spec.rb +41 -0
  54. data/spec/cauldron/builder_spec.rb +186 -0
  55. data/spec/cauldron/dynamic/add_number_template_spec.rb +30 -0
  56. data/spec/cauldron/dynamic_operator_spec.rb +416 -0
  57. data/spec/cauldron/example_set_spec.rb +49 -0
  58. data/spec/cauldron/example_spec.rb +33 -0
  59. data/spec/cauldron/histories_spec.rb +135 -0
  60. data/spec/cauldron/history_spec.rb +118 -0
  61. data/spec/cauldron/if_relationship_spec.rb +1 -1
  62. data/spec/cauldron/operator/array_reverse_operator_spec.rb +73 -0
  63. data/spec/cauldron/{concat_operator_spec.rb → operator/concat_operator_spec.rb} +30 -12
  64. data/spec/cauldron/operator/hash_key_value_operator_spec.rb +98 -0
  65. data/spec/cauldron/operator/numeric_operator_spec.rb +110 -0
  66. data/spec/cauldron/operator/string_asterisk_operator_spec.rb +196 -0
  67. data/spec/cauldron/operator/var_collect_operator_spec.rb +38 -0
  68. data/spec/cauldron/pot_spec.rb +176 -14
  69. data/spec/cauldron/solution/composite_spec.rb +421 -0
  70. data/spec/cauldron/solution/one_spec.rb +24 -0
  71. data/spec/cauldron/statement_generator_spec.rb +211 -0
  72. data/spec/cauldron/terminal_spec.rb +2 -2
  73. data/spec/spec_helper.rb +5 -1
  74. data/spec/support/code_matcher.rb +55 -0
  75. data/spec/support/include_instance_of_matcher.rb +9 -0
  76. data/spec/support/shared_examples_for_leaf_operators.rb +22 -0
  77. data/spec/support/shared_examples_for_operators.rb +23 -0
  78. data/syntax_spec.txt +2 -0
  79. metadata +104 -41
  80. data/README +0 -1
  81. data/README.rdoc +0 -19
  82. data/VERSION +0 -1
  83. data/features/cauldron_new_approach.feature +0 -46
  84. data/lib/cauldron/array_reverse_operator.rb +0 -39
  85. data/lib/cauldron/concat_operator.rb +0 -34
  86. data/lib/cauldron/numeric_operator.rb +0 -45
  87. data/lib/cauldron/relationship.rb +0 -5
  88. data/spec/cauldron/array_reverse_operator_spec.rb +0 -59
  89. data/spec/cauldron/numeric_operator_spec.rb +0 -70
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ module Cauldron
4
+
5
+ describe ExampleSet do
6
+
7
+ describe '#all?' do
8
+
9
+ context %q{contains example {:arguments => ['Mass'], :response => 'effect'}} do
10
+
11
+ context %q{with block {|x| x.response == 'effect'}} do
12
+
13
+ let(:example_set) do
14
+ Cauldron::ExampleSet.new(
15
+ [
16
+ Cauldron::Example.new({:arguments => ['Mass'], :response => 'effect'})
17
+ ]
18
+ )
19
+ end
20
+
21
+ it 'returns false' do
22
+ example_set.all? {|x| x.response == 'effect'}.should == true
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ describe '#scope' do
32
+
33
+ let(:example) { Cauldron::Example.new({:arguments => ['Mass'], :response => 'effect'}) }
34
+
35
+ let(:example_set) do
36
+ Cauldron::ExampleSet.new(
37
+ [ example ]
38
+ )
39
+ end
40
+
41
+ it 'creates a new variables array' do
42
+ example_set.scope.variables.object_id.should_not === example.params.object_id
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ module Cauldron
4
+
5
+ describe Example do
6
+
7
+ describe '#params' do
8
+
9
+ let(:example) do
10
+ Cauldron::Example.new(
11
+ { arguments: [["Pip", "Rowe"]], response: ["Pi", "Row"] }
12
+ )
13
+ end
14
+
15
+ it "returns ['var0']" do
16
+ example.params.should == ['var0']
17
+ end
18
+
19
+ context '#params has already been called' do
20
+
21
+ before(:each) { example.params }
22
+
23
+ it "returns ['var0']" do
24
+ example.params.should == ['var0']
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ module Cauldron
4
+
5
+ describe Histories do
6
+
7
+ describe '#insert_points' do
8
+
9
+ context 'has history with point [0]' do
10
+
11
+ let(:first_line_history) { Cauldron::History.new([{point: [0]}])}
12
+
13
+ let(:subject){
14
+ Cauldron::Histories.new([first_line_history])
15
+ }
16
+
17
+ it 'returns [ [0] ]' do
18
+ subject.insert_points.should == [[0]]
19
+ end
20
+
21
+ end
22
+
23
+ context 'has history 2 points [1,0]' do
24
+
25
+ let(:first_history) { Cauldron::History.new([{point: [1,0]}])}
26
+ let(:second_history) { Cauldron::History.new([{point: [1,0]}])}
27
+
28
+ let(:subject){
29
+ Cauldron::Histories.new([first_history,second_history])
30
+ }
31
+
32
+ it 'returns 1 insert point' do
33
+ expect(subject.insert_points.length).to eql(1)
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ describe '#contexts_at' do
41
+
42
+ # #<Cauldron::Histories:0x007f7f5c3f38c8
43
+ # @results=
44
+ # [#<Cauldron::History:0x007f7f5c3f3940
45
+ # @logs=
46
+ # [{:var2=>"Sparky", :var0=>["Sparky", "Kels"], :var1=>nil, :line=>0, :depth=>1, :total_line=>3, :point=>[0, 0]},
47
+ # {:var2=>"Kels", :var0=>["Sparky", "Kels"], :var1=>nil, :line=>0, :depth=>1, :total_line=>3, :point=>[0, 0]},
48
+ # {:var0=>["Sparky", "Kels"], :var1=>["Sparky", "Kels"], :line=>0, :depth=>0, :total_line=>4, :point=>[1]}]>]>
49
+
50
+ # point [0,0] => [{:var2=>"Sparky", :var0=>["Sparky", "Kels"], :var1=>nil}]
51
+ # point [0,0] => [{:var2=>"Kels", :var0=>["Sparky", "Kels"], :var1=>nil}]
52
+ # point [1] => [{:var2=>"Kels", :var0=>["Sparky", "Kels"], :var1=>nil}]
53
+
54
+ let(:histories) do
55
+ Cauldron::Histories.new(
56
+ [
57
+ Cauldron::History.new(
58
+ [
59
+ {:var2=>"Sparky", :var0=>["Sparky", "Kels"], :var1=>nil, :line=>0, :depth=>1, :total_line=>3, :point=>[0, 0]},
60
+ {:var2=>"Kels", :var0=>["Sparky", "Kels"], :var1=>nil, :line=>0, :depth=>1, :total_line=>3, :point=>[0, 0]},
61
+ {:var0=>["Sparky", "Kels"], :var1=>["Sparky", "Kels"], :line=>0, :depth=>0, :total_line=>4, :point=>[1]}
62
+ ]
63
+ )
64
+ ]
65
+ )
66
+ end
67
+
68
+ it 'returns 1 context' do
69
+ expect(histories.contexts_at([1]).length).to eql(1)
70
+ end
71
+
72
+ it 'returns 2 contexts' do
73
+ expect(histories.contexts_at([0, 0]).length).to eql(2)
74
+ end
75
+
76
+ end
77
+
78
+ describe '#variable_permutations' do
79
+
80
+ let(:histories) do
81
+ Cauldron::Histories.new(
82
+ [
83
+ Cauldron::History.new([{var0: 4}])
84
+ ]
85
+ )
86
+ end
87
+
88
+ it 'returns [{var0: 4}]' do
89
+ histories.variable_permutations(1).should == [
90
+ {var0: 4}
91
+ ]
92
+ end
93
+
94
+ context 'when var0 is ["Sparky", "Kel"]' do
95
+
96
+ let(:histories) do
97
+ Cauldron::Histories.new(
98
+ [
99
+ Cauldron::History.new([{:var0=>["Sparky", "Kel"], :line=>0, :depth=>0, :total_line=>0}])
100
+ ]
101
+ )
102
+ end
103
+
104
+ it 'returns ["Sparky", "Kel"]' do
105
+ histories.variable_permutations(1).should == [
106
+ {var0: ["Sparky", "Kel"]}
107
+ ]
108
+ end
109
+
110
+ end
111
+
112
+ context 'using two histories' do
113
+
114
+ let(:histories) do
115
+ Cauldron::Histories.new(
116
+ [
117
+ Cauldron::History.new([{:var0=>"Sparky", :line=>0, :depth=>0, :total_line=>0}]),
118
+ Cauldron::History.new([{:var0=>"Kel", :line=>0, :depth=>0, :total_line=>0}])
119
+ ]
120
+ )
121
+ end
122
+
123
+ it 'returns []' do
124
+ histories.variable_permutations(1).should == [
125
+ {var0: 'Sparky'}, {var0: 'Kel'}
126
+ ]
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+ end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+
3
+ module Cauldron
4
+
5
+ describe History do
6
+
7
+ describe '#insert_points' do
8
+
9
+ context %q{given the history is
10
+ History is:
11
+ [line: 0, depth:0, var0: ['Sparky','Kel'] ]
12
+ } do
13
+
14
+ let(:subject) { History.new([{line: 0, depth: 0, point: [0], var0: ['Sparky','Kel'] }]) }
15
+
16
+ it 'has 1 insert point' do
17
+ expect(subject.insert_points.length).to eql(1)
18
+ end
19
+
20
+ it 'has the insert point [0,0]' do
21
+ subject.insert_points.should include([0])
22
+ end
23
+
24
+ end
25
+
26
+ context %q{given the history is
27
+ History is:
28
+ [line: 1, depth:0, var0: 'Sparky', var1: 'Spark' ]
29
+ from:
30
+ var1 = var0.chop
31
+ } do
32
+
33
+ let(:subject) { History.new([{line: 1, depth: 0, point: [1], var0: 'Sparky', var1: 'Spark'}]) }
34
+
35
+ it 'has 1 insert point' do
36
+ expect(subject.insert_points.length).to eql(1)
37
+ end
38
+
39
+ it 'has the insert point [1,0]' do
40
+ subject.insert_points.should include([1])
41
+ end
42
+
43
+ end
44
+
45
+ context %q{
46
+ History is:
47
+ [line: 1, depth:1, total_line: 2, point: [0,1], var0: ['Sparky', 'Kels'], var1: 'Spark' ],
48
+ [line: 1, depth:1, total_line: 2, point: [0,1], var0: ['Sparky', 'Kels'], var1: 'Kel' ],
49
+ [line: 1, depth:0, total_line: 2, point: [1], var0: ['Sparky', 'Kels'], var1: 'Kel', var2: ['Spark', 'Kel'] ],
50
+ from:
51
+ var2 = var0.each do |var1|
52
+ var1.chop
53
+ end
54
+ } do
55
+
56
+ let(:subject) {
57
+ History.new([
58
+ {line: 1, depth:1, total_line: 2, point: [0,1], var0: ['Sparky', 'Kels'], var1: 'Spark'},
59
+ {line: 1, depth:1, total_line: 2, point: [0,1], var0: ['Sparky', 'Kels'], var1: 'Kel'},
60
+ {line: 1, depth:0, total_line: 2, point: [1], var0: ['Sparky', 'Kels'], var1: 'Kel', var2: ['Spark', 'Kel']}
61
+ ])
62
+ }
63
+
64
+ it 'has 2 insert point' do
65
+ expect(subject.insert_points.length).to eql(2)
66
+ end
67
+
68
+ it 'has the insert point [1]' do
69
+ subject.insert_points.should include([1])
70
+ end
71
+
72
+ it 'has the insert point [0,1]' do
73
+ subject.insert_points.should include([0,1])
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+
80
+ describe '#variables' do
81
+
82
+ context %q{
83
+ History is:
84
+ [line: 0, depth:0, var0: ['Sparky','Kel'] ]
85
+ } do
86
+
87
+ let(:history) { History.new([{line: 0, depth: 0, var0: ['Sparky','Kel'] }]) }
88
+
89
+ it 'returns "var0"' do
90
+ history.variables.should == [:var0]
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+
97
+ describe '#values' do
98
+
99
+ context %q{
100
+ History is:
101
+ [line: 0, depth:0, var0: ['Sparky','Kel'] ]
102
+ } do
103
+
104
+ let(:history) { History.new([{line: 0, depth: 0, var0: ['Sparky','Kel'] }]) }
105
+
106
+ it %q{returns "[ ['Sparky','Kel'] ]"} do
107
+ history.values(:var0).should == [
108
+ ['Sparky','Kel']
109
+ ]
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -13,7 +13,7 @@ module Cauldron
13
13
  {arguments: [7], response: 'seven'},
14
14
  {arguments: [8], response: 'eight'}
15
15
  ]
16
- IfRelationship.match?(problem).should be_true
16
+ expect(IfRelationship.match?(problem)).to eql(true)
17
17
  end
18
18
 
19
19
  end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ module Cauldron
4
+
5
+ describe 'ArrayReverseOperator' do
6
+
7
+ it_behaves_like "operator" do
8
+ let(:operator) { ArrayReverseOperator.new([0]) }
9
+ let(:initial_scope) { Cauldron::Scope.new(['var0']) }
10
+ let(:initial_operators) { [] }
11
+ end
12
+
13
+ describe '.viable?' do
14
+
15
+ context 'the arguments are not arrays' do
16
+
17
+ it 'is false' do
18
+ expect(ArrayReverseOperator.viable?([8], ['lions','tigers','bears'])).to eql(false)
19
+ end
20
+
21
+ end
22
+
23
+ context 'using more than 1 argument' do
24
+
25
+ it 'is false' do
26
+ expect(ArrayReverseOperator.viable?([['lions'],['tigers']], ['lions','tigers'])).to eql(false)
27
+ end
28
+
29
+ end
30
+
31
+ context 'response is not an array' do
32
+
33
+ it 'is false' do
34
+ expect(ArrayReverseOperator.viable?([['lions','tigers']], 'lions')).to eql(false)
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ describe '#successful?' do
42
+
43
+ context 'using array that needs reversed' do
44
+
45
+ it 'is true' do
46
+ operator = ArrayReverseOperator.new([0])
47
+ expect(
48
+ operator.successful?(
49
+ { arguments: [['lions','tigers']],response: ['tigers','lions']}
50
+ )
51
+ ).to eql(true)
52
+ end
53
+
54
+ end
55
+
56
+ context "using array that can't be reversed" do
57
+
58
+ it 'is false' do
59
+ operator = ArrayReverseOperator.new([0])
60
+ expect(
61
+ operator.successful?(
62
+ {arguments:[['lions','tigers']],response: ['lions','tigers']}
63
+ )
64
+ ).to eql(false)
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -2,14 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  module Cauldron
4
4
 
5
- describe 'ConcatOperator' do
5
+ describe ConcatOperator do
6
+
7
+ it_behaves_like "leaf_operator" do
8
+ let(:leaf_operator) { ConcatOperator.new([0]) }
9
+ end
10
+
11
+ it_behaves_like "operator" do
12
+ let(:operator) { ConcatOperator.new([0]) }
13
+ let(:initial_scope) { Cauldron::Scope.new(['var0']) }
14
+ let(:initial_operators) { [] }
15
+ end
6
16
 
7
17
  describe '.viable?' do
8
18
 
9
19
  context 'the arguments are not string' do
10
20
 
11
21
  it 'is false' do
12
- ConcatOperator.viable?([8], 'foobar').should be_false
22
+ expect(ConcatOperator.viable?([8], 'foobar')).to eql(false)
13
23
  end
14
24
 
15
25
  end
@@ -17,7 +27,7 @@ module Cauldron
17
27
  context 'the reponse is not a string' do
18
28
 
19
29
  it 'is false' do
20
- ConcatOperator.viable?(['foo'],8).should be_false
30
+ expect(ConcatOperator.viable?(['foo'],8)).to eql(false)
21
31
  end
22
32
 
23
33
  end
@@ -30,10 +40,13 @@ module Cauldron
30
40
 
31
41
  context 'response is "foobar"' do
32
42
 
43
+ let(:problems) do
44
+ Cauldron::ExampleSet.new(
45
+ [Cauldron::Example.new({ arguments: ['foo'], response: 'foobar'})]
46
+ )
47
+ end
48
+
33
49
  it 'return "[bar]"' do
34
- problems = [
35
- { arguments: ['foo'], response: 'foobar'}
36
- ]
37
50
  ConcatOperator.find_constants(problems).should == ['bar']
38
51
  end
39
52
 
@@ -41,10 +54,13 @@ module Cauldron
41
54
 
42
55
  context 'response is "barfoo"' do
43
56
 
57
+ let(:problems) do
58
+ Cauldron::ExampleSet.new(
59
+ [Cauldron::Example.new({ arguments: ['foo'], response: 'barfoo'})]
60
+ )
61
+ end
62
+
44
63
  it 'returns "[]"' do
45
- problems = [
46
- { arguments: ['foo'], response: 'barfoo'}
47
- ]
48
64
  ConcatOperator.find_constants(problems).should == []
49
65
  end
50
66
 
@@ -63,7 +79,7 @@ module Cauldron
63
79
  {arguments: ['foo'], response: 'foobar'},
64
80
  {arguments: ['goo'], response: 'goobar'}
65
81
  ]
66
- operator = ConcatOperator.new('bar')
82
+ operator = ConcatOperator.new([])
67
83
  problems.all? {|x| operator.successful?(x) }.should == true
68
84
  end
69
85
 
@@ -75,9 +91,11 @@ module Cauldron
75
91
 
76
92
  context 'using the constant "bar"' do
77
93
 
94
+ let(:scope) { Cauldron::Scope.new(['var0']) }
95
+
78
96
  it 'returns "var0.concat("bar")"' do
79
- operator = ConcatOperator.new('bar')
80
- operator.to_ruby.should == " var0.concat('bar')"+"\n"
97
+ operator = ConcatOperator.new([0])
98
+ operator.to_ruby(scope,[]).should == "var0.concat(\"bar\")"
81
99
  end
82
100
 
83
101
  end