cauldron 0.1.0 → 0.1.1
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.
- data/Gemfile +2 -0
- data/Rakefile +7 -0
- data/VERSION +1 -1
- data/features/cauldron_generates_runtime_method.feature +3 -2
- data/features/step_definitions/cauldron_steps.rb +0 -1
- data/features/support/method_1.example +3 -0
- data/features/support/method_2.example +6 -0
- data/lib/Chain.rb +140 -264
- data/lib/CodeHandler.rb +0 -4
- data/lib/ScopeDependencies.rb +1 -0
- data/lib/Theory.rb +12 -15
- data/lib/UnifiedChain.rb +265 -8
- data/lib/cauldron.rb +1 -1
- data/lib/cauldron/demos.rb +280 -0
- data/lib/cauldron/pot.rb +56 -30
- data/lib/cauldron/sexp2cauldron.rb +109 -126
- data/lib/cauldron/terminal.rb +5 -74
- data/lib/core/ClassMethodCallContainer.rb +14 -0
- data/lib/core/Container.rb +12 -2
- data/lib/core/InstanceCallContainer.rb +30 -4
- data/lib/core/TheoryGenerator.rb +2 -9
- data/lib/core/assignment/Equal.rb +1 -1
- data/lib/core/assignment/Equivalent.rb +1 -1
- data/lib/core/assignment/NotEqual.rb +1 -1
- data/lib/core/call_container/CallContainer.rb +7 -1
- data/lib/core/instance_call/Chop.rb +0 -9
- data/lib/core/instance_call/instance_calls.rb +8 -0
- data/lib/core/instance_call/length_equal.rb +1 -1
- data/lib/core/requirement/Requirement.rb +1 -0
- data/lib/core/runtime_class/class_names.rb +12 -12
- data/lib/core/runtime_method/ActsAsRuntimeMethod.rb +0 -7
- data/lib/core/runtime_method/RuntimeMethod.rb +59 -45
- data/lib/core/statement/ActsAsStatement.rb +1 -1
- data/lib/core/statement/ArrayAccess.rb +28 -2
- data/lib/core/statement/OpenStatement.rb +7 -0
- data/lib/core/statement/Statement.rb +22 -18
- data/lib/core/statement/TheoryStatement.rb +8 -1
- data/lib/core/syntax/Addition.rb +3 -2
- data/lib/core/syntax/If.rb +8 -0
- data/lib/core/syntax/Return.rb +1 -1
- data/lib/core/variable/BaseVariable.rb +0 -2
- data/lib/core/variable/MethodParameter.rb +4 -31
- data/lib/core/variable/Unknown.rb +1 -5
- data/lib/implemented_chain.rb +3 -2
- data/lib/required.rb +0 -1
- data/lib/ruby_code/String.rb +0 -17
- data/lib/theories.rb +25 -1
- data/lib/theory/TheoryAction.rb +35 -5
- data/lib/theory/TheoryChainValidator.rb +10 -8
- data/lib/theory/TheoryComponent.rb +17 -0
- data/lib/theory/TheoryConnector.rb +76 -9
- data/lib/theory/TheoryDependent.rb +2 -2
- data/lib/theory/TheoryImplementation.rb +7 -7
- data/lib/util/ClassEvaluation.rb +2 -7
- data/lib/util/MethodValidation.rb +10 -6
- data/lib/util/Parser.rb +26 -20
- data/lib/util/StringToTheory.rb +27 -3
- data/spec/cauldron/chain_spec.rb +24 -0
- data/spec/cauldron/demos_spec.rb +30 -0
- data/spec/cauldron/pot_spec.rb +66 -0
- data/spec/cauldron/runtime_method_spec.rb +47 -5
- data/spec/cauldron/sexp_2_cauldron_spec.rb +92 -0
- data/spec/cauldron/terminal_spec.rb +1 -1
- data/spec/cauldron/theory_action_spec.rb +20 -0
- data/spec/cauldron/theory_connector_spec.rb +52 -0
- data/spec/cauldron/theory_spec.rb +59 -0
- data/spec/cauldron/unified_chain_spec.rb +102 -0
- data/spec/spec_helper.rb +10 -1
- data/tasks/theory_tasks.rake +274 -0
- data/test/fixtures/implementation_results/0/dump +0 -0
- data/test/fixtures/theories/0/dump +0 -0
- data/test/fixtures/theories/1/dump +0 -0
- data/test/fixtures/theories/10/dump +0 -0
- data/test/fixtures/theories/11/dump +0 -0
- data/test/fixtures/theories/12/dump +0 -0
- data/test/fixtures/theories/13/declaration.txt +1 -1
- data/test/fixtures/theories/13/desc +1 -1
- data/test/fixtures/theories/13/dump +0 -0
- data/test/fixtures/theories/14/dump +0 -0
- data/test/fixtures/theories/15/dump +0 -0
- data/test/fixtures/theories/16/dump +0 -0
- data/test/fixtures/theories/17/dump +0 -0
- data/test/fixtures/theories/18/dump +0 -0
- data/test/fixtures/theories/19/dump +0 -0
- data/test/fixtures/theories/2/dump +0 -0
- data/test/fixtures/theories/20/declaration.txt +1 -1
- data/test/fixtures/theories/20/desc +1 -1
- data/test/fixtures/theories/20/dump +0 -0
- data/test/fixtures/theories/3/dump +0 -0
- data/test/fixtures/theories/4/dump +0 -0
- data/test/fixtures/theories/5/dump +0 -0
- data/test/fixtures/theories/6/dump +0 -0
- data/test/fixtures/theories/7/dump +0 -0
- data/test/fixtures/theories/8/dump +0 -0
- data/test/fixtures/theories/9/dump +0 -0
- data/test/fixtures/theory_implementations/0/declaration.txt +1 -1
- data/test/fixtures/theory_implementations/0/dump +0 -0
- data/test/fixtures/theory_implementations/1/declaration.txt +11 -0
- data/test/fixtures/theory_implementations/1/dump +0 -0
- data/test/fixtures/theory_implementations/2/declaration.txt +11 -0
- data/test/fixtures/theory_implementations/2/dump +0 -0
- data/test/output/simple_method.txt +0 -1
- data/test/tc_contextual_variables.rb +2 -41
- data/test/tc_describe.rb +1 -2
- data/test/tc_method.rb +2 -5
- data/test/unit/core/runtime_method/tc_realised_runtime_method.rb +5 -3
- data/test/unit/core/runtime_method/tc_runtime_method.rb +34 -56
- data/test/unit/core/statement/tc_block_statement.rb +2 -0
- data/test/unit/core/statement/tc_open_statement.rb +15 -6
- data/test/unit/core/statement/tc_statement.rb +4 -5
- data/test/unit/core/statement/tc_statement_dependencies.rb +1 -0
- data/test/unit/core/statement/tc_theory_statement.rb +2 -0
- data/test/unit/core/syntax/tc_if_container.rb +5 -5
- data/test/unit/core/tc_theory_generator_heavy.rb +1 -1
- data/test/unit/core/tracking/tc_history.rb +3 -1
- data/test/unit/core/variable/tc_method_parameter_variable.rb +2 -2
- data/test/unit/tc_chain_with_case_1.rb +1 -1
- data/test/unit/tc_method_usage.rb +1 -1
- data/test/unit/tc_theory.rb +8 -2
- data/test/unit/theory/tc_theory_action.rb +37 -5
- data/test/unit/theory/tc_theory_chain_validator.rb +3 -3
- data/test/unit/theory/tc_theory_connector.rb +2 -37
- data/test/unit/theory/tc_theory_dependent.rb +2 -0
- data/test/unit/theory/tc_theory_implementation.rb +5 -1
- data/test/unit/theory/tc_theory_result.rb +3 -2
- data/test/unit/util/tc_method_validation.rb +4 -1
- data/test/unit/util/tc_parser.rb +2 -0
- data/test/unit/util/tc_string_to_theory.rb +3 -2
- data/tmp/runtime_method_evaluation.rb +7 -4
- metadata +59 -13
- data/lib/core/syntax/IfContainer.rb +0 -100
data/test/tc_describe.rb
CHANGED
|
@@ -18,8 +18,7 @@ System.reset
|
|
|
18
18
|
def test_nothing_is_added
|
|
19
19
|
|
|
20
20
|
# Create the method variable for the method (self = 'test')
|
|
21
|
-
|
|
22
|
-
method_variable = MethodParameter.new(requirement)
|
|
21
|
+
method_variable = MethodParameter.new
|
|
23
22
|
|
|
24
23
|
# # Create runtime method with one parameter ('test')
|
|
25
24
|
# runtime_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new))
|
data/test/tc_method.rb
CHANGED
|
@@ -12,7 +12,7 @@ class TestMethod < Test::Unit::TestCase
|
|
|
12
12
|
@simple_method_usage = MethodUsage.new()
|
|
13
13
|
|
|
14
14
|
# Create the simple runtime method
|
|
15
|
-
@simple_method = RuntimeMethod.new(@simple_method_usage)
|
|
15
|
+
@simple_method = RuntimeMethod.new(@simple_method_usage,0)
|
|
16
16
|
|
|
17
17
|
# Create the usage for a method with two paramters
|
|
18
18
|
param_1 = MethodParameter.new
|
|
@@ -20,9 +20,6 @@ class TestMethod < Test::Unit::TestCase
|
|
|
20
20
|
|
|
21
21
|
# Create the method with paramaters
|
|
22
22
|
@method_with_paramaters = RuntimeMethod.new(@parameter_method_usage)
|
|
23
|
-
|
|
24
|
-
# Setting the method paramaters
|
|
25
|
-
#@method_with_paramaters.parameters = [MethodParameter.new(Requirement.new(This.new,Equal.new,Literal.new('test')))]
|
|
26
23
|
|
|
27
24
|
end
|
|
28
25
|
|
|
@@ -81,7 +78,7 @@ class TestMethod < Test::Unit::TestCase
|
|
|
81
78
|
original_method = RuntimeMethod.new(parameter_method_usage)
|
|
82
79
|
|
|
83
80
|
# Add parameters to the method
|
|
84
|
-
param_values = MethodParameter.new
|
|
81
|
+
param_values = MethodParameter.new
|
|
85
82
|
#original_method.parameters = [param_values]
|
|
86
83
|
|
|
87
84
|
# Check the number of paramaters
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../../../../lib',__FILE__)
|
|
2
|
+
|
|
1
3
|
require 'required'
|
|
2
4
|
require 'test/unit'
|
|
3
5
|
|
|
@@ -6,9 +8,9 @@ class TestRealisedRuntimeMethod < Test::Unit::TestCase
|
|
|
6
8
|
def setup
|
|
7
9
|
|
|
8
10
|
# Create the method usage
|
|
9
|
-
@method_var_a = MethodParameter.new
|
|
11
|
+
@method_var_a = MethodParameter.new
|
|
10
12
|
# Not used in the method
|
|
11
|
-
@method_var_b = MethodParameter.new
|
|
13
|
+
@method_var_b = MethodParameter.new
|
|
12
14
|
@single_parameter_usage = MethodUsage.new(@method_var_a,@method_var_b)
|
|
13
15
|
|
|
14
16
|
# Create the simple method used in the tests
|
|
@@ -96,7 +98,7 @@ class TestRealisedRuntimeMethod < Test::Unit::TestCase
|
|
|
96
98
|
firefox = 'firefox'.to_declared_variable_statement
|
|
97
99
|
statement_with_open_statement.push(firefox)
|
|
98
100
|
firefox_var = firefox.declared_variable
|
|
99
|
-
if_statement = Statement.new(
|
|
101
|
+
if_statement = Statement.new(If.new,Container.new(InstanceCallContainer.new(firefox_var,StringLength.new),Equivalent.new,7.to_literal))
|
|
100
102
|
open_if_statement = OpenStatement.new(if_statement)
|
|
101
103
|
open_if_statement.push('IE'.to_declared_variable_statement)
|
|
102
104
|
statement_with_open_statement.push(open_if_statement)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../../../../lib',__FILE__)
|
|
2
|
+
|
|
1
3
|
require 'required'
|
|
2
4
|
require 'test/unit'
|
|
3
5
|
|
|
@@ -6,9 +8,9 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
6
8
|
def setup
|
|
7
9
|
|
|
8
10
|
# Create the method usage
|
|
9
|
-
@method_var_a = MethodParameter.new
|
|
11
|
+
@method_var_a = MethodParameter.new
|
|
10
12
|
# Not used in the method
|
|
11
|
-
@method_var_b = MethodParameter.new
|
|
13
|
+
@method_var_b = MethodParameter.new
|
|
12
14
|
@single_parameter_usage = MethodUsage.new(@method_var_a,@method_var_b)
|
|
13
15
|
|
|
14
16
|
# Create the simple method used in the tests
|
|
@@ -34,7 +36,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
34
36
|
@method_b = RuntimeMethod.new(MethodUsage.new)
|
|
35
37
|
|
|
36
38
|
# Create a method that accepts one string parameter and some string parameters to use
|
|
37
|
-
@method_c = RuntimeMethod.new(MethodUsage.new(MethodParameter.new
|
|
39
|
+
@method_c = RuntimeMethod.new(MethodUsage.new(MethodParameter.new))
|
|
38
40
|
@var_g = 'Monkey'.to_var
|
|
39
41
|
@var_h = 'Island'.to_var
|
|
40
42
|
@var_i = '3'.to_var
|
|
@@ -45,12 +47,12 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
45
47
|
@method_d = RuntimeMethod.new(MethodUsage.new(),@method_respnse_a)
|
|
46
48
|
|
|
47
49
|
# Create a method that excepts two string parameters
|
|
48
|
-
@method_usage_var_b = MethodParameter.new(
|
|
49
|
-
@method_usage_var_c = MethodParameter.new(
|
|
50
|
+
@method_usage_var_b = MethodParameter.new()
|
|
51
|
+
@method_usage_var_c = MethodParameter.new()
|
|
50
52
|
@method_e = RuntimeMethod.new(MethodUsage.new(@method_usage_var_b,@method_usage_var_c))
|
|
51
53
|
|
|
52
|
-
@method_usage_var_e = MethodParameter.new(
|
|
53
|
-
@method_usage_var_f = MethodParameter.new(
|
|
54
|
+
@method_usage_var_e = MethodParameter.new()
|
|
55
|
+
@method_usage_var_f = MethodParameter.new()
|
|
54
56
|
@method_respnse_b = 'Halo'.to_var
|
|
55
57
|
@method_f = RuntimeMethod.new(MethodUsage.new(@method_usage_var_e,@method_usage_var_f),@method_respnse_b)
|
|
56
58
|
|
|
@@ -169,7 +171,13 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
169
171
|
# Check that each of the variables has the correct evaluated value
|
|
170
172
|
local_var_a = 'test'.to_var
|
|
171
173
|
local_var_b = 'LividKel'.to_var
|
|
172
|
-
assert_equal(
|
|
174
|
+
assert_equal(
|
|
175
|
+
local_var_a.value,
|
|
176
|
+
@simple_method.literal_value_of_var(
|
|
177
|
+
@method_var_a.variable_id,
|
|
178
|
+
ParametersContainer.new(local_var_a,local_var_b)
|
|
179
|
+
)
|
|
180
|
+
)
|
|
173
181
|
assert_equal(9,@simple_method.literal_value_of_var(@var_b.variable_id,ParametersContainer.new(local_var_a,local_var_b)))
|
|
174
182
|
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
183
|
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)))
|
|
@@ -200,24 +208,6 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
200
208
|
assert_equal(9,@method_e.callable_combinations([@var_g,@var_h,@var_i]).length)
|
|
201
209
|
|
|
202
210
|
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
211
|
|
|
222
212
|
# TODO Need to test with methods that require parameters (var_a) etc
|
|
223
213
|
def test_history
|
|
@@ -228,7 +218,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
228
218
|
|
|
229
219
|
# Check that history retains the correct variable ids
|
|
230
220
|
manny = 'Manny'.to_var
|
|
231
|
-
string_runtime_method = RuntimeMethod.new(MethodUsage.new(
|
|
221
|
+
string_runtime_method = RuntimeMethod.new(MethodUsage.new(),nil)
|
|
232
222
|
|
|
233
223
|
# Add a statement to the runtime method
|
|
234
224
|
manny_length_var = Unknown.new
|
|
@@ -274,7 +264,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
274
264
|
def test_trackify
|
|
275
265
|
|
|
276
266
|
# Create a simple method to be trackified
|
|
277
|
-
manny = MethodParameter.new(
|
|
267
|
+
manny = MethodParameter.new()
|
|
278
268
|
string_runtime_method = RuntimeMethod.new(MethodUsage.new(manny),nil)
|
|
279
269
|
|
|
280
270
|
# Add a statement to the runtime method
|
|
@@ -339,11 +329,9 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
339
329
|
def test_realise
|
|
340
330
|
|
|
341
331
|
# Create a simple runtime method and check that the paramaters are valid
|
|
342
|
-
var_a = MethodParameter.new
|
|
343
|
-
var_b = MethodParameter.new
|
|
344
|
-
var_g = MethodParameter.new
|
|
345
|
-
Requirement.new(InstanceCallContainer.new(This.new,ClassCall.new),Equivalent.new,ArrayClass.new)
|
|
346
|
-
)
|
|
332
|
+
var_a = MethodParameter.new
|
|
333
|
+
var_b = MethodParameter.new
|
|
334
|
+
var_g = MethodParameter.new
|
|
347
335
|
simple_method = RuntimeMethod.new(MethodUsage.new(var_a,var_b,var_g))
|
|
348
336
|
|
|
349
337
|
# Check that realise returns an identical runtime method
|
|
@@ -370,7 +358,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
370
358
|
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
359
|
|
|
372
360
|
# Check that invalid paramters and undeclared parameters are caught
|
|
373
|
-
temp_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new
|
|
361
|
+
temp_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new))
|
|
374
362
|
assert_raises(StandardError) {temp_method.realise2([])}
|
|
375
363
|
|
|
376
364
|
# Now let's add a few statements to the method
|
|
@@ -381,7 +369,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
381
369
|
assert_equal(
|
|
382
370
|
"\n#\n#\t@param\t[StringVariable] 'Grim'\n#\t@param\t[StringVariable] 'fandango'\n#\t@param\t[StringVariable] 'Threepwood'\n#\n#\n"\
|
|
383
371
|
"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\
|
|
372
|
+
"\n\tvar_64 = var_35.length\nend\n",
|
|
385
373
|
realised_instance_2.write
|
|
386
374
|
)
|
|
387
375
|
|
|
@@ -395,7 +383,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
395
383
|
"#\t@param\t[StringVariable] 'fandango'\n"\
|
|
396
384
|
"#\t@param\t[StringVariable] 'Threepwood'\n"\
|
|
397
385
|
"#\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
|
-
"\
|
|
386
|
+
"\tvar_64 = var_#{simple_method.usage[0].variable_id}.length\n\tvar_76 = var_#{simple_method.usage[0].variable_id}.chop\nend\n",
|
|
399
387
|
realised_simple_method_3.write
|
|
400
388
|
)
|
|
401
389
|
|
|
@@ -414,7 +402,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
414
402
|
simple_method_written_4 = simple_method.write
|
|
415
403
|
realised_simple_method_4 = simple_method.realise2(['Grim','fandango','Threepwood'])
|
|
416
404
|
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(
|
|
405
|
+
"\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_35, var_36, var_37)\n\tvar_64 = var_35.length\n\tvar_76 = var_35.chop\n\tvar_89 = var_36.length\n\tvar_90 = var_89 + var_64\nend\n",
|
|
418
406
|
realised_simple_method_4.write
|
|
419
407
|
)
|
|
420
408
|
|
|
@@ -459,44 +447,34 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
459
447
|
|
|
460
448
|
end
|
|
461
449
|
|
|
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
450
|
# Test that the runtime methods are written properly.
|
|
471
451
|
#
|
|
472
452
|
def test_write
|
|
473
453
|
|
|
474
454
|
# Create a simple method with no paramaters
|
|
475
455
|
method_example_a = RuntimeMethod.new(MethodUsage.new)
|
|
476
|
-
assert_equal("\n#\n#\ndef method_#{method_example_a.method_id.to_s}\
|
|
456
|
+
assert_equal("\n#\n#\ndef method_#{method_example_a.method_id.to_s}\nend\n",method_example_a.write(nil))
|
|
477
457
|
|
|
478
458
|
# Test a simple method with one paramter
|
|
479
459
|
#param_1 = StringVariable.new('Girm')
|
|
480
|
-
param_1 = MethodParameter.new
|
|
460
|
+
param_1 = MethodParameter.new
|
|
481
461
|
method_example_b = RuntimeMethod.new(MethodUsage.new(param_1))
|
|
482
462
|
assert_not_equal("#\n#\ndef method_"+method_example_b.method_id.to_s+"\n\nend\n",method_example_b.write)
|
|
483
463
|
|
|
484
464
|
# Test that neested methods are writen properly
|
|
485
|
-
assert_equal("\n#\n#\ndef
|
|
465
|
+
assert_equal("\n#\n#\ndef method_6\n\tvar_28 = ''\n\tvar_29 = 'x'\n\t3.times do |var_30|\n\t\tvar_28 = var_28 + var_29\n\tend\n\nend\n",@build_xxx_method.write)
|
|
486
466
|
|
|
487
467
|
# Test how the method is written with tabs
|
|
488
|
-
assert_equal("\n\t#\n\t#\n\tdef
|
|
489
|
-
|
|
490
|
-
# TODO Test write with passed in parameters
|
|
468
|
+
assert_equal("\n\t#\n\t#\n\tdef method_6\n\t\tvar_28 = ''\n\t\tvar_29 = 'x'\n\t\t3.times do |var_30|\n\t\t\tvar_28 = var_28 + var_29\n\t\tend\n\n\tend\n",@build_xxx_method.write(nil,1))
|
|
469
|
+
|
|
491
470
|
end
|
|
492
471
|
|
|
493
472
|
def test_push
|
|
494
473
|
|
|
495
474
|
# Create a method that is passed a string
|
|
496
475
|
#manny = 'Manny'.to_var
|
|
497
|
-
manny = MethodParameter.new
|
|
498
|
-
string_runtime_method = RuntimeMethod.new(MethodUsage.new(manny),nil)
|
|
499
|
-
#string_runtime_method.parameters = [manny]
|
|
476
|
+
manny = MethodParameter.new
|
|
477
|
+
string_runtime_method = RuntimeMethod.new(MethodUsage.new(manny),nil)
|
|
500
478
|
|
|
501
479
|
manny_length_var = Unknown.new
|
|
502
480
|
a_equals_manny_length = Statement.new(manny_length_var,Equal.new,InstanceCallContainer.new(manny_length_var,StringLength.new))
|
|
@@ -518,7 +496,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
518
496
|
# end
|
|
519
497
|
# end
|
|
520
498
|
string_runtime_method = RuntimeMethod.new(
|
|
521
|
-
MethodUsage.new(MethodParameter.new
|
|
499
|
+
MethodUsage.new(MethodParameter.new),nil
|
|
522
500
|
)
|
|
523
501
|
|
|
524
502
|
manny_length_var = Unknown.new
|
|
@@ -569,7 +547,7 @@ class TestRuntimeMethod < Test::Unit::TestCase
|
|
|
569
547
|
assert_nothing_raised() {literal_return_runtime_method.to_declaration}
|
|
570
548
|
|
|
571
549
|
# Test a simple runtime method that accepts a parameter
|
|
572
|
-
single_parameter_runtime_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new(
|
|
550
|
+
single_parameter_runtime_method = RuntimeMethod.new(MethodUsage.new(MethodParameter.new()),nil)
|
|
573
551
|
assert_nothing_raised() {single_parameter_runtime_method.to_declaration}
|
|
574
552
|
|
|
575
553
|
# Test that a runtime method that contains one statement is duplicated correctly
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../../../../lib',__FILE__)
|
|
2
|
+
|
|
1
3
|
require 'required'
|
|
2
4
|
require 'test/unit'
|
|
3
5
|
|
|
@@ -7,7 +9,7 @@ class TestOpenStatement < Test::Unit::TestCase
|
|
|
7
9
|
|
|
8
10
|
# Create a simple open if statement
|
|
9
11
|
@simple_if_statement_var = Unknown.new
|
|
10
|
-
simple_if_statement = Statement.new(If.new
|
|
12
|
+
simple_if_statement = Statement.new(If.new,Container.new(@simple_if_statement_var,Equivalent.new,'Stobart'.to_literal))
|
|
11
13
|
@simple_open_if_statement = OpenStatement.new(simple_if_statement)
|
|
12
14
|
|
|
13
15
|
# Create a simple open statement with variables
|
|
@@ -31,11 +33,11 @@ class TestOpenStatement < Test::Unit::TestCase
|
|
|
31
33
|
def test_write
|
|
32
34
|
|
|
33
35
|
# Test the simple statement is written out properly
|
|
34
|
-
assert_equal("if
|
|
36
|
+
assert_equal("if(#{@simple_if_statement_var.write} == 'Stobart')\nend" ,@simple_open_if_statement.write)
|
|
35
37
|
|
|
36
38
|
# Test that internal statements are properly tabs
|
|
37
39
|
@simple_open_if_statement << Statement.new(Return.new,True.new)
|
|
38
|
-
assert_equal("if
|
|
40
|
+
assert_equal("if(#{@simple_if_statement_var.write} == 'Stobart')\n\treturn true\nend" ,@simple_open_if_statement.write)
|
|
39
41
|
|
|
40
42
|
end
|
|
41
43
|
|
|
@@ -55,9 +57,16 @@ class TestOpenStatement < Test::Unit::TestCase
|
|
|
55
57
|
# Test copy with an open theory statement
|
|
56
58
|
# TODO This is quite a good way to test copy - I should use it across the other main classes
|
|
57
59
|
initial_theory = StringToTheory.run("if(var1.length = var2.length)\nend")
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
# => TODO uniq shouldn't be needed - why is it selecting the same value
|
|
61
|
+
original_element_ids = initial_theory.select_all{true}.collect {|x| x.object_id}.uniq
|
|
62
|
+
|
|
63
|
+
copied_theory = initial_theory.copy
|
|
64
|
+
copied_elements_ids = copied_theory.select_all{true}.collect {|x| x.object_id}.uniq
|
|
65
|
+
|
|
66
|
+
assert_equal(
|
|
67
|
+
original_element_ids.length*2,
|
|
68
|
+
(copied_elements_ids + original_element_ids).uniq.length
|
|
69
|
+
)
|
|
61
70
|
end
|
|
62
71
|
|
|
63
72
|
def test_write_structure_with_simple_examples
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../../../../lib',__FILE__)
|
|
2
|
+
|
|
1
3
|
require 'required'
|
|
2
4
|
require 'test/unit'
|
|
3
5
|
|
|
@@ -128,10 +130,7 @@ class TestStatement < Test::Unit::TestCase
|
|
|
128
130
|
def test_variable_subst
|
|
129
131
|
|
|
130
132
|
# Create the substitute variable (the one to replace the current one) self.class = String
|
|
131
|
-
|
|
132
|
-
# TODO If this is 8 it still works - it should raise an exception since it is a conflict
|
|
133
|
-
string_value_req = Requirement.new(This.new,Equal.new,Literal.new('tests'))
|
|
134
|
-
subst_variable = MethodParameter.new(class_req)
|
|
133
|
+
subst_variable = MethodParameter.new
|
|
135
134
|
|
|
136
135
|
# Create the variable to be replaced self.class = String
|
|
137
136
|
replacable_variable = Unknown.new
|
|
@@ -404,7 +403,7 @@ class TestStatement < Test::Unit::TestCase
|
|
|
404
403
|
|
|
405
404
|
# c. Retrieve the history instance for the runtime method
|
|
406
405
|
history_2 = runtime_method_2.history(ParametersContainer.new,[calling_runtime_method_2])
|
|
407
|
-
|
|
406
|
+
|
|
408
407
|
assert_equal(true,statement_2.realise2(history_2).find_variable(unknown_variable_2.variable_id).kind_of?(StringVariable))
|
|
409
408
|
assert_equal('sparky',statement_2.realise2(history_2).find_variable(unknown_variable_2.variable_id).value)
|
|
410
409
|
|
|
@@ -8,18 +8,18 @@ class TestIfContainer < Test::Unit::TestCase
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def teardown
|
|
11
|
-
System.reset
|
|
11
|
+
System.reset
|
|
12
12
|
RuntimeMethod.reset_global_id
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def test_write
|
|
16
16
|
|
|
17
17
|
# 1. if(true)
|
|
18
|
-
assert_equal('if(true)',
|
|
18
|
+
assert_equal('if(true)',Statement.new(If.new,Container.new(True.new)).write)
|
|
19
19
|
|
|
20
20
|
# 2. if(var_x == 'test')
|
|
21
21
|
unknown_variable_2 = Unknown.new
|
|
22
|
-
if_statement_2 =
|
|
22
|
+
if_statement_2 = Statement.new(If.new,Container.new(unknown_variable_2,Equivalent.new,Literal.new('test')))
|
|
23
23
|
assert_equal('if(var_'+unknown_variable_2.variable_id.to_s+" == 'test')",if_statement_2.write)
|
|
24
24
|
|
|
25
25
|
end
|
|
@@ -27,11 +27,11 @@ System.reset
|
|
|
27
27
|
def test_copy
|
|
28
28
|
|
|
29
29
|
# 1. Check copy works if(true)
|
|
30
|
-
assert_equal(
|
|
30
|
+
assert_equal(Statement.new(If.new,Container.new(True.new)).write,Statement.new(If.new(Container.new(True.new))).copy.write)
|
|
31
31
|
|
|
32
32
|
# 2. Check copy works for "if(var_x == 'test')"
|
|
33
33
|
unknown_variable_2 = Unknown.new
|
|
34
|
-
if_statement_2 =
|
|
34
|
+
if_statement_2 = Statement.new(If.new,Container.new(unknown_variable_2,Equivalent.new,Literal.new('test')))
|
|
35
35
|
assert_equal(if_statement_2.copy.write,if_statement_2.write)
|
|
36
36
|
|
|
37
37
|
end
|
|
@@ -34,7 +34,7 @@ class TestTheoryGenerator < Test::Unit::TestCase
|
|
|
34
34
|
assert_equal(
|
|
35
35
|
true,
|
|
36
36
|
theories.any? do |x|
|
|
37
|
-
x.write == '<runtime_method>.add_statement_at(OpenStatement.new(
|
|
37
|
+
x.write == '<runtime_method>.add_statement_at(OpenStatement.new(Statement.new(If.new,Container.new(var1.params[var5], Equivalent.new, var2[var3][:params][var5]))),var1.statement_id)'
|
|
38
38
|
end
|
|
39
39
|
)
|
|
40
40
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
$LOAD_PATH << File.expand_path('../../../../../lib',__FILE__)
|
|
2
|
+
|
|
1
3
|
require 'required'
|
|
2
4
|
require 'test/unit'
|
|
3
5
|
|
|
@@ -9,7 +11,7 @@ class TestHistory < Test::Unit::TestCase
|
|
|
9
11
|
@simple_runtime_method = RuntimeMethod.new(MethodUsage.new,nil.to_var)
|
|
10
12
|
|
|
11
13
|
# Create a method that is passed a string
|
|
12
|
-
@grim_fandango_method_var = MethodParameter.new
|
|
14
|
+
@grim_fandango_method_var = MethodParameter.new
|
|
13
15
|
@grim_fandango = 'Grim Fandango'.to_var(@grim_fandango_method_var.variable_id)
|
|
14
16
|
@string_runtime_method = RuntimeMethod.new(MethodUsage.new(@grim_fandango_method_var),nil)
|
|
15
17
|
|
|
@@ -12,11 +12,11 @@ class TestMethodParameterVariable < Test::Unit::TestCase
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def test_initialize
|
|
15
|
-
assert_nothing_raised(){MethodParameter.new
|
|
15
|
+
assert_nothing_raised(){MethodParameter.new}
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def test_initialize_variable_id_is_created
|
|
19
|
-
assert(MethodParameter.new
|
|
19
|
+
assert(MethodParameter.new.variable_id.kind_of?(Fixnum))
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
end
|