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.
- 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
@@ -1,39 +0,0 @@
|
|
1
|
-
class ArrayReverseOperator
|
2
|
-
|
3
|
-
#Arra
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
end
|
7
|
-
|
8
|
-
# Matching in
|
9
|
-
def successful?(input,output)
|
10
|
-
# NOTE - for the future - like the idea of not actually calling the method
|
11
|
-
# input.length.each do |i|
|
12
|
-
# does input[0] == output[input.length-0]
|
13
|
-
# does input[1] == output[input.length-1]
|
14
|
-
# does input[3] == output[input.length-3]
|
15
|
-
# end
|
16
|
-
|
17
|
-
# in this case x.reverse will work
|
18
|
-
return true if input.first.reverse == output
|
19
|
-
false
|
20
|
-
end
|
21
|
-
|
22
|
-
# 1. Only has one argument value
|
23
|
-
# 2. Argument is an array value
|
24
|
-
# 3. Response is an array
|
25
|
-
def self.viable?(arguments,output)
|
26
|
-
return false unless arguments.length == 1
|
27
|
-
return false unless arguments.all? { |x| x.kind_of?(Array) }
|
28
|
-
return false unless output.kind_of?(Array)
|
29
|
-
true
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.find_constants(problems)
|
33
|
-
[]
|
34
|
-
end
|
35
|
-
|
36
|
-
# def describe -
|
37
|
-
# should be able to describe the x.object_id moving to the different locations
|
38
|
-
|
39
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
class ConcatOperator
|
2
|
-
|
3
|
-
def initialize(constant)
|
4
|
-
@constant = constant
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.viable?(arguments, response)
|
8
|
-
return false unless arguments.all? { |x| x.kind_of?(String) }
|
9
|
-
return false unless response.kind_of?(String)
|
10
|
-
# TODO - Only accpets one argument
|
11
|
-
true
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.find_constants(problems)
|
15
|
-
problems.inject([]) do |total, x|
|
16
|
-
result = x[:response].gsub( Regexp.new('^'+x[:arguments].first),'')
|
17
|
-
total << result unless result == x[:response]
|
18
|
-
total
|
19
|
-
end.uniq
|
20
|
-
end
|
21
|
-
|
22
|
-
# Operator for "x.concat("bar")"
|
23
|
-
def successful?(problem)
|
24
|
-
if (problem[:arguments].first + @constant) == problem[:response]
|
25
|
-
return true
|
26
|
-
end
|
27
|
-
return false
|
28
|
-
end
|
29
|
-
|
30
|
-
def to_ruby
|
31
|
-
' var0.concat(\''+@constant.to_s+'\')'+"\n"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
class NumericOperator
|
2
|
-
|
3
|
-
# Maybe NumericOperation
|
4
|
-
|
5
|
-
def initialize(constant)
|
6
|
-
@constant = constant
|
7
|
-
end
|
8
|
-
|
9
|
-
# Is the problem suitable for a numeric operatio?
|
10
|
-
# e.g. can the .find_contants call be called without error
|
11
|
-
def self.viable?(arguments,output)
|
12
|
-
|
13
|
-
# 1. Only has one argument value
|
14
|
-
# 2. Argument is a numeric value
|
15
|
-
# 3. Response is numeric
|
16
|
-
|
17
|
-
# TODO Need to save these viablility tests in shared (easily comparable) state.
|
18
|
-
# e.g. so all viable operations can be found in one go.
|
19
|
-
|
20
|
-
return false unless arguments.all? { |x| x.kind_of?(Numeric) }
|
21
|
-
return false unless output.kind_of?(Numeric)
|
22
|
-
true
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_ruby
|
27
|
-
' var0 + '+@constant.to_s+"\n"
|
28
|
-
end
|
29
|
-
|
30
|
-
# Operator for "x + n" e.g. x + 1
|
31
|
-
def successful?(problem)
|
32
|
-
# Does the input match the answer
|
33
|
-
#problem.collect {|x| x[:response] - x[:arguments].first }.uniq.length == 1
|
34
|
-
if (problem[:arguments].first + @constant) == problem[:response]
|
35
|
-
return true
|
36
|
-
end
|
37
|
-
return false
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.find_constants(problems)
|
41
|
-
problems.collect {|x| x[:response] - x[:arguments].first }.uniq
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Cauldron
|
4
|
-
|
5
|
-
describe 'ArrayReverseOperator' do
|
6
|
-
|
7
|
-
describe '.viable?' do
|
8
|
-
|
9
|
-
context 'the arguments are not arrays' do
|
10
|
-
|
11
|
-
it 'is false' do
|
12
|
-
ArrayReverseOperator.viable?([8], ['lions','tigers','bears']).should be_false
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'using more than 1 argument' do
|
18
|
-
|
19
|
-
it 'is false' do
|
20
|
-
ArrayReverseOperator.viable?([['lions'],['tigers']], ['lions','tigers']).should be_false
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'response is not an array' do
|
26
|
-
|
27
|
-
it 'is false' do
|
28
|
-
ArrayReverseOperator.viable?([['lions','tigers']], 'lions').should be_false
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#successful?' do
|
36
|
-
|
37
|
-
context 'using array that needs reversed' do
|
38
|
-
|
39
|
-
it 'is true' do
|
40
|
-
operator = ArrayReverseOperator.new
|
41
|
-
operator.successful?([['lions','tigers']],['tigers','lions']).should be_true
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
context "using array that can't be reversed" do
|
47
|
-
|
48
|
-
it 'is false' do
|
49
|
-
operator = ArrayReverseOperator.new
|
50
|
-
operator.successful?([['lions','tigers']],['lions','tigers']).should be_false
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Cauldron
|
4
|
-
|
5
|
-
describe 'NumericOperator' do
|
6
|
-
|
7
|
-
describe '.viable?' do
|
8
|
-
|
9
|
-
context 'consistent difference between argument and response' do
|
10
|
-
|
11
|
-
it 'is true' do
|
12
|
-
problem = [
|
13
|
-
{arguments: [7], response: 8},
|
14
|
-
{arguments: [10], response: 11}
|
15
|
-
]
|
16
|
-
#NumericOperator.viable?(problem).should be_true
|
17
|
-
problem.all? {|x| NumericOperator.viable?(x[:arguments], x[:response]) }.should be_true
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'arguments are not numeric' do
|
23
|
-
|
24
|
-
it 'is false' do
|
25
|
-
problem = [
|
26
|
-
{arguments: ["ted"], response: 8},
|
27
|
-
{arguments: ["ben"], response: 11}
|
28
|
-
]
|
29
|
-
#NumericValueRelationship.match?(problem).should be_false
|
30
|
-
problem.all? {|x| NumericOperator.viable?(x[:arguments], x[:response]) }.should be_false
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'responses are not numeric' do
|
36
|
-
|
37
|
-
it 'is false' do
|
38
|
-
problem = [
|
39
|
-
{arguments: [7], response: 'ben'},
|
40
|
-
{arguments: [10], response: 'ted'}
|
41
|
-
]
|
42
|
-
#NumericValueRelationship.match?(problem).should be_false
|
43
|
-
problem.all? {|x| NumericOperator.viable?(x[:arguments], x[:response]) }.should be_false
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '#successful?' do
|
51
|
-
|
52
|
-
context 'no consistent difference between values' do
|
53
|
-
|
54
|
-
it 'is false' do
|
55
|
-
problem = [
|
56
|
-
{arguments: [7], response: 24},
|
57
|
-
{arguments: [10], response: 11}
|
58
|
-
]
|
59
|
-
operator = NumericOperator.new(17)
|
60
|
-
#NumericValueRelationship.match?(problem).should be_false
|
61
|
-
problem.all? {|x| operator.successful?(x) }.should be_false
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|