cauldron 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/Gemfile +2 -0
  2. data/Rakefile +7 -0
  3. data/VERSION +1 -1
  4. data/features/cauldron_generates_runtime_method.feature +3 -2
  5. data/features/step_definitions/cauldron_steps.rb +0 -1
  6. data/features/support/method_1.example +3 -0
  7. data/features/support/method_2.example +6 -0
  8. data/lib/Chain.rb +140 -264
  9. data/lib/CodeHandler.rb +0 -4
  10. data/lib/ScopeDependencies.rb +1 -0
  11. data/lib/Theory.rb +12 -15
  12. data/lib/UnifiedChain.rb +265 -8
  13. data/lib/cauldron.rb +1 -1
  14. data/lib/cauldron/demos.rb +280 -0
  15. data/lib/cauldron/pot.rb +56 -30
  16. data/lib/cauldron/sexp2cauldron.rb +109 -126
  17. data/lib/cauldron/terminal.rb +5 -74
  18. data/lib/core/ClassMethodCallContainer.rb +14 -0
  19. data/lib/core/Container.rb +12 -2
  20. data/lib/core/InstanceCallContainer.rb +30 -4
  21. data/lib/core/TheoryGenerator.rb +2 -9
  22. data/lib/core/assignment/Equal.rb +1 -1
  23. data/lib/core/assignment/Equivalent.rb +1 -1
  24. data/lib/core/assignment/NotEqual.rb +1 -1
  25. data/lib/core/call_container/CallContainer.rb +7 -1
  26. data/lib/core/instance_call/Chop.rb +0 -9
  27. data/lib/core/instance_call/instance_calls.rb +8 -0
  28. data/lib/core/instance_call/length_equal.rb +1 -1
  29. data/lib/core/requirement/Requirement.rb +1 -0
  30. data/lib/core/runtime_class/class_names.rb +12 -12
  31. data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +0 -7
  32. data/lib/core/runtime_method/RuntimeMethod.rb +59 -45
  33. data/lib/core/statement/ActsAsStatement.rb +1 -1
  34. data/lib/core/statement/ArrayAccess.rb +28 -2
  35. data/lib/core/statement/OpenStatement.rb +7 -0
  36. data/lib/core/statement/Statement.rb +22 -18
  37. data/lib/core/statement/TheoryStatement.rb +8 -1
  38. data/lib/core/syntax/Addition.rb +3 -2
  39. data/lib/core/syntax/If.rb +8 -0
  40. data/lib/core/syntax/Return.rb +1 -1
  41. data/lib/core/variable/BaseVariable.rb +0 -2
  42. data/lib/core/variable/MethodParameter.rb +4 -31
  43. data/lib/core/variable/Unknown.rb +1 -5
  44. data/lib/implemented_chain.rb +3 -2
  45. data/lib/required.rb +0 -1
  46. data/lib/ruby_code/String.rb +0 -17
  47. data/lib/theories.rb +25 -1
  48. data/lib/theory/TheoryAction.rb +35 -5
  49. data/lib/theory/TheoryChainValidator.rb +10 -8
  50. data/lib/theory/TheoryComponent.rb +17 -0
  51. data/lib/theory/TheoryConnector.rb +76 -9
  52. data/lib/theory/TheoryDependent.rb +2 -2
  53. data/lib/theory/TheoryImplementation.rb +7 -7
  54. data/lib/util/ClassEvaluation.rb +2 -7
  55. data/lib/util/MethodValidation.rb +10 -6
  56. data/lib/util/Parser.rb +26 -20
  57. data/lib/util/StringToTheory.rb +27 -3
  58. data/spec/cauldron/chain_spec.rb +24 -0
  59. data/spec/cauldron/demos_spec.rb +30 -0
  60. data/spec/cauldron/pot_spec.rb +66 -0
  61. data/spec/cauldron/runtime_method_spec.rb +47 -5
  62. data/spec/cauldron/sexp_2_cauldron_spec.rb +92 -0
  63. data/spec/cauldron/terminal_spec.rb +1 -1
  64. data/spec/cauldron/theory_action_spec.rb +20 -0
  65. data/spec/cauldron/theory_connector_spec.rb +52 -0
  66. data/spec/cauldron/theory_spec.rb +59 -0
  67. data/spec/cauldron/unified_chain_spec.rb +102 -0
  68. data/spec/spec_helper.rb +10 -1
  69. data/tasks/theory_tasks.rake +274 -0
  70. data/test/fixtures/implementation_results/0/dump +0 -0
  71. data/test/fixtures/theories/0/dump +0 -0
  72. data/test/fixtures/theories/1/dump +0 -0
  73. data/test/fixtures/theories/10/dump +0 -0
  74. data/test/fixtures/theories/11/dump +0 -0
  75. data/test/fixtures/theories/12/dump +0 -0
  76. data/test/fixtures/theories/13/declaration.txt +1 -1
  77. data/test/fixtures/theories/13/desc +1 -1
  78. data/test/fixtures/theories/13/dump +0 -0
  79. data/test/fixtures/theories/14/dump +0 -0
  80. data/test/fixtures/theories/15/dump +0 -0
  81. data/test/fixtures/theories/16/dump +0 -0
  82. data/test/fixtures/theories/17/dump +0 -0
  83. data/test/fixtures/theories/18/dump +0 -0
  84. data/test/fixtures/theories/19/dump +0 -0
  85. data/test/fixtures/theories/2/dump +0 -0
  86. data/test/fixtures/theories/20/declaration.txt +1 -1
  87. data/test/fixtures/theories/20/desc +1 -1
  88. data/test/fixtures/theories/20/dump +0 -0
  89. data/test/fixtures/theories/3/dump +0 -0
  90. data/test/fixtures/theories/4/dump +0 -0
  91. data/test/fixtures/theories/5/dump +0 -0
  92. data/test/fixtures/theories/6/dump +0 -0
  93. data/test/fixtures/theories/7/dump +0 -0
  94. data/test/fixtures/theories/8/dump +0 -0
  95. data/test/fixtures/theories/9/dump +0 -0
  96. data/test/fixtures/theory_implementations/0/declaration.txt +1 -1
  97. data/test/fixtures/theory_implementations/0/dump +0 -0
  98. data/test/fixtures/theory_implementations/1/declaration.txt +11 -0
  99. data/test/fixtures/theory_implementations/1/dump +0 -0
  100. data/test/fixtures/theory_implementations/2/declaration.txt +11 -0
  101. data/test/fixtures/theory_implementations/2/dump +0 -0
  102. data/test/output/simple_method.txt +0 -1
  103. data/test/tc_contextual_variables.rb +2 -41
  104. data/test/tc_describe.rb +1 -2
  105. data/test/tc_method.rb +2 -5
  106. data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +5 -3
  107. data/test/unit/core/runtime_method/tc_runtime_method.rb +34 -56
  108. data/test/unit/core/statement/tc_block_statement.rb +2 -0
  109. data/test/unit/core/statement/tc_open_statement.rb +15 -6
  110. data/test/unit/core/statement/tc_statement.rb +4 -5
  111. data/test/unit/core/statement/tc_statement_dependencies.rb +1 -0
  112. data/test/unit/core/statement/tc_theory_statement.rb +2 -0
  113. data/test/unit/core/syntax/tc_if_container.rb +5 -5
  114. data/test/unit/core/tc_theory_generator_heavy.rb +1 -1
  115. data/test/unit/core/tracking/tc_history.rb +3 -1
  116. data/test/unit/core/variable/tc_method_parameter_variable.rb +2 -2
  117. data/test/unit/tc_chain_with_case_1.rb +1 -1
  118. data/test/unit/tc_method_usage.rb +1 -1
  119. data/test/unit/tc_theory.rb +8 -2
  120. data/test/unit/theory/tc_theory_action.rb +37 -5
  121. data/test/unit/theory/tc_theory_chain_validator.rb +3 -3
  122. data/test/unit/theory/tc_theory_connector.rb +2 -37
  123. data/test/unit/theory/tc_theory_dependent.rb +2 -0
  124. data/test/unit/theory/tc_theory_implementation.rb +5 -1
  125. data/test/unit/theory/tc_theory_result.rb +3 -2
  126. data/test/unit/util/tc_method_validation.rb +4 -1
  127. data/test/unit/util/tc_parser.rb +2 -0
  128. data/test/unit/util/tc_string_to_theory.rb +3 -2
  129. data/tmp/runtime_method_evaluation.rb +7 -4
  130. metadata +59 -13
  131. data/lib/core/syntax/IfContainer.rb +0 -100
