add some multi method tests

This commit is contained in:
Torsten Ruger 2018-04-26 12:33:33 +03:00
parent a8e7602193
commit 26fe77ed68
5 changed files with 93 additions and 1 deletions

View File

@ -0,0 +1,8 @@
require_relative '../helper'
module Methods
class MethodsTest < MiniTest::Test
include Risc::Ticker
def setup;end
end
end

View File

@ -0,0 +1,32 @@
require_relative 'helper'
module Methods
class TestCallCond < MethodsTest
def if_cond( arg )
str = <<HERE
def called( n )
if( n < 10)
return 10
else
return 20
end
end
def main(arg)
return called( ARG )
end
HERE
str.sub("ARG" , arg.to_s)
end
def test_call_sm
run_space if_cond(8)
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
end
def test_call_lg
run_space if_cond(18)
assert_equal Parfait::Integer , get_return.class
assert_equal 20 , get_return.value
end
end
end

View File

@ -0,0 +1,26 @@
require_relative 'helper'
module Methods
class TestFibo < MethodsTest
def est_ruby_adds
run_space <<HERE
def fibo_r( n )
if( n < 2 )
return n
else
a = fibo_r(n - 1)
b = fibo_r(n - 2)
return a + b
end
end
def main(arg)
return fibo_r(8)
end
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 8 , get_return.value
end
end
end

View File

@ -0,0 +1,19 @@
require_relative 'helper'
module Methods
class TestCallSimple < MethodsTest
def test_call
run_space <<HERE
def called( n )
return n
end
def main(arg)
return called(8)
end
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 8 , get_return.value
end
end
end

View File

@ -79,12 +79,19 @@ module Risc
classes
end
# do the setup, compile and run the input to the end
# do the setup, compile and run the input (a main) to the end
def run_main(input)
@string_input = as_main(input)
do_setup
run_all
end
# wrap the input in Space (main is assumed to be part of it)
def run_space(input)
@string_input = in_Space(input)
do_setup
run_all
end
def run_all
@interpreter.tick while(@interpreter.instruction)
end