cauldron 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (398) hide show
  1. data/.document +5 -0
  2. data/Gemfile +13 -0
  3. data/LICENSE.txt +20 -0
  4. data/README +1 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/bin/cauldron +10 -0
  9. data/cauldron/.autotest +23 -0
  10. data/cauldron/History.txt +6 -0
  11. data/cauldron/Manifest.txt +8 -0
  12. data/cauldron/README.txt +57 -0
  13. data/cauldron/Rakefile +27 -0
  14. data/cauldron/bin/cauldron +3 -0
  15. data/cauldron/lib/cauldron.rb +3 -0
  16. data/cauldron/test/test_cauldron.rb +8 -0
  17. data/features/cauldron_example_cases.feature +13 -0
  18. data/features/cauldron_generates_runtime_method.feature +12 -0
  19. data/features/cauldron_start_terminal.feature +13 -0
  20. data/features/step_definitions/cauldron_steps.rb +16 -0
  21. data/features/step_definitions/terminal_steps.rb +34 -0
  22. data/features/support/env.rb +19 -0
  23. data/lib/Chain.rb +879 -0
  24. data/lib/ChainMapping.rb +172 -0
  25. data/lib/CodeHandler.rb +517 -0
  26. data/lib/Mapping.rb +26 -0
  27. data/lib/MappingValues.rb +24 -0
  28. data/lib/ScopeDependencies.rb +7 -0
  29. data/lib/Theory.rb +274 -0
  30. data/lib/UnifiedChain.rb +110 -0
  31. data/lib/cauldron.rb +6 -0
  32. data/lib/cauldron/conversion.rb +15 -0
  33. data/lib/cauldron/pot.rb +134 -0
  34. data/lib/cauldron/sexp2cauldron.rb +156 -0
  35. data/lib/cauldron/terminal.rb +120 -0
  36. data/lib/cauldron/theory_factory.rb +10 -0
  37. data/lib/core/ActsAsCode.rb +25 -0
  38. data/lib/core/BlockToken.rb +33 -0
  39. data/lib/core/CCall.rb +7 -0
  40. data/lib/core/CTestCase.rb +27 -0
  41. data/lib/core/ClassMethodCallContainer.rb +45 -0
  42. data/lib/core/Container.rb +85 -0
  43. data/lib/core/InstanceCallContainer.rb +272 -0
  44. data/lib/core/MethodUsage.rb +66 -0
  45. data/lib/core/PrintVariables.rb +25 -0
  46. data/lib/core/TheoryGenerator.rb +764 -0
  47. data/lib/core/Token.rb +7 -0
  48. data/lib/core/assignment/Assignment.rb +18 -0
  49. data/lib/core/assignment/Equal.rb +39 -0
  50. data/lib/core/assignment/Equivalent.rb +20 -0
  51. data/lib/core/assignment/NotEqual.rb +14 -0
  52. data/lib/core/call_container/CallContainer.rb +66 -0
  53. data/lib/core/class_method_call/New.rb +15 -0
  54. data/lib/core/class_method_call/RuntimeClassMethodCall.rb +31 -0
  55. data/lib/core/declaration/Declaration.rb +16 -0
  56. data/lib/core/declaration/LiteralDeclaration.rb +47 -0
  57. data/lib/core/declaration/VariableDeclaration.rb +59 -0
  58. data/lib/core/instance_call/ArrayEach.rb +23 -0
  59. data/lib/core/instance_call/ArrayLength.rb +15 -0
  60. data/lib/core/instance_call/Chop.rb +28 -0
  61. data/lib/core/instance_call/Copy.rb +22 -0
  62. data/lib/core/instance_call/DeclaredVariable.rb +18 -0
  63. data/lib/core/instance_call/InstanceCall.rb +77 -0
  64. data/lib/core/instance_call/Params.rb +15 -0
  65. data/lib/core/instance_call/Push.rb +20 -0
  66. data/lib/core/instance_call/StringLength.rb +32 -0
  67. data/lib/core/instance_call/Times.rb +20 -0
  68. data/lib/core/instance_call/instance_calls.rb +168 -0
  69. data/lib/core/instance_call/length_equal.rb +15 -0
  70. data/lib/core/kernal/EvalCall.rb +15 -0
  71. data/lib/core/kernal/LocalVariablesCall.rb +15 -0
  72. data/lib/core/literal/Literal.rb +111 -0
  73. data/lib/core/literal/Raw.rb +23 -0
  74. data/lib/core/literal/RuntimeMethodLiteral.rb +21 -0
  75. data/lib/core/literal/StatementLiteral.rb +28 -0
  76. data/lib/core/method_call/AvailableVariablesCall.rb +25 -0
  77. data/lib/core/method_call/ClassCall.rb +33 -0
  78. data/lib/core/method_call/DefCall.rb +72 -0
  79. data/lib/core/method_call/EvaluateClassCall.rb +29 -0
  80. data/lib/core/method_call/MethodNameCall.rb +27 -0
  81. data/lib/core/method_call/ToDeclarationCall.rb +15 -0
  82. data/lib/core/requirement/Requirement.rb +291 -0
  83. data/lib/core/runtime_class/ArrayClass.rb +19 -0
  84. data/lib/core/runtime_class/ClassCallClass.rb +23 -0
  85. data/lib/core/runtime_class/ClassEvaluationClass.rb +19 -0
  86. data/lib/core/runtime_class/ClassName.rb +18 -0
  87. data/lib/core/runtime_class/DefCallClass.rb +21 -0
  88. data/lib/core/runtime_class/EqualClass.rb +19 -0
  89. data/lib/core/runtime_class/FixnumClass.rb +15 -0
  90. data/lib/core/runtime_class/IfStatementClass.rb +12 -0
  91. data/lib/core/runtime_class/InstanceCallClass.rb +19 -0
  92. data/lib/core/runtime_class/InstanceCallContainerClass.rb +16 -0
  93. data/lib/core/runtime_class/InstanceClassCallClass.rb +19 -0
  94. data/lib/core/runtime_class/LiteralClass.rb +19 -0
  95. data/lib/core/runtime_class/MethodParameterClass.rb +27 -0
  96. data/lib/core/runtime_class/MethodUsageClass.rb +27 -0
  97. data/lib/core/runtime_class/RequirementClass.rb +19 -0
  98. data/lib/core/runtime_class/ReturnClass.rb +21 -0
  99. data/lib/core/runtime_class/RuntimeClass.rb +30 -0
  100. data/lib/core/runtime_class/RuntimeClassClass.rb +19 -0
  101. data/lib/core/runtime_class/RuntimeMethodClass.rb +34 -0
  102. data/lib/core/runtime_class/StatementClass.rb +53 -0
  103. data/lib/core/runtime_class/StringClass.rb +23 -0
  104. data/lib/core/runtime_class/StringLengthClass.rb +19 -0
  105. data/lib/core/runtime_class/StringVariableClass.rb +19 -0
  106. data/lib/core/runtime_class/ThisClass.rb +15 -0
  107. data/lib/core/runtime_class/UnknownClass.rb +23 -0
  108. data/lib/core/runtime_class/class_names.rb +95 -0
  109. data/lib/core/runtime_class/runtime_class.rb +123 -0
  110. data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +300 -0
  111. data/lib/core/runtime_method/ParametersContainer.rb +29 -0
  112. data/lib/core/runtime_method/RealisedRuntimeMethod.rb +94 -0
  113. data/lib/core/runtime_method/RuntimeMethod.rb +817 -0
  114. data/lib/core/runtime_method/WriteParameters.rb +35 -0
  115. data/lib/core/statement/ActsAsStatement.rb +116 -0
  116. data/lib/core/statement/ArrayAccess.rb +96 -0
  117. data/lib/core/statement/BlockStatement.rb +348 -0
  118. data/lib/core/statement/DeclarationStatement.rb +19 -0
  119. data/lib/core/statement/HackStatement.rb +25 -0
  120. data/lib/core/statement/HashAccess.rb +18 -0
  121. data/lib/core/statement/OpenStatement.rb +171 -0
  122. data/lib/core/statement/RealisedStatement.rb +5 -0
  123. data/lib/core/statement/SingleLineBlockStatement.rb +39 -0
  124. data/lib/core/statement/Statement.rb +1223 -0
  125. data/lib/core/statement/StatementDependencies.rb +271 -0
  126. data/lib/core/statement/StatementGroup.rb +157 -0
  127. data/lib/core/statement/StatementStructure2.rb +224 -0
  128. data/lib/core/statement/TheoryStatement.rb +60 -0
  129. data/lib/core/statement/TopologicalStatements.rb +34 -0
  130. data/lib/core/structure/DeclareNewInstanceStructure.rb +49 -0
  131. data/lib/core/structure/DeclareRuntimeMethodStructure.rb +34 -0
  132. data/lib/core/structure/DeclareVariableAsLiteralStructure.rb +31 -0
  133. data/lib/core/structure/DeclareVariableAsVariableStructure.rb +52 -0
  134. data/lib/core/structure/FixnumAdditionStructure.rb +56 -0
  135. data/lib/core/structure/InstanceCallContainerStructure.rb +50 -0
  136. data/lib/core/structure/InstanceCallStructure.rb +53 -0
  137. data/lib/core/structure/InstanceMethodCallStructure.rb +21 -0
  138. data/lib/core/structure/ReturnStructure.rb +20 -0
  139. data/lib/core/structure/StatementStructure.rb +11 -0
  140. data/lib/core/syntax/Addition.rb +25 -0
  141. data/lib/core/syntax/BlockContainer.rb +130 -0
  142. data/lib/core/syntax/Boolean.rb +15 -0
  143. data/lib/core/syntax/Code.rb +11 -0
  144. data/lib/core/syntax/Do.rb +20 -0
  145. data/lib/core/syntax/False.rb +12 -0
  146. data/lib/core/syntax/If.rb +28 -0
  147. data/lib/core/syntax/IfContainer.rb +100 -0
  148. data/lib/core/syntax/Nil.rb +15 -0
  149. data/lib/core/syntax/Return.rb +33 -0
  150. data/lib/core/syntax/Subtract.rb +19 -0
  151. data/lib/core/syntax/This.rb +40 -0
  152. data/lib/core/syntax/True.rb +20 -0
  153. data/lib/core/syntax/syntax.rb +24 -0
  154. data/lib/core/tracking/ActsAsTrackable.rb +65 -0
  155. data/lib/core/tracking/History.rb +167 -0
  156. data/lib/core/tracking/RuntimeTrackingMethod.rb +32 -0
  157. data/lib/core/tracking/Step.rb +52 -0
  158. data/lib/core/variable/ArrayVariable.rb +76 -0
  159. data/lib/core/variable/BaseVariable.rb +154 -0
  160. data/lib/core/variable/BlockVariable.rb +92 -0
  161. data/lib/core/variable/FixnumVariable.rb +36 -0
  162. data/lib/core/variable/HistoryVariable.rb +8 -0
  163. data/lib/core/variable/MethodParameter.rb +206 -0
  164. data/lib/core/variable/MethodUsageVariable.rb +60 -0
  165. data/lib/core/variable/NilVariable.rb +29 -0
  166. data/lib/core/variable/RuntimeMethodParameter.rb +67 -0
  167. data/lib/core/variable/StatementVariable.rb +72 -0
  168. data/lib/core/variable/StepVariable.rb +7 -0
  169. data/lib/core/variable/StringVariable.rb +46 -0
  170. data/lib/core/variable/TypeVariable.rb +72 -0
  171. data/lib/core/variable/Unknown.rb +116 -0
  172. data/lib/core/variable/UnknownVariable.rb +29 -0
  173. data/lib/core/variable/Variable.rb +70 -0
  174. data/lib/core/variable/VariableContainer.rb +28 -0
  175. data/lib/core/variable/VariableIncluded.rb +27 -0
  176. data/lib/core/variable/VariableReference.rb +85 -0
  177. data/lib/error/FailedToFindStatementContainerError.rb +7 -0
  178. data/lib/error/FailedToFindStatementError.rb +7 -0
  179. data/lib/error/FailedToFindVariableError.rb +7 -0
  180. data/lib/error/FailedToLiteraliseError.rb +7 -0
  181. data/lib/error/FailedVariableMatch.rb +7 -0
  182. data/lib/error/ImproperStatementUsageError.rb +7 -0
  183. data/lib/error/IncompatiableRequirementsError.rb +7 -0
  184. data/lib/error/InvalidStatementError.rb +7 -0
  185. data/lib/error/MethodSizeError.rb +7 -0
  186. data/lib/error/RuntimeSyntaxError.rb +7 -0
  187. data/lib/error/UnexpectedStatementTypeError.rb +7 -0
  188. data/lib/error/UnknownStatementType.rb +7 -0
  189. data/lib/error/UnliteralisableError.rb +7 -0
  190. data/lib/implemented_chain.rb +34 -0
  191. data/lib/intrinsic/IntrinsicLastRuntimeMethod.rb +20 -0
  192. data/lib/intrinsic/IntrinsicLiteral.rb +26 -0
  193. data/lib/intrinsic/IntrinsicObject.rb +22 -0
  194. data/lib/intrinsic/IntrinsicRuntimeMethod.rb +27 -0
  195. data/lib/intrinsic/IntrinsicTestCases.rb +17 -0
  196. data/lib/logger/StandardLogger.rb +62 -0
  197. data/lib/required.rb +236 -0
  198. data/lib/ruby_code/Array.rb +95 -0
  199. data/lib/ruby_code/Fixnum.rb +39 -0
  200. data/lib/ruby_code/Hash.rb +25 -0
  201. data/lib/ruby_code/NilClass.rb +19 -0
  202. data/lib/ruby_code/Object.rb +24 -0
  203. data/lib/ruby_code/String.rb +86 -0
  204. data/lib/ruby_code/Symbol.rb +7 -0
  205. data/lib/standard_library/Tasks.rb +12 -0
  206. data/lib/theories.rb +143 -0
  207. data/lib/theory/ActionImplementation.rb +17 -0
  208. data/lib/theory/TheoryAction.rb +70 -0
  209. data/lib/theory/TheoryChainValidator.rb +101 -0
  210. data/lib/theory/TheoryComponent.rb +42 -0
  211. data/lib/theory/TheoryConnector.rb +755 -0
  212. data/lib/theory/TheoryDependent.rb +135 -0
  213. data/lib/theory/TheoryImplementation.rb +74 -0
  214. data/lib/theory/TheoryResult.rb +131 -0
  215. data/lib/theory/TheoryVariable.rb +63 -0
  216. data/lib/theory/theory_collection.rb +62 -0
  217. data/lib/util/ClassEvaluation.rb +68 -0
  218. data/lib/util/CodeEvaluation.rb +35 -0
  219. data/lib/util/DeclarationStatementEvaluation.rb +31 -0
  220. data/lib/util/MethodEvaluation.rb +49 -0
  221. data/lib/util/MethodTester.rb +71 -0
  222. data/lib/util/MethodValidation.rb +145 -0
  223. data/lib/util/MethodWriter.rb +66 -0
  224. data/lib/util/Parser.rb +299 -0
  225. data/lib/util/StatementCheck.rb +42 -0
  226. data/lib/util/StringToTheory.rb +119 -0
  227. data/lib/util/System.rb +8 -0
  228. data/spec/cauldron/pot_spec.rb +6 -0
  229. data/spec/cauldron/runtime_method_spec.rb +36 -0
  230. data/spec/cauldron/sexp_2_cauldron_spec.rb +26 -0
  231. data/spec/cauldron/terminal_spec.rb +38 -0
  232. data/spec/cauldron/theory_action_spec.rb +5 -0
  233. data/spec/spec_helper.rb +4 -0
  234. data/test/fixtures/chains/1/declaration.txt +26 -0
  235. data/test/fixtures/chains/1/dump +0 -0
  236. data/test/fixtures/chains/2/declaration.txt +26 -0
  237. data/test/fixtures/chains/2/dump +0 -0
  238. data/test/fixtures/chains/3/declaration.txt +26 -0
  239. data/test/fixtures/chains/3/dump +0 -0
  240. data/test/fixtures/implementation_results/0/declaration.txt +3 -0
  241. data/test/fixtures/implementation_results/0/dump +0 -0
  242. data/test/fixtures/theories/0/declaration.txt +9 -0
  243. data/test/fixtures/theories/0/desc +10 -0
  244. data/test/fixtures/theories/0/dump +0 -0
  245. data/test/fixtures/theories/1/declaration.txt +15 -0
  246. data/test/fixtures/theories/1/desc +11 -0
  247. data/test/fixtures/theories/1/dump +0 -0
  248. data/test/fixtures/theories/10/declaration.txt +23 -0
  249. data/test/fixtures/theories/10/desc +17 -0
  250. data/test/fixtures/theories/10/dump +0 -0
  251. data/test/fixtures/theories/11/declaration.txt +20 -0
  252. data/test/fixtures/theories/11/desc +14 -0
  253. data/test/fixtures/theories/11/dump +0 -0
  254. data/test/fixtures/theories/12/declaration.txt +18 -0
  255. data/test/fixtures/theories/12/desc +12 -0
  256. data/test/fixtures/theories/12/dump +0 -0
  257. data/test/fixtures/theories/13/declaration.txt +24 -0
  258. data/test/fixtures/theories/13/desc +20 -0
  259. data/test/fixtures/theories/13/dump +0 -0
  260. data/test/fixtures/theories/14/declaration.txt +26 -0
  261. data/test/fixtures/theories/14/desc +20 -0
  262. data/test/fixtures/theories/14/dump +0 -0
  263. data/test/fixtures/theories/15/declaration.txt +20 -0
  264. data/test/fixtures/theories/15/desc +14 -0
  265. data/test/fixtures/theories/15/dump +0 -0
  266. data/test/fixtures/theories/16/declaration.txt +30 -0
  267. data/test/fixtures/theories/16/desc +14 -0
  268. data/test/fixtures/theories/16/dump +0 -0
  269. data/test/fixtures/theories/17/declaration.txt +25 -0
  270. data/test/fixtures/theories/17/desc +11 -0
  271. data/test/fixtures/theories/17/dump +0 -0
  272. data/test/fixtures/theories/18/declaration.txt +23 -0
  273. data/test/fixtures/theories/18/desc +11 -0
  274. data/test/fixtures/theories/18/dump +0 -0
  275. data/test/fixtures/theories/19/declaration.txt +23 -0
  276. data/test/fixtures/theories/19/desc +11 -0
  277. data/test/fixtures/theories/19/dump +0 -0
  278. data/test/fixtures/theories/2/declaration.txt +12 -0
  279. data/test/fixtures/theories/2/desc +10 -0
  280. data/test/fixtures/theories/2/dump +0 -0
  281. data/test/fixtures/theories/20/declaration.txt +23 -0
  282. data/test/fixtures/theories/20/desc +17 -0
  283. data/test/fixtures/theories/20/dump +0 -0
  284. data/test/fixtures/theories/3/declaration.txt +19 -0
  285. data/test/fixtures/theories/3/desc +11 -0
  286. data/test/fixtures/theories/3/dump +0 -0
  287. data/test/fixtures/theories/4/declaration.txt +11 -0
  288. data/test/fixtures/theories/4/desc +11 -0
  289. data/test/fixtures/theories/4/dump +0 -0
  290. data/test/fixtures/theories/5/declaration.txt +6 -0
  291. data/test/fixtures/theories/5/desc +9 -0
  292. data/test/fixtures/theories/5/dump +0 -0
  293. data/test/fixtures/theories/6/declaration.txt +13 -0
  294. data/test/fixtures/theories/6/desc +11 -0
  295. data/test/fixtures/theories/6/dump +0 -0
  296. data/test/fixtures/theories/7/declaration.txt +19 -0
  297. data/test/fixtures/theories/7/desc +11 -0
  298. data/test/fixtures/theories/7/dump +0 -0
  299. data/test/fixtures/theories/8/declaration.txt +21 -0
  300. data/test/fixtures/theories/8/desc +11 -0
  301. data/test/fixtures/theories/8/dump +0 -0
  302. data/test/fixtures/theories/9/declaration.txt +24 -0
  303. data/test/fixtures/theories/9/desc +20 -0
  304. data/test/fixtures/theories/9/dump +0 -0
  305. data/test/fixtures/theory_implementations/0/declaration.txt +11 -0
  306. data/test/fixtures/theory_implementations/0/desc.txt +9 -0
  307. data/test/fixtures/theory_implementations/0/dump +0 -0
  308. data/test/fixtures/theory_implementations/0/theory_id +1 -0
  309. data/test/fixtures/theory_implementations/1/desc.txt +9 -0
  310. data/test/fixtures/theory_implementations/1/dump +0 -0
  311. data/test/fixtures/theory_implementations/1/theory_id +1 -0
  312. data/test/fixtures/theory_implementations/2/desc.txt +9 -0
  313. data/test/fixtures/theory_implementations/2/dump +0 -0
  314. data/test/fixtures/theory_implementations/2/theory_id +1 -0
  315. data/test/output/simple_method.txt +6 -0
  316. data/test/output/test_method/first_possible_method.txt +6 -0
  317. data/test/output/test_simple_cases/simple_case_01.txt +8 -0
  318. data/test/output/test_simple_cases/simple_case_02.txt +7 -0
  319. data/test/output/test_simple_cases/simple_case_03.txt +8 -0
  320. data/test/output/test_simple_cases/simple_case_04.txt +8 -0
  321. data/test/output/test_simple_cases/simple_case_05.txt +8 -0
  322. data/test/output/test_simple_cases/simple_case_06.txt +9 -0
  323. data/test/output/test_simple_cases/simple_case_07.txt +9 -0
  324. data/test/output/test_simple_cases/simple_case_08.txt +9 -0
  325. data/test/tc_contextual_variables.rb +87 -0
  326. data/test/tc_describe.rb +47 -0
  327. data/test/tc_method.rb +133 -0
  328. data/test/tc_requirement.rb +30 -0
  329. data/test/tc_suite_complete.rb +26 -0
  330. data/test/tc_variable.rb +52 -0
  331. data/test/ts_complete.rb +84 -0
  332. data/test/ts_stable.rb +81 -0
  333. data/test/unit/core/declaration/tc_literal_declaration.rb +34 -0
  334. data/test/unit/core/method_call/tc_class_call.rb +20 -0
  335. data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +129 -0
  336. data/test/unit/core/runtime_method/tc_runtime_method.rb +616 -0
  337. data/test/unit/core/statement/tc_array_access.rb +63 -0
  338. data/test/unit/core/statement/tc_block_statement.rb +51 -0
  339. data/test/unit/core/statement/tc_hack_statement.rb +26 -0
  340. data/test/unit/core/statement/tc_open_statement.rb +70 -0
  341. data/test/unit/core/statement/tc_statement.rb +681 -0
  342. data/test/unit/core/statement/tc_statement_dependencies.rb +146 -0
  343. data/test/unit/core/statement/tc_statement_group.rb +35 -0
  344. data/test/unit/core/statement/tc_statement_replace_variable.rb +61 -0
  345. data/test/unit/core/statement/tc_theory_statement.rb +51 -0
  346. data/test/unit/core/structure/tc_declare_new_instance_structure.rb +41 -0
  347. data/test/unit/core/structure/tc_declare_variable_as_literal_structure.rb +41 -0
  348. data/test/unit/core/structure/tc_declare_variable_as_variable_structure.rb +66 -0
  349. data/test/unit/core/structure/tc_instance_call_container_structure.rb +41 -0
  350. data/test/unit/core/structure/tc_return_structure.rb +32 -0
  351. data/test/unit/core/syntax/tc_block_container.rb +32 -0
  352. data/test/unit/core/syntax/tc_if_container.rb +39 -0
  353. data/test/unit/core/tc_class_method_call.rb +34 -0
  354. data/test/unit/core/tc_container.rb +41 -0
  355. data/test/unit/core/tc_ctest_case.rb +25 -0
  356. data/test/unit/core/tc_instance_call_container.rb +93 -0
  357. data/test/unit/core/tc_literal.rb +30 -0
  358. data/test/unit/core/tc_theory_generator.rb +336 -0
  359. data/test/unit/core/tc_theory_generator_heavy.rb +42 -0
  360. data/test/unit/core/tracking/tc_history.rb +102 -0
  361. data/test/unit/core/tracking/tc_step.rb +65 -0
  362. data/test/unit/core/variable/tc_array_variable.rb +61 -0
  363. data/test/unit/core/variable/tc_block_variable.rb +17 -0
  364. data/test/unit/core/variable/tc_fixnum_variable.rb +54 -0
  365. data/test/unit/core/variable/tc_method_parameter_variable.rb +22 -0
  366. data/test/unit/core/variable/tc_runtime_method_variable.rb +32 -0
  367. data/test/unit/core/variable/tc_string_variable.rb +37 -0
  368. data/test/unit/core/variable/tc_unknown.rb +24 -0
  369. data/test/unit/core/variable/tc_variable_reference.rb +28 -0
  370. data/test/unit/ruby_code/tc_array.rb +64 -0
  371. data/test/unit/ruby_code/tc_fixnum.rb +18 -0
  372. data/test/unit/ruby_code/tc_hash.rb +41 -0
  373. data/test/unit/ruby_code/tc_string.rb +38 -0
  374. data/test/unit/tc_chain.rb +434 -0
  375. data/test/unit/tc_chain_mapping.rb +62 -0
  376. data/test/unit/tc_chain_with_case_1.rb +169 -0
  377. data/test/unit/tc_instance_call.rb +40 -0
  378. data/test/unit/tc_instance_call_structure.rb +35 -0
  379. data/test/unit/tc_method_usage.rb +35 -0
  380. data/test/unit/tc_pot.rb +124 -0
  381. data/test/unit/tc_runtime_tracking_method.rb +40 -0
  382. data/test/unit/tc_statement_structure_2.rb +43 -0
  383. data/test/unit/tc_theory.rb +533 -0
  384. data/test/unit/tc_variable_declaration.rb +32 -0
  385. data/test/unit/theory/tc_theory_action.rb +80 -0
  386. data/test/unit/theory/tc_theory_action_implementation.rb +23 -0
  387. data/test/unit/theory/tc_theory_chain_validator.rb +340 -0
  388. data/test/unit/theory/tc_theory_connector.rb +396 -0
  389. data/test/unit/theory/tc_theory_dependent.rb +151 -0
  390. data/test/unit/theory/tc_theory_implementation.rb +133 -0
  391. data/test/unit/theory/tc_theory_result.rb +111 -0
  392. data/test/unit/theory/tc_theory_variable.rb +45 -0
  393. data/test/unit/util/tc_method_validation.rb +98 -0
  394. data/test/unit/util/tc_parser.rb +108 -0
  395. data/test/unit/util/tc_string_to_theory.rb +299 -0
  396. data/test/unit/variable/tc_method_usage_variable.rb +25 -0
  397. data/tmp/runtime_method_evaluation.rb +10 -0
  398. metadata +522 -0