@@ -1,5 +1,3 @@
1
- # TODO Look into matrix
2
- require "matrix"
3
1
  require "tsort"
4
2
 
5
3
  # A code handler continualy considers how to extend the complexity
@@ -13,8 +11,6 @@ require "tsort"
13
11
  # can. Note they are consider unique if the process to create them is
14
12
  # new, NOT whether or not there value is new.
15
13
  #
16
- # TODO Look up dynamic refactoring
17
- #
18
14
  class CodeHandler
19
15
 
20
16
  attr_reader :runtime_methods
@@ -1,6 +1,7 @@
1
1
  class ScopeDependencies < Array
2
2
 
3
3
  def initialize
4
+ raise StandardError.new('Will anyone miss me')
4
5
  super()
5
6
  end
6
7
 
@@ -22,6 +22,10 @@ class Theory
22
22
  return Marshal.load(Marshal.dump(self))
23
23
  end
24
24
 
25
+ def irrelevant?
26
+ dependents.empty? and results.empty? and action.nil?
27
+ end
28
+
25
29
  # Identify the dependents and actions that haven't changed between adding the action.
26
30
  #
27
31
  def identify_unchanged
@@ -51,20 +55,6 @@ class Theory
51
55
  return Theory.new(changing_dependents,action.copy,changing_results,example_runtime_method.copy)
