move the methods test to mains

previous commit made the mains tests more general
this joins methods tests here
so we can run them on arm too
fix #11
This commit is contained in:
Torsten Ruger 2018-08-18 20:06:15 +03:00
parent 80264c5322
commit 5b2c7745fe
13 changed files with 78 additions and 118 deletions

View File

@ -0,0 +1,9 @@
class Space
def same( n )
return n
end
def main(arg)
a = same(8 - 1)
return a
end
end

View File

@ -0,0 +1,13 @@
class Space
def if_small( n )
if( n < 10)
return 10
else
"large".putstring
return 20
end
end
def main(arg)
return if_small( 12 )
end
end

View File

@ -0,0 +1,13 @@
class Space
def if_small( n )
if( n < 10)
"small".putstring
return 10
else
return 20
end
end
def main(arg)
return if_small( 8 )
end
end

View File

@ -0,0 +1,10 @@
class Space
def same( n )
return n
end
def main(arg)
return same(8)
end
end

View File

@ -0,0 +1,16 @@
class Space
def down( n )
if( n < 2 )
return n
else
a = down(n - 1)
return a
end
end
def main(arg)
return down(10)
end
end

View File

@ -0,0 +1,16 @@
class Space
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(5)
end
end

View File

@ -39,7 +39,7 @@ module Mains
def compile(input , file , scp) def compile(input , file , scp)
Risc.boot! Risc.boot!
puts "Compiling test/#{file}.o" if DEBUG puts "Compiling test/#{file}.o" if DEBUG
RubyX::RubyXCompiler.ruby_to_binary( "class Space;def main(arg);#{input};end;end" ) RubyX::RubyXCompiler.ruby_to_binary( input )
writer = Elf::ObjectWriter.new(Risc.machine) writer = Elf::ObjectWriter.new(Risc.machine)
writer.save "test/#{file}.o" writer.save "test/#{file}.o"
object_file = "/tmp/#{file}.o" object_file = "/tmp/#{file}.o"

View File

@ -1,5 +0,0 @@
# Method Testing
Test the calling of several methods (including Builtin)
All in one class though. Using the Interpreter.

View File

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

View File

@ -1,30 +0,0 @@
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 10 , get_return
end
def test_call_lg
run_space if_cond(18)
assert_equal 20 , get_return
end
end
end

View File

@ -1,43 +0,0 @@
require_relative 'helper'
module Methods
class TestFibo < MethodsTest
def test_count_down
run_space <<HERE
def down( n )
if( n < 2 )
return n
else
a = down(n - 1)
return a
end
end
def main(arg)
return down(8)
end
HERE
assert_equal 1 , get_return
end
def test_fibo
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(6)
end
HERE
assert_equal 8 , get_return
end
end
end

View File

@ -1,31 +0,0 @@
require_relative 'helper'
module Methods
class TestCallSimple < MethodsTest
def test_simple
run_space <<HERE
def same( n )
return n
end
def main(arg)
return same(8)
end
HERE
assert_equal 8 , get_return
end
def test_call_with_call
run_space <<HERE
def same( n )
return n
end
def main(arg)
a = same(8 - 1)
return a
end
HERE
assert_equal 7 , get_return
end
end
end