@@ -0,0 +1,616 @@
1
+ require 'required'
2
+ require 'test/unit'
3
+
4
+ class TestRuntimeMethod < Test::Unit::TestCase
5
+
6
+ def setup
7
+
8
+ # Create the method usage
9
+ @method_var_a = MethodParameter.new(Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,StringClass.new))
10
+ # Not used in the method
11
+ @method_var_b = MethodParameter.new(Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,StringClass.new))
12
+ @single_parameter_usage = MethodUsage.new(@method_var_a,@method_var_b)
13
+
14
+ # Create the simple method used in the tests
15
+ @simple_method = RuntimeMethod.new(@single_parameter_usage)
16
+
17
+ # Add a few simple statements to the method
18
+ @var_b = Unknown.new
19
+ @statement_a = Statement.new(@var_b,Equal.new,Literal.new(9))
20
+ @var_c = Unknown.new
21
+ @statement_b = Statement.new(@var_c,Equal.new,InstanceCallContainer.new(@method_var_a,Chop.new))
22
+ @var_d = Unknown.new
23
+ @statement_c = Statement.new(@var_d,Equal.new,InstanceCallContainer.new(@var_c,StringLength.new))
24
+ @var_e = Unknown.new
25
+ @var_f = Unknown.new
26
+ @statement_d = Statement.new(@var_e,Equal.new,@var_b,Addition.new,@var_d)
27
+ @simple_method.push(@statement_a)
28
+ @simple_method.push(@statement_b)
29
+ @simple_method.push(@statement_c)
30
+ @simple_method.push(@statement_d)
31
+ @simple_method.push(Statement.new(@var_f,Equal.new,InstanceCallContainer.new(@var_c,StringLength.new)))
32
+
33
+ # Create a runtime method with no parameters
34
+ @method_b = RuntimeMethod.new(MethodUsage.new)
35
+
36
+ # Create a method that accepts one string parameter and some string parameters to use
37
+ @method_c = RuntimeMethod.new(MethodUsage.new(MethodParameter.new(Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,StringClass.new))))
38
+ @var_g = 'Monkey'.to_var
39
+ @var_h = 'Island'.to_var
40
+ @var_i = '3'.to_var
41
+
42
+ # The methods all return string variables and have an increasing number of parameters
43
+ @method_usage_var_a = 'a string'.to_var
44
+ @method_respnse_a = 'Mass Effect'.to_var
45
+ @method_d = RuntimeMethod.new(MethodUsage.new(),@method_respnse_a)
46
+
47
+ # Create a method that excepts two string parameters
48
+ @method_usage_var_b = MethodParameter.new(Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,StringClass.new))
49
+ @method_usage_var_c = MethodParameter.new(Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,StringClass.new))
50
+ @method_e = RuntimeMethod.new(MethodUsage.new(@method_usage_var_b,@method_usage_var_c))
51
+
52
+ @method_usage_var_e = MethodParameter.new(Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,StringClass.new))
53
+ @method_usage_var_f = MethodParameter.new(Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,StringClass.new))
54
+ @method_respnse_b = 'Halo'.to_var
55
+ @method_f = RuntimeMethod.new(MethodUsage.new(@method_usage_var_e,@method_usage_var_f),@method_respnse_b)
56
+
57
+ # Create the methods to test the runtime methods history call
58
+ # Simple example
59
+ # def method_0
60
+ # var_0 = 'Civilisation'
61
+ # var_1 = var_0.length
62
+ # end
63
+ @method_history_a = RuntimeMethod.new(MethodUsage.new)
64
+ @var_j = Unknown.new
65
+ @method_history_a.push( Statement.new(@var_j,Equal.new,Literal.new('Civilisation')) )
66
+ @method_history_a.push( Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new(@var_j,StringLength.new)) )
67
+
68
+ # Create a runtime method that use nested statements
69
+ # var_0 = ''
70
+ # var_1 = 'x'
71
+ # 3.times do |var_2|
72
+ # var_0 = var_0 + var_1
73
+ # end
74
+ #
75
+ @build_xxx_method = RuntimeMethod.new(MethodUsage.new)
76
+ @blank_variable = Unknown.new
77
+ @x_variable = Unknown.new
78
+ @build_xxx_method.push( Statement.new(@blank_variable,Equal.new,Literal.new('')) )
79
+ @build_xxx_method.push( Statement.new(@x_variable,Equal.new,Literal.new('x')) )
80
+ nested_xxx_statement = BlockStatement.new( Statement.new(InstanceCallContainer.new(Literal.new(3),Times.new)) )
81
+ nested_xxx_statement.push(Statement.new(@blank_variable,Equal.new,@blank_variable,Addition.new,@x_variable) )
82
+ @build_xxx_method.push( nested_xxx_statement )
83
+
84
+ # Create a method that calls a different method
85
+ @called_method = RuntimeMethod.new(MethodUsage.new)
86
+ @called_method << Statement.new(Return.new,' Jelly'.to_literal)
87
+
88
+ # Create an empty runtime method
89
+ @empty_rumtime_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new,MethodParameter.new))
90
+
91
+ end
92
+
93
+ def teardown
94
+ System.reset
95
+ end
96
+
97
+ def test_copy
98
+
99
+ # Test some basic runtime method instances
100
+ assert_equal(@statement_d.write,@statement_d.copy.write)
101
+ assert_equal(@statement_d.write_with_uniq_id,@statement_d.copy.write_with_uniq_id)
102
+ assert_equal(@build_xxx_method.write,@build_xxx_method.copy.write)
103
+ assert_equal(@build_xxx_method.write_with_uniq_id,@build_xxx_method.copy.write_with_uniq_id)
104
+
105
+ # Check that dependies are found for modified statements
106
+ # var_a = 8
107
+ # var_b = []
108
+ # var_b.push(9)
109
+ # var_b.push(10)
110
+ statement_a_1 = Statement.new(Unknown.new,Equal.new,8.to_literal)
111
+ statement_a_2 = Statement.new(Unknown.new,Equal.new,[].to_literal)
112
+ statement_a_3 = Statement.new(InstanceCallContainer.new(statement_a_2.first.copy,Push.new,9.to_literal))
113
+ statement_a_4 = Statement.new(InstanceCallContainer.new(statement_a_3.first.subject.copy,Push.new,10.to_literal))
114
+ runtime_a = RuntimeMethod.new(MethodUsage.new)
115
+ runtime_a.push(statement_a_1)
116
+ runtime_a.push(statement_a_2)
117
+ runtime_a.push(statement_a_3)
118
+ runtime_a.push(statement_a_4)
119
+ assert_equal(runtime_a.write,runtime_a.copy.write)
120
+ assert_equal(runtime_a.write_with_uniq_id,runtime_a.copy.write_with_uniq_id)
121
+
122
+
123
+ end
124
+
125
+ def test_statement_count
126
+ assert_equal(5,@simple_method.statement_count)
127
+ assert_equal(0,@method_b.statement_count)
128
+ assert_equal(5,@build_xxx_method.statement_count)
129
+ end
130
+
131
+ def test_partial_method
132
+
133
+ # Retrieve a partial version of a runtime method and checks the length is correct
134
+ assert_nothing_raised(){@simple_method.partial_method(3)}
135
+ assert(@simple_method.partial_method(3).kind_of?(RuntimeMethod))
136
+ assert(4,@simple_method.partial_method(4).length)
137
+
138
+ # Attempt to retrieve a bigger method
139
+ assert_raises(MethodSizeError){@simple_method.partial_method(@simple_method.length+1)}
140
+
141
+ # Retrieve a partial for a method with nested statements
142
+ assert_nothing_raised(){@build_xxx_method.partial_method(3)}
143
+
144
+ end
145
+
146
+ # Tests the method that retrieves all the variables from a particular
147
+ # method. The variables aren't in the context of the method.
148
+ #
149
+ def test_available_variables
150
+
151
+ # Check the correct number of variables are returned
152
+ var_count = 7
153
+ assert_equal(var_count,@simple_method.available_variables(ParametersContainer.new(@method_var_a,@method_var_b)).length)
154
+
155
+ # Check its in the expected order
156
+ assert_equal(@var_f.variable_id,@simple_method.available_variables(ParametersContainer.new(@method_var_a,@method_var_b)).last.variable_id)
157
+
158
+ # Add a dupplicate statement to method and check there are the same number of variables
159
+ @simple_method.push(@statement_a)
160
+ assert_equal(var_count,@simple_method.available_variables(ParametersContainer.new(@method_var_a,@method_var_b)).length)
161
+
162
+ end
163
+
164
+ # Tests that the literal value of each variable in the method can
165
+ # be evaluated.
166
+ #
167
+ def test_literal_value_of_var
168
+
169
+ # Check that each of the variables has the correct evaluated value
170
+ local_var_a = 'test'.to_var
171
+ local_var_b = 'LividKel'.to_var
172
+ assert_equal(local_var_a.value,@simple_method.literal_value_of_var(@method_var_a.variable_id,ParametersContainer.new(local_var_a,local_var_b)))
173
+ assert_equal(9,@simple_method.literal_value_of_var(@var_b.variable_id,ParametersContainer.new(local_var_a,local_var_b)))
174
+ assert_equal(local_var_a.value.clone.chop,@simple_method.literal_value_of_var(@var_c.variable_id,ParametersContainer.new(local_var_a,local_var_b)))
175
+ assert_equal(local_var_a.value.clone.chop.length,@simple_method.literal_value_of_var(@var_d.variable_id,ParametersContainer.new(local_var_a,local_var_b)))
176
+ assert_equal(12,@simple_method.literal_value_of_var(@var_e.variable_id,ParametersContainer.new(local_var_a,local_var_b)))
177
+
178
+ # Check that an exception is raised for not existant variables
179
+ assert_raises(FailedToFindVariableError){@simple_method.literal_value_of_var(Variable.variable_id+1,ParametersContainer.new(local_var_a,local_var_b))}
180
+
181
+ end
182
+
183
+ # Tests the RuntimeMethods abilitity to identify what comninations
184
+ # of variables can be used to call this method.
185
+ #
186
+ def test_callable_combinations
187
+
188
+ # Assert that a method with no parameters only has one call
189
+ assert_equal(1,@method_b.callable_combinations([]).length)
190
+ assert(@method_b.callable_combinations([]).last.kind_of?(DefCall))
191
+
192
+ # Check the number of methods calls available when only using variables
193
+ assert_equal(3,@method_c.callable_combinations([@var_g,@var_h,@var_i]).length)
194
+ assert(@method_c.callable_combinations([@var_g,@var_h,@var_i]).last.kind_of?(DefCall))
195
+
196
+ # Check a combination of method calls and runtime methods
197
+ assert_equal(3,@method_c.callable_combinations([@var_g,@var_h,@var_i]).length)
198
+
199
+ # Check using a method that allows muliple parameters
200
+ assert_equal(9,@method_e.callable_combinations([@var_g,@var_h,@var_i]).length)
201
+
202
+ end
203
+
204
+ # Tests the method that converts any runtime method instances to def_calls
205
+ # using the other variables available to it.
206
+ #
207
+ def test_convert_methods_to_def_calls
208
+
209
+ # Check that when there are no runtime methdods just the supplied variables are returned
210
+ assert_equal(2,@method_c.send(:convert_methods_to_def_calls,[@var_g,@var_h]).length)
211
+
212
+ # Check that a single runtime method is converted to a def_call
213
+ assert(@method_c.send(:convert_methods_to_def_calls,[@method_d]).last.kind_of?(DefCall))
214
+
215
+ # Check that method_f (excepts two parameters) gets changed into 4 different def_calls
216
+ # 2 = both variables
217
+ # 4 = @method_f using both variables in different combinations
218
+ assert_equal(6,@method_c.send(:convert_methods_to_def_calls,[@var_g,@var_h,@method_f]).length)
219
+
220
+ end
221
+
222
+ # TODO Need to test with methods that require parameters (var_a) etc
223
+ def test_history
224
+ assert_equal(2,@method_history_a.history(ParametersContainer.new)[2]['variables'].length)
225
+ assert_equal("'Civilisation'",@method_history_a.history(ParametersContainer.new)[1]['variables'].first['value'].write)
226
+ assert_equal("12",@method_history_a.history(ParametersContainer.new)[2]['variables'].first['value'].write)
227
+ assert_equal("'Civilisation'",@method_history_a.history(ParametersContainer.new)[2]['variables'].last['value'].write)
228
+
229
+ # Check that history retains the correct variable ids
230
+ manny = 'Manny'.to_var
231
+ string_runtime_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new('Manny'.to_requirement)),nil)
232
+
233
+ # Add a statement to the runtime method
234
+ manny_length_var = Unknown.new
235
+
236
+ a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny,StringLength.new))
237
+ string_runtime_method.push(a_equals_manny_length)
238
+
239
+ # Check that the unknown variable "manny_length_var" retains the correct id
240
+ assert_nothing_raised() {string_runtime_method.find_variable(manny_length_var.variable_id)}
241
+
242
+ # Check that history captures all the expected values.
243
+ @method_history_a.history(ParametersContainer.new)[1]['variables'].each do |x|
244
+ assert_not_nil(x['id'])
245
+ assert_not_nil(x['uniq_id'])
246
+ end
247
+
248
+ end
249
+
250
+ # def method_0(var1)
251
+ # if(var1=='something')
252
+ # return 'exists'
253
+ # end
254
+ # return 'does not exist'
255
+ # end
256
+ #
257
+ def test_history_case_1
258
+
259
+ # Create the runtime that's history will be checked
260
+ param1 = MethodParameter.new
261
+ rm = RuntimeMethod.new(MethodUsage.new(param1))
262
+ statement1 = Parser.run("if(#{param1.write}=='something')\nend")
263
+ statement1 << Parser.run("return 'exists'")
264
+ rm << statement1
265
+ rm << Parser.run("return 'does not exists'")
266
+
267
+ assert_nothing_raised(){rm.history2(['akfjlkasd'])}
268
+ assert_equal(2,rm.history2(['akfjlkasd']).length)
269
+ assert_equal(2,rm.history2(['something']).length)
270
+ # TODO Should check what I think statement_id values are are correct
271
+
272
+ end
273
+
274
+ def test_trackify
275
+
276
+ # Create a simple method to be trackified
277
+ manny = MethodParameter.new(Requirement.new(This.new,Equivalent.new,'Manny'.to_literal))
278
+ string_runtime_method = RuntimeMethod.new(MethodUsage.new(manny),nil)
279
+
280
+ # Add a statement to the runtime method
281
+ manny_length_var = Unknown.new
282
+ a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny,StringLength.new))
283
+ string_runtime_method.push(a_equals_manny_length)
284
+
285
+ # Save the original written method
286
+ original_written = string_runtime_method.write
287
+
288
+ # Create the method that changes are logged to
289
+ instance_tracking_variable = ArrayVariable.new
290
+ instance_tracking_variable.instance_variable = true
291
+ tracking_method = RuntimeTrackingMethod.new(instance_tracking_variable)
292
+
293
+ # Trackify it and check nothing is raised
294
+ assert_nothing_raised(){string_runtime_method.trackify(ParametersContainer.new('Manny'.to_var),tracking_method)}
295
+
296
+ # Check that the method is unchanged after trackify
297
+ assert_equal(original_written,string_runtime_method.write)
298
+
299
+ end
300
+
301
+ def test_realise_with_an_empty_runtime_method
302
+
303
+ # Check that parameters have the same variable id
304
+ assert_not_nil(@empty_rumtime_method.usage[0].variable_id)
305
+ assert_not_nil(@empty_rumtime_method.realise2(['Mia','Elle']).params[0].variable_id)
306
+ assert_equal(
307
+ @empty_rumtime_method.usage[0].variable_id,
308
+ @empty_rumtime_method.realise2(['Mia','Elle']).params[0].variable_id
309
+ )
310
+
311
+ end
312
+
313
+ # Checks that a relised method only contrains literal values
314
+ # and type variables. Each of the type variables should contain
315
+ # there own literal value.
316
+ #
317
+ # TODO Test this nested statements and with variable overwritting.
318
+ #
319
+ # TODO When I start to use variable overwriting I need to come up with
320
+ # a way of identifying equivalence.
321
+ #
322
+ # e.g.
323
+ # var_a = 'test'
324
+ # var_b = var_a.length
325
+ #
326
+ # and
327
+ #
328
+ # var_a = 'test'
329
+ # var_a = var_a.length
330
+ #
331
+ # In this situation var_a is the same as var_b. Asides from removing the
332
+ # availablility of 'var_a'test'.
333
+ #
334
+ # Actually it really boils down to creating new variables. So as long as
335
+ # var_a isn't used the overwrite doesn't matter. I do need keep track of
336
+ # variations of a variable e.g. var_a(0) var_a(1). The variations are
337
+ # essential variables in their own right.
338
+ #
339
+ def test_realise
340
+
341
+ # Create a simple runtime method and check that the paramaters are valid
342
+ var_a = MethodParameter.new('Grim'.to_requirement)
343
+ var_b = MethodParameter.new('fandango'.to_requirement)
344
+ var_g = MethodParameter.new(
345
+ Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,ArrayClass.new)
346
+ )
347
+ simple_method = RuntimeMethod.new(MethodUsage.new(var_a,var_b,var_g))
348
+
349
+ # Check that realise returns an identical runtime method
350
+ var_a_value = StringVariable.new('Grim')
351
+ var_b_value = 'fandango'.to_var
352
+ var_g_value = 'Threepwood'.to_var
353
+ assert_nothing_raised(){
354
+ simple_method.realise2(['Grim','fandango','Threepwood'])
355
+ }
356
+ realised_instance_1 = simple_method.realise2(['Grim','fandango','Threepwood'])
357
+ assert_equal(
358
+ "\n#\n#\t@param\t[StringVariable] 'Grim'\n#\t@param\t[StringVariable] 'fandango'\n" \
359
+ "#\t@param\t[StringVariable] 'Threepwood'\n#\n#\n" \
360
+ "def method_0(var_#{simple_method.usage[0].variable_id}, var_#{simple_method.usage[1].variable_id}, var_#{simple_method.usage[2].variable_id})\n\nend\n",
361
+ realised_instance_1.write
362
+ )
363
+
364
+ # Check that all the variables are type variables and have a literal value
365
+ realised_instance_1.available_variables(ParametersContainer.new(var_a_value,var_b_value,var_g_value)).each do |x|
366
+ assert(x.kind_of?(TypeVariable))
367
+ end
368
+ assert(realised_instance_1.available_variables(ParametersContainer.new(var_a_value,var_b_value,var_g_value)).any? {|x| x.value == 'Grim' })
369
+ assert(realised_instance_1.available_variables(ParametersContainer.new(var_a_value,var_b_value,var_g_value)).any? {|x| x.value == 'fandango' })
370
+ assert_not_equal(true,realised_instance_1.available_variables(ParametersContainer.new(var_a_value,var_b_value,var_g_value)).any? {|x| x.value == 'WARREN' })
371
+
372
+ # Check that invalid paramters and undeclared parameters are caught
373
+ temp_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new(Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,StringClass.new))))
374
+ assert_raises(StandardError) {temp_method.realise2([])}
375
+
376
+ # Now let's add a few statements to the method
377
+ # var_c = var_a.length
378
+ var_c = Unknown.new
379
+ simple_method.push(Statement.new(var_c,Equal.new,InstanceCallContainer.new(var_a,StringLength.new)))
380
+ realised_instance_2 = simple_method.realise2(['Grim','fandango','Threepwood'])
381
+ assert_equal(
382
+ "\n#\n#\t@param\t[StringVariable] 'Grim'\n#\t@param\t[StringVariable] 'fandango'\n#\t@param\t[StringVariable] 'Threepwood'\n#\n#\n"\
383
+ "def method_0(var_#{simple_method.usage[0].variable_id}, var_#{simple_method.usage[1].variable_id}, var_#{simple_method.usage[2].variable_id})"\
384
+ "\n\tvar_58 = var_33.length\nend\n",
385
+ realised_instance_2.write
386
+ )
387
+
388
+ # Now lets have a chop instance call as well
389
+ # var_d = var_a.chop
390
+ simple_method.push(Statement.new(Unknown.new,Equal.new,InstanceCallContainer.new(var_a,Chop.new)))
391
+ simple_method_written_3 = simple_method.write
392
+ realised_simple_method_3 = simple_method.realise2(['Grim','fandango','Threepwood'])
393
+ assert_equal(
394
+ "\n#\n#\t@param\t[StringVariable] 'Grim'\n"\
395
+ "#\t@param\t[StringVariable] 'fandango'\n"\
396
+ "#\t@param\t[StringVariable] 'Threepwood'\n"\
397
+ "#\n#\ndef method_0(var_#{simple_method.usage[0].variable_id}, var_#{simple_method.usage[1].variable_id}, var_#{simple_method.usage[2].variable_id})\n"\
398
+ "\tvar_58 = var_#{simple_method.usage[0].variable_id}.length\n\tvar_68 = var_#{simple_method.usage[0].variable_id}.chop\nend\n",
399
+ realised_simple_method_3.write
400
+ )
401
+
402
+ # Go through each statement and check that there are no unrealised values
403
+ realised_simple_method_3.each do |x|
404
+ assert_equal(0,x.unrealised_variables.length)
405
+ end
406
+
407
+ # Try adding a variable that gets defined in a previous statement
408
+ # var_e = var_b.length
409
+ # var_f = var_e+var_c
410
+ var_e = Unknown.new
411
+ var_f = Unknown.new()
412
+ simple_method.push(Statement.new(var_e,Equal.new,InstanceCallContainer.new(var_b,StringLength.new)))
413
+ simple_method.push(Statement.new(var_f,Equal.new,var_e,Addition.new,var_c))
414
+ simple_method_written_4 = simple_method.write
415
+ realised_simple_method_4 = simple_method.realise2(['Grim','fandango','Threepwood'])
416
+ assert_equal(
417
+ "\n#\n#\t@param\t[StringVariable] 'Grim'\n#\t@param\t[StringVariable] 'fandango'\n#\t@param\t[StringVariable] 'Threepwood'\n#\n#\ndef method_0(var_33, var_34, var_35)\n\tvar_58 = var_33.length\n\tvar_68 = var_33.chop\n\tvar_79 = var_34.length\n\tvar_80 = var_79 + var_58\nend\n",
418
+ realised_simple_method_4.write
419
+ )
420
+
421
+ # Go through and check that there are no unrealised_variables
422
+ realised_simple_method_4.each do |x|
423
+ assert_equal(0,x.unrealised_variables.length)
424
+ end
425
+
426
+ # Check that a array variable can be realised
427
+ var_h = Unknown.new
428
+ simple_method.push(Statement.new(var_h,Equal.new,InstanceCallContainer.new(var_g,ArrayLength.new)))
429
+
430
+ # Check that a block statement can be used
431
+ nested_statement = BlockStatement.new(Statement.new(InstanceCallContainer.new(var_h,Times.new)))
432
+ nested_statement.push Statement.new(var_e,Equal.new,var_e,Addition.new,var_f)
433
+ simple_method.push(nested_statement)
434
+
435
+ # 2# Try relising a method that declares a value via another method call
436
+ # e.g. a method with the statement 'var = method_45'
437
+
438
+ # a. Create the method that returns a statement variable
439
+ return_statement_method = RuntimeMethod.new(MethodUsage.new(),Statement.new.to_var)
440
+ return_statement_method.push(Statement.new(Return.new,Statement.new(Return.new,'sparky').to_declaration ))
441
+
442
+ # b. Create the method
443
+ runtime_method_2 = RuntimeMethod.new(MethodUsage.new)
444
+ declared_variable = Unknown.new
445
+ runtime_method_2.push( Statement.new(declared_variable,Equal.new,DefCall.new(Statement.new.to_var,return_statement_method)))
446
+
447
+ # c. Check that the method can't be relised with the called runtime method
448
+ assert_raises(StandardError) {runtime_method_2.realise2(ParametersContainer.new)}
449
+
450
+ # d. Check that the unknow variable has been converted into a StatementVariable
451
+ assert_nothing_raised() {runtime_method_2.realise2(ParametersContainer.new,[return_statement_method])}
452
+ assert(runtime_method_2.realise2(ParametersContainer.new,[return_statement_method]).kind_of?(RealisedRuntimeMethod))
453
+ realised_runtime_method_2 = runtime_method_2.realise2(ParametersContainer.new,[return_statement_method])
454
+ assert_equal(false,realised_runtime_method_2.find_variable(declared_variable.variable_id).kind_of?(Unknown))
455
+
456
+ # Check that value of last variable after it has been realised
457
+
458
+ # NEXT Use method calls
459
+
460
+ end
461
+
462
+ # def test_realise_when_it_contains_a_method_variable
463
+ #
464
+ # runtime_method = RuntimeMethod.new(MethodUsage.new)
465
+ # runtime_method << Statement.new(Unknown.new,Equal.new,ClassMethodCallContainer.new(MethodParameterClass.new,New.new))
466
+ # assert_nothing_raised(runtime_method.realise2(ParametersContainer.new))
467
+ #
468
+ # end
469
+
470
+ # Test that the runtime methods are written properly.
471
+ #
472
+ def test_write
473
+
474
+ # Create a simple method with no paramaters
475
+ method_example_a = RuntimeMethod.new(MethodUsage.new)
476
+ assert_equal("\n#\n#\ndef method_#{method_example_a.method_id.to_s}\n\nend\n",method_example_a.write(nil))
477
+
478
+ # Test a simple method with one paramter
479
+ #param_1 = StringVariable.new('Girm')
480
+ param_1 = MethodParameter.new(Requirement.new(This.new,Equivalent.new,'Grim'.to_literal))
481
+ method_example_b = RuntimeMethod.new(MethodUsage.new(param_1))
482
+ assert_not_equal("#\n#\ndef method_"+method_example_b.method_id.to_s+"\n\nend\n",method_example_b.write)
483
+
484
+ # Test that neested methods are writen properly
485
+ assert_equal("\n#\n#\ndef method_7\n\tvar_26 = ''\n\tvar_27 = 'x'\n\t3.times do |var_28|\n\t\tvar_26 = var_26 + var_27\n\tend\n\nend\n",@build_xxx_method.write)
486
+
487
+ # Test how the method is written with tabs
488
+ assert_equal("\n\t#\n\t#\n\tdef method_7\n\t\tvar_26 = ''\n\t\tvar_27 = 'x'\n\t\t3.times do |var_28|\n\t\t\tvar_26 = var_26 + var_27\n\t\tend\n\n\tend\n",@build_xxx_method.write(nil,1))
489
+
490
+ # TODO Test write with passed in parameters
491
+ end
492
+
493
+ def test_push
494
+
495
+ # Create a method that is passed a string
496
+ #manny = 'Manny'.to_var
497
+ manny = MethodParameter.new('Manny'.to_requirement)
498
+ string_runtime_method = RuntimeMethod.new(MethodUsage.new(manny),nil)
499
+ #string_runtime_method.parameters = [manny]
500
+
501
+ manny_length_var = Unknown.new
502
+ a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny_length_var,StringLength.new))
503
+ string_runtime_method.push(a_equals_manny_length)
504
+
505
+ # Check that the variable ids are equal
506
+ assert_nothing_raised(){string_runtime_method.find_variable(manny_length_var.variable_id)}
507
+
508
+ end
509
+
510
+ def test_identify_overriding_statements
511
+
512
+ # Create a method that is passed a string
513
+ manny = 'Manny'.to_var
514
+ # def method_0(var_a)
515
+ # var_b = var_a.length
516
+ # var_b.times do |var_c|
517
+ # var_a = 'Glotis'
518
+ # end
519
+ # end
520
+ string_runtime_method = RuntimeMethod.new(
521
+ MethodUsage.new(MethodParameter.new(Requirement.new(This.new,Equivalent.new,'Manny'.to_literal))),nil
522
+ )
523
+
524
+ manny_length_var = Unknown.new
525
+ a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny,StringLength.new))
526
+ string_runtime_method.push(a_equals_manny_length)
527
+
528
+ # Add the first nested statement to the method.
529
+ manny_length_times = Statement.new(InstanceCallContainer.new(manny_length_var,Times.new))
530
+ manny_length_times_do = BlockStatement.new(manny_length_times)
531
+
532
+ # Override manny with a new string
533
+ overriding_statement = Statement.new(manny,Equal.new,Literal.new('Glotis'))
534
+ manny_length_times_do.push( overriding_statement )
535
+ string_runtime_method.push(manny_length_times_do)
536
+
537
+ # Identify all the overridden statements
538
+ assert_nothing_raised() {string_runtime_method.identify_overriding_statements(ParametersContainer.new(manny))}
539
+ assert_equal(false,string_runtime_method.find_statement(a_equals_manny_length.statement_id).overrides?)
540
+ assert_equal(true,string_runtime_method.find_statement(overriding_statement.statement_id).overrides?)
541
+
542
+ end
543
+
544
+ def test_to_var
545
+ assert(@simple_method.to_var.kind_of?(RuntimeMethodParameter))
546
+
547
+ # Declare the runtime method variable and check it retains the properties of
548
+ # the original runtime method.
549
+ simple_method_var = @simple_method.to_var
550
+
551
+ # Check the statements are retained
552
+ assert_equal(@simple_method.length,simple_method_var.value.length)
553
+ assert_equal(@simple_method.method_id,simple_method_var.value.method_id)
554
+
555
+ # Check that variable ids can be set
556
+ assert_equal(8,@simple_method.to_var(8,9).variable_id)
557
+ assert_equal(9,@simple_method.to_var(8,9).uniq_id)
558
+
559
+ end
560
+
561
+ def test_to_declaration
562
+
563
+ # Test the simplest possible runtime method - accepts nothing and returns nothing
564
+ simple_runtime_method = RuntimeMethod.new(MethodUsage.new,nil.to_var)
565
+ assert_nothing_raised() {simple_runtime_method.to_declaration}
566
+
567
+ # Test a simple runtime method expected to return a literal
568
+ literal_return_runtime_method = RuntimeMethod.new(MethodUsage.new,56)
569
+ assert_nothing_raised() {literal_return_runtime_method.to_declaration}
570
+
571
+ # Test a simple runtime method that accepts a parameter
572
+ single_parameter_runtime_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new('test'.to_requirement)),nil)
573
+ assert_nothing_raised() {single_parameter_runtime_method.to_declaration}
574
+
575
+ # Test that a runtime method that contains one statement is duplicated correctly
576
+ test_3_runtime_method = RuntimeMethod.new(MethodUsage.new)
577
+ test_3_runtime_method.push Statement.new(Return.new,'Tony')
578
+ assert_equal('Tony',MethodValidation.new.use_runtime_method(test_3_runtime_method))
579
+
580
+ # Create a duplicate of the simple runtime method
581
+ duplicate_test_3_runtime_method = test_3_runtime_method.to_declaration.evaluate
582
+ assert_equal('Tony',MethodValidation.new.use_runtime_method(duplicate_test_3_runtime_method))
583
+
584
+ end
585
+
586
+ def test_abstract_variables_for_tracking_with_some_simple_statement
587
+ #assert_equal(1,@simple_method.abstract_variables_for_tracking(Parser.run('var4 = "test"')).length)
588
+ # TODO The parser doesn't generate a variable with an id of 7 here - is that a problem?
589
+ assert_equal(2,@simple_method.abstract_variables_for_tracking(Parser.run('var7 = var70.length')).length)
590
+ end
591
+
592
+ def test_all_pass_with_basic_method
593
+ basic_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new()))
594
+ basic_method.push(Parser.run('return var'+basic_method.usage.first.variable_id.to_s))
595
+ test_cases = [
596
+ {:params=>['sparky'], :output=>'sparky'},
597
+ {:params=>['pip'], :output=>'pip'},
598
+ ]
599
+ assert_equal(true,basic_method.all_pass?(test_cases))
600
+ end
601
+
602
+ def test_pass_with_basic_method
603
+ basic_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new()))
604
+ basic_method.push(Parser.run('return var'+basic_method.usage.first.variable_id.to_s))
605
+ assert_equal(true,basic_method.pass?({:params=>['sparky'], :output=>'sparky'}))
606
+ end
607
+
608
+ def test_pass_with_a_method_that_returns_an_integer
609
+ basic_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new()))
610
+ basic_method.push(
611
+ Parser.run("return var#{basic_method.usage.first.variable_id.to_s}.length")
612
+ )
613
+ assert_equal(true,basic_method.pass?({:params=>['sparky'], :output=>'sparky'.length}))
614
+ end
615
+
616
+ end