52
56
  end
53
57
 
54
- # # NOTE: This method might not be useful.
55
- # # Returns a number of theories but with the number of dependents and results limited by the
56
- # # the numbers specified.
57
- # #
58
- # def variants(dependent_limit=4,results_limit=4)
59
- # results = []
60
- # @dependents.copy.permutation(dependent_limit).each do |d|
61
- # @results.copy.permutation(results_limit).each do |r|
62
- # results << Theory.new(d.copy,action.copy,r,example_runtime_method.copy)
63
- # end
64
- # end
65
- # return results
66
- # end
67
-
68
58
  # Loads a particular theory that has been saved to a file
69
59
  #
70
60
  def self.load_theory(theory_id)
@@ -140,13 +130,20 @@ class Theory
140
130
  #
141
131
  def map_to(mapping,values={})
142
132
  raise StandardError.new('Please use the maping datatype') unless mapping.kind_of?(Mapping)
133
+ # return TheoryImplementation.new(
134
+ # @dependents.collect {|y| y.map_to(mapping)},
135
+ # @action ? @action.map_to(mapping) : nil,
136
+ # @results.collect {|y| y.map_to(mapping)},
137
+ # mapping,
138
+ # values
139
+ # )
143
140
  return TheoryImplementation.new(
144
141
  @dependents.collect {|y| y.map_to(mapping)},
145
142
  @action ? @action.map_to(mapping) : nil,
146
143
  @results.collect {|y| y.map_to(mapping)},
147
144
  mapping,
148
145
  values
149
- )
146
+ )
150
147
  end
151
148
 
152
149
  # TODO Need to write tests for this that use the mapping
@@ -35,7 +35,261 @@ class UnifiedChain < Chain
35
35
  implemented_nodes = @nodes.inject([]) do |total,theory|
36
36
  total << theory.map_to(mapping)
37
37
  end
