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
@@ -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,5 +0,0 @@
1
- class Relationship
2
-
3
-
4
-
5
- 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