add some multi method tests
This commit is contained in:
parent
a8e7602193
commit
26fe77ed68
8
test/risc/methods/helper.rb
Normal file
8
test/risc/methods/helper.rb
Normal file
@ -0,0 +1,8 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module Methods
|
||||
class MethodsTest < MiniTest::Test
|
||||
include Risc::Ticker
|
||||
def setup;end
|
||||
end
|
||||
end
|
32
test/risc/methods/test_call_cond.rb
Normal file
32
test/risc/methods/test_call_cond.rb
Normal 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
|
26
test/risc/methods/test_call_fibo.rb
Normal file
26
test/risc/methods/test_call_fibo.rb
Normal 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
|
19
test/risc/methods/test_call_simple.rb
Normal file
19
test/risc/methods/test_call_simple.rb
Normal 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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user