38
- return ImplementedChain.new(implemented_nodes)
38
+ return ImplementedChain.new(implemented_nodes,mapping)
39
+ end
40
+
41
+ def implementation_permuatations2(runtime_method,test_cases,mapping)
42
+
43
+ more_mapping = valid_mapping_permutations(runtime_method.copy,test_cases.copy)
44
+
45
+ return more_mapping.inject([]) { |total,mapping| total << self.copy.implement(mapping) }
46
+
47
+ end
48
+
49
+ def valid_mapping_permutations(runtime_method,test_cases)
50
+
51
+ # Get the initially available intrinsic values
52
+ intrinsic_values = [IntrinsicRuntimeMethod.new,IntrinsicTestCases.new]
53
+
54
+ total_variables = self.theory_variables.length
55
+
56
+ available_values = [IntrinsicRuntimeMethod.new,IntrinsicTestCases.new]
57
+
58
+ valid_mappings = [Mapping.new]
59
+
60
+ #itteration_limit = 6
61
+ itteration_limit = 8
62
+
63
+ @nodes.each_with_index do |node,index|
64
+
65
+ node.dependents.each do |dependent|
66
+ if index == 0
67
+ chain = partial_chain(0)
68
+ else
69
+ chain = partial_chain(index-1)
70
+ end
71
+ limit = 0
72
+ until has_all_variables_been_found?(dependent,valid_mappings) or limit > itteration_limit
73
+ valid_mappings = extend_mapping(valid_mappings,dependent,runtime_method.copy,test_cases.copy,chain,available_values)
74
+ limit += 1
75
+ end
76
+ end
77
+
78
+ unless node.action.nil?
79
+ if index == 0
80
+ chain = partial_chain(0)
81
+ else
82
+ chain = partial_chain(index-1)
83
+ end
84
+ limit = 0
85
+ until has_all_variables_been_found?(node.action,valid_mappings) or limit > itteration_limit
86
+ valid_mappings = extend_mapping(valid_mappings,node.action,runtime_method.copy,test_cases.copy,chain,available_values)
87
+ limit += 1
88
+ end
89
+ if limit > itteration_limit
90
+ raise StandardError.new('Unable to resolve action: '+node.action.write)
91
+ end
92
+ end
93
+
94
+ node.results.each do |result|
95
+ chain = partial_chain(index)
96
+ limit = 0
97
+ until has_all_variables_been_found?(result,valid_mappings) or limit > itteration_limit
98
+ valid_mappings = extend_mapping(valid_mappings,result,runtime_method.copy,test_cases.copy,chain,available_values)
99
+ limit += 1
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+
106
+ return valid_mappings.collect {|x| Mapping.new(x)}
107
+
108
+ end
109
+
110
+ def has_all_variables_been_found?(component,mappings)
111
+ component.theory_variables.each do |var|
112
+ mappings.each do |mapping|
113
+ return false unless mapping.has_key? var.theory_variable_id
114
+ end
115
+ end
116
+ return true
117
+ end
118
+
119
+ def extend_mapping(valid_mappings,component,runtime_method,test_cases,chain,available_values)
120
+
121
+ new_mappings = []
122
+ component.theory_variables.each do |var|
123
+ next if valid_mappings.first.has_key?(var.theory_variable_id)
124
+ valid_mappings.each do |mapping|
125
+
126
+ #next if mapping.has_key?(var.theory_variable_id)
127
+ implemented_chain = chain.implement(Mapping.new(mapping))
128
+ implemented_runtime_method = TheoryChainValidator.new.build_method_from_chain(
129
+ implemented_chain,runtime_method.copy,test_cases.copy
130
+ )
131
+
132
+ possible_values = available_values-mapping.values
133
+ begin
134
+ values = intrinsic_values_for_variable(
135
+ var.theory_variable_id,
136
+ component,
137
+ mapping,
138
+ implemented_runtime_method,
139
+ test_cases.copy,
140
+ possible_values
141
+ )
142
+ rescue NoMethodError => e
143
+ valid_mappings = valid_mappings-[mapping]
144
+ next
145
+ end
146
+ values = values.uniq
147
+ values.each do |value|
148
+ copied_mapping = mapping.copy
149
+ copied_mapping[var.theory_variable_id] = value
150
+ new_mappings << copied_mapping
151
+ end
152
+ end
153
+
154
+ end
155
+ # => QUICK Hack
156
+ new_mappings = identify_uniq_mappings(new_mappings)
157
+ longest_mapping = new_mappings.inject(0) do |highest,m|
158
+ if(m.length > highest)
159
+ highest = m.length
160
+ end
161
+ highest
162
+ end
163
+ res = new_mappings.select {|x| x.length == longest_mapping}
164
+ new_mappings = res
165
+
166
+ unless new_mappings.empty?
167
+ valid_mappings = new_mappings
168
+ end
169
+ return valid_mappings
170
+
171
+ end
172
+
173
+ def identify_uniq_mappings(mappings)
174
+ uniq_mappings = []
175
+ count = mappings.length
176
+ until mappings.empty?
177
+ mapping = mappings.shift
178
+ already_exists = mappings.any? do |x|
179
+ next false unless x.length == mapping.length
180
+ next false unless x.keys.sort == mapping.keys.sort
181
+ all_values_the_same = true
182
+ x.each do |key,value|
183
+ if mapping[key].class != value.class
184
+ all_values_the_same = false
185
+ end
186
+ if mapping[key].class == value.class
187
+ if mapping[key].kind_of?(IntrinsicLiteral)
188
+ if mapping[key].write != value.write
189
+ all_values_the_same = false
190
+ end
191
+ end
192
+ end
193
+ end
194
+ next false unless all_values_the_same
195
+ next true
196
+ end
197
+ unless already_exists
198
+ uniq_mappings << mapping
199
+ end
200
+ end
201
+ if uniq_mappings.length == 0 && count != 0
202
+ raise StandardError.new('uniq_mappings should not be 0')
203
+ end
204
+ return uniq_mappings
205
+ end
206
+
207
+ def intrinsic_values_for_variable(id,component,mapping,runtime_method,test_cases,intrinsic_values)
208
+
209
+ values = []
210
+ component.statements_with_variable(id).each do |statement|
211
+ reg = eval('/^var'+id.to_s+'\./')
212
+ if statement.write.match(reg)
213
+
214
+ intrinsic_values.each do |value|
215
+ temp_mapping = mapping.copy
216
+ temp_mapping[id] = value
217
+ # => TODO Not validating the component - e.g. if(var1.kind_of?(RuntimeMethod))
218
+ if valid_mapping?(runtime_method.copy,test_cases.copy,statement,temp_mapping)
219
+ values << value
220
+ end
221
+ end
222
+ next
223
+ end
224
+
225
+ # values for index
226
+ index_values = []
227
+ intrinsic_statement = statement.map_to(mapping)
228
+ if intrinsic_statement.select_all {|z| z.kind_of?(TheoryVariable)}.length > 0
229
+ if m = intrinsic_statement.write.match(/([\w\.]+)\[var(\d)+\]/)
230
+ method_call = $1
231
+ if m2 = method_call.match(/var(\d+)/)
232
+ next
233
+ end
234
+ literal = evaluate_statement(method_call,runtime_method.copy,test_cases.copy)
235
+ literal.length.times do |n|
236
+ index_values << IntrinsicLiteral.new(n)
237
+ end
238
+ end
239
+ end
240
+ values += index_values
241
+
242
+ #variable_values = []
243
+ #result.statements_with_variable(var.theory_variable_id).each do |statement|
244
+ #variable_values += values_for_variable_as_argument(var,statement,mapping,intrinsic_values,implemented_runtime_method.copy,test_cases.copy)
245
+ #end
246
+ #values += variable_values
247
+
248
+ #intrinsic_statement = statement.map_to(mapping)
249
+ variable_values = []
250
+ intrinsic_values.each do |value|
251
+ literal = intrinsic_statement.write.gsub(/var(\d)+/,value.write)
252
+ begin
253
+ eval literal
254
+ variable_values << value
255
+ rescue
256
+ next
257
+ end
258
+ end
259
+ #return results
260
+ values += variable_values
261
+
262
+
263
+ end
264
+ return values
265
+ end
266
+
267
+ def partial_chain(limit)
268
+ links = @nodes[1..limit].collect {|x| x.copy }
269
+ UnifiedChain.new(links)
270
+ end
271
+
272
+ def mapping_permutations(keys,values)
273
+ values.permutation(keys.length).to_a.inject([]) do |total,value_permutation|
274
+ total << Hash[*keys.zip(value_permutation).flatten]
275
+ end
276
+ end
277
+
278
+ def valid_mapping?(runtime_method,test_cases,statement,mapping)
279
+ intrinsic_statement = statement.map_to(mapping)
280
+ return false unless intrinsic_statement.select_all {|z| z.kind_of?(TheoryVariable)}.length == 0
281
+ valid_statement?(intrinsic_statement,runtime_method.copy,test_cases.copy)
282
+ end
283
+
284
+ def evaluate_statement(statement,runtime_method,test_cases)
285
+ eval statement
286
+ end
287
+
288
+ def valid_statement?(statement,runtime_method,test_cases)
289
+ eval statement.write
290
+ return true
291
+ rescue NoMethodError
292
+ return false
39
293
  end
40
294
 
41
295
  # Returns an array of implemented chains using the various value
@@ -48,6 +302,8 @@ class UnifiedChain < Chain
48
302
  #
49
303
  def implementation_permuatations(runtime_method,test_cases,mapping)
50
304
 
305
+ return implementation_permuatations2(runtime_method,test_cases,mapping)
306
+
51
307
  # Determine the number of variables without intrinsic values
52
308
  theory_variable_ids = theory_variables.collect {|x| x.theory_variable_id}
53
309
 
@@ -57,22 +313,24 @@ class UnifiedChain < Chain
57
313
  # Take the first theory and identify all the accessors
58
314
  # (need to work out what is the runtime method and what the test cases)
59
315
 
60
- #pp missing_intrinsic_values
61
- #puts @nodes.first.class.to_s
62
- #@nodes.each {|x| puts x.class}
63
316
  # TEMP: Why are these implemented theories
64
- @nodes.first.all_theory_variables
317
+ # @nodes.first.all_theory_variables
65
318
 
66
319
  # Create the theory generator
67
320
  generator = TheoryGenerator.new()
68
- accessors, temp_mapping = generator.generate_accessors_and_mapping(test_cases,runtime_method,1)
321
+
322
+ #accessors, temp_mapping = generator.generate_accessors_and_mapping(test_cases,runtime_method,1)
323
+ accessors, temp_mapping = generator.generate_accessors_and_mapping(test_cases,runtime_method,3)
324
+
69
325
  if temp_mapping.length > missing_intrinsic_values.length
70
326
 
71
327
  # Now to assign real values to the chain
72
328
 
73
329
  # Apply the values in the various permutaions
74
330
  # (this is very crude and means that odd calls )
75
- theory_variable_ids = @nodes.first.all_theory_variables.collect {|x| x.theory_variable_id }
331
+ #theory_variable_ids = @nodes.first.all_theory_variables.collect {|x| x.theory_variable_id }
332
+
333
+ theory_variable_ids = self.theory_variables.collect {|x| x.theory_variable_id }
76
334
 
77
335
  # Get the posible sets for values in an array so that non of the arrays contain all the same values
78
336
  res = temp_mapping.values.collect {|x| x}
@@ -81,7 +339,6 @@ class UnifiedChain < Chain
81
339
  intrinsic_res = res.collect {|x| x.to_intrinsic}
82
340
  value_permutaions = intrinsic_res.permutation(theory_variable_ids.length).to_a
83
341
  uniq_value_permutations = value_permutaions.collect {|x| x.to_set}.uniq
84
-
85
342
  possible_mappings = []
86
343
 
87
344
  theory_variable_id_permutations = theory_variable_ids.permutation(theory_variable_ids.length).to_a
@@ -1,6 +1,6 @@
1
-
2
1
  require 'required'
3
2
 
4
3
  require 'cauldron/sexp2cauldron'
5
4
  require 'cauldron/conversion'
5
+ require 'cauldron/demos'
6
6
  require 'cauldron/terminal'
@@ -0,0 +1,280 @@
1
+ module Cauldron
2
+
3
+ module Demos
4
+
5
+ def convert_to_cauldron_test_cases(cases)
6
+ cases.inject([]) do |total,x|
7
+ cauldron_case = CTestCase.new
8
+ cauldron_case[:params] = x[0]
9
+ cauldron_case[:output] = x[1]
10
+ total << cauldron_case
11
+ end
12
+ end
13
+
14
+ def demo(id)
15
+
16
+ if id == '1'
17
+ return demo_one
18
+ end
19
+ raise StandardError.new('Unable to find demo with id '+id)
20
+
21
+ end
22
+
23
+ def demo_one
24
+
25
+ @demo_1_test_cases = convert_to_cauldron_test_cases(
26
+ [
27
+ [['sparky'],'sparky'],
28
+ [['kel'],'kel']
29
+ ]
30
+ )
31
+
32
+ # Create demo #1 chain
33
+ # Create the head for the chain
34
+ head = Theory.new([],nil,[])
35
+
36
+ link_one_action = TheoryAction.new(
37
+ TheoryStatement.new(StringToTheory.run('Statement.new(Return.new,var1.params[var3])')),
38
+ StringToTheory.run('var1.statement_id')
39
+ )
40
+ # NOTE: I need to add one result so the theory can be flagged as complete - I might not need it
41
+ # to be complete -
42
+ link_one_result = TheoryResult.new(StringToTheory.run("if(var1.all_pass?(var2))\nreturn true\nend"))
43
+ link_one = Theory.new([],link_one_action,[link_one_result])
44
+ chain = Chain.new
45
+ chain = chain.extension_permutaions(head).first
46
+ chain = chain.extension_permutaions(
47
+ link_one,
48
+ {
49
+ 1=>IntrinsicRuntimeMethod.new,
50
+ 2=>IntrinsicTestCases.new,
51
+ 3=>IntrinsicLiteral.new(0)
52
+ }
53
+ ).first
54
+
55
+ # Now implement the chain
56
+ implemented_chain = chain.implement
57
+
58
+ # TODO It should generate the values too.(TheoryGenerator)
59
+ return {
60
+ :initial_method=>RuntimeMethod.new(MethodUsage.new(MethodParameter.new)),
61
+ :test_cases=>@demo_1_test_cases,
62
+ :chain=>chain,
63
+ :values=>{}
64
+ }
65
+
66
+ end
67
+
68
+ # => "def method_3(var_0)\n\tif(var_0 == 'fish')\n\t\treturn 'animal'\n\tend\n\treturn 'vegetable'\nend\n"
69
+ def demo_two
70
+ @demo_2_test_cases = convert_to_cauldron_test_cases(
71
+ [
72
+ [['fish'],'animal'],
73
+ [['carrot'],'vegtable'],
74
+ ]
75
+ )
76
+ head = Theory.new([],nil,[])
77
+
78
+ # Statementents
79
+ # => TODO Need a clear way to format theories
80
+ # => OpenStatement.new(If.new,Container.new(runtime_method.params[var1],Equivalent.new,test_cases[var2][:params][var3]))
81
+ # => Statement.new(Return.new,test_cases[var2][:result]) (added to the open statement)
82
+ # => Statement.new(Return.new,test_cases[var6][:result])
83
+
84
+ # => TODO Don't actually want to include these connection hacks
85
+
86
+ # => HEAD
87
+ head_result = TheoryResult.new(StringToTheory.run(
88
+ "if(var1.kind_of?(RuntimeMethod))\nreturn true\nend")
89
+ )
90
+ head_result_2 = TheoryResult.new(StringToTheory.run(
91
+ "if(var2.length == 2)\nreturn true\nend")
92
+ )
93
+ head = Theory.new([],nil,[head_result,head_result_2])
94
+
95
+ # => LINK #1
96
+ link_one_dependent = TheoryDependent.new(StringToTheory.run(
97
+ "if(var1.kind_of?(RuntimeMethod))\nreturn true\nend"
98
+ )
99
+ )
100
+ link_one_dependent_2 = TheoryDependent.new(StringToTheory.run(
101
+ "if(var2.length == 2)\nreturn true\nend")
102
+ )
103
+ link_one_action = TheoryAction.new(
104
+ TheoryStatement.new(StringToTheory.run(
105
+ 'OpenStatement.new(TheoryStatement.new(If.new,Container.new(var1.params[var3],Equivalent.new,var2[var4][:params][var5])))'
106
+ )),
107
+ StringToTheory.run('var1.statement_id')
108
+ )
109
+ link_one_result = TheoryResult.new(StringToTheory.run(
110
+ "if(var1.kind_of?(RuntimeMethod))\nreturn true\nend"
111
+ ))
112
+ link_one_result_2 = TheoryResult.new(StringToTheory.run(
113
+ "if(var2.length == 2)\nreturn true\nend"
114
+ ))
115
+ link_one_result_3 = TheoryResult.new(StringToTheory.run(
116
+ "if(var4.kind_of?(Fixnum))\nreturn true\nend"
117
+ ))
118
+ link_one = Theory.new([link_one_dependent,link_one_dependent_2],link_one_action,[link_one_result,link_one_result_2,link_one_result_3])
119
+
120
+ # => LINK #2
121
+ link_two_dependent = TheoryDependent.new(StringToTheory.run(
122
+ "if(var1.kind_of?(RuntimeMethod))\nreturn true\nend"
123
+ ))
124
+ link_two_dependent_2 = TheoryDependent.new(StringToTheory.run(
125
+ "if(var2.length == 2)\nreturn true\nend"
126
+ ))
127
+ link_two_dependent_3 = TheoryDependent.new(StringToTheory.run(
128
+ "if(var4.kind_of?(Fixnum))\nreturn true\nend"
129
+ ))
130
+ link_two_action = TheoryAction.new(
131
+ TheoryStatement.new(StringToTheory.run(
132
+ 'Statement.new(Return.new,var2[var4][:output])'
133
+ )),
134
+ StringToTheory.run('var1.first.statement_id')
135
+ )
136
+ # link_two_result = TheoryResult.new(StringToTheory.run(
137
+ # "if(var1.history(var2[var4][:params]) == var2[var4][:output])\nreturn true\nend"
138
+ # ))
139
+ link_two_result = TheoryResult.new(StringToTheory.run(
140
+ "if(var2[var4][:params].length == 1)\nreturn true\nend"
141
+ ))
142
+ # TODO Don't want to have to include this one
143
+ link_two_result_2 = TheoryResult.new(StringToTheory.run(
144
+ "if(var6.kind_of?(Fixnum))\nreturn true\nend"
145
+ ))
146
+ link_two_result_3 = TheoryResult.new(StringToTheory.run(
147
+ "if(var1.kind_of?(RuntimeMethod))\nreturn true\nend"
148
+ ))
149
+
150
+ link_two = Theory.new(
151
+ [link_two_dependent,link_two_dependent_2,link_two_dependent_3],
152
+ link_two_action,
153
+ [link_two_result,link_two_result_2,link_two_result_3]
154
+ )
155
+
156
+ # => LINK #3
157
+ # link_three_dependent = TheoryDependent.new(StringToTheory.run(
158
+ # "if(var1.history(var2[var4][:params]) == var2[var4][:output])\nreturn true\nend"
159
+ # ))
160
+ link_three_dependent = TheoryDependent.new(StringToTheory.run(
161
+ "if(var2[var4][:params].length == 1)\nreturn true\nend"
162
+ ))
163
+ link_three_dependent_2 = TheoryDependent.new(StringToTheory.run(
164
+ "if(var6.kind_of?(Fixnum))\nreturn true\nend"
165
+ ))
166
+ link_three_dependent_3 = TheoryDependent.new(StringToTheory.run(
167
+ "if(var1.kind_of?(RuntimeMethod))\nreturn true\nend"
168
+ ))
169
+ link_three_action = TheoryAction.new(
170
+ TheoryStatement.new(
171
+ StringToTheory.run(
172
+ 'Statement.new(Return.new,var2[var6][:output])'
173
+ )
174
+ ),
175
+ StringToTheory.run('var1.statement_id')
176
+ )
177
+ #link_three_result = TheoryResult.new(StringToTheory.run(
178
+ # "if(var1.history(var2[var6][:params]) == var2[var6][:output])\nreturn true\nend"
179
+ #))
180
+ link_three_result = TheoryResult.new(StringToTheory.run(
181
+ "if(var2[var4][:params].length == 1)\nreturn true\nend"
182
+ ))
183
+ link_three_result_2 = TheoryResult.new(StringToTheory.run(
184
+ "if(var2.length == 2)\nreturn true\nend"
185
+ ))
186
+ link_three_result_3 = TheoryResult.new(StringToTheory.run(
187
+ "if(var1.length == 2)\nreturn true\nend"
188
+ ))
189
+ link_three = Theory.new(
190
+ [link_three_dependent,link_three_dependent_2,link_three_dependent_3],
191
+ link_three_action,
192
+ [link_three_result,link_three_result_2,link_three_result_3]
193
+ )
194
+
195
+ # => LINK #4
196
+ #link_four_dependent = TheoryDependent.new(StringToTheory.run(
197
+ # "if(var1.history(var2[var6][:params]) == var2[var6][:output])\nreturn true\nend"
198
+ #))
199
+ link_four_dependent = TheoryDependent.new(StringToTheory.run(
200
+ "if(var1.kind_of?(RuntimeMethod))\nreturn true\nend"
201
+ ))
202
+ link_four_dependent_2 = TheoryDependent.new(StringToTheory.run(
203
+ "if(var2.length == 2)\nreturn true\nend"
204
+ ))
205
+ link_four_dependent_3 = TheoryDependent.new(StringToTheory.run(
206
+ "if(var1.length == 2)\nreturn true\nend"
207
+ ))
208
+ link_four_result = TheoryResult.new(StringToTheory.run(
209
+ "if(var1.all_pass?(var2))\nreturn true\nend"
210
+ ))
211
+ link_four = Theory.new(
212
+ [link_four_dependent,link_four_dependent_2,link_four_dependent_3],
213
+ nil,
214
+ [link_four_result]
215
+ )
216
+
217
+ chain = Chain.new
218
+ chains = chain.extension_permutaions(head)
219
+ chain = chains.first
220
+
221
+ head_id = chain.first.theory_id
222
+ last_id = chain.last.theory_id
223
+
224
+ values = {
225
+ 1=>IntrinsicRuntimeMethod.new,
226
+ 2=>IntrinsicTestCases.new,
227
+ 3=>IntrinsicLiteral.new(0),
228
+ 4=>IntrinsicLiteral.new(0),
229
+ 5=>IntrinsicLiteral.new(0),
230
+ 6=>IntrinsicLiteral.new(1)
231
+ }
232
+
233
+ chains = chain.extension_permutaions(
234
+ link_one,values
235
+ )
236
+ order = [head_id,link_one.theory_id,last_id]
237
+ chain = chains.detect do |c|
238
+ c.collect {|t| t.theory_id} == order
239
+ end
240
+
241
+ chains = chain.extension_permutaions(
242
+ link_two,values
243
+ )
244
+ order = [head_id,link_one.theory_id,link_two.theory_id,last_id]
245
+ chain = chains.detect do |c|
246
+ c.collect {|t| t.theory_id} == order
247
+ end
248
+
249
+ chains = chain.extension_permutaions(
250
+ link_three,values
251
+ )
252
+ order = [head_id,link_one.theory_id,link_two.theory_id,link_three.theory_id,last_id]
253
+ chain = chains.detect do |c|
254
+ c.collect {|t| t.theory_id} == order
255
+ end
256
+
257
+ chains = chain.extension_permutaions(
258
+ link_four,values
259
+ )
260
+ order = [head_id,link_one.theory_id,link_two.theory_id,link_three.theory_id,link_four.theory_id,last_id]
261
+ chain = chains.detect do |c|
262
+ c.collect {|t| t.theory_id} == order
263
+ end
264
+
265
+ unified_chain = chain.unify_chain
266
+
267
+ implemented_chain = chain.implement
268
+
269
+ return {
270
+ :initial_method=>RuntimeMethod.new(MethodUsage.new(MethodParameter.new)),
271
+ :test_cases=>@demo_2_test_cases,
272
+ :chain=>chain,
273
+ :values=>{}
274
+ }
275
+
276
+ end
277
+
278
+ end
279
+
280
+ end