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:
parent
80264c5322
commit
5b2c7745fe
9
test/mains/source/call-call__7.rb
Normal file
9
test/mains/source/call-call__7.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class Space
|
||||
def same( n )
|
||||
return n
|
||||
end
|
||||
def main(arg)
|
||||
a = same(8 - 1)
|
||||
return a
|
||||
end
|
||||
end
|
13
test/mains/source/if-false_large_20.rb
Normal file
13
test/mains/source/if-false_large_20.rb
Normal 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
|
13
test/mains/source/if-true_small_10.rb
Normal file
13
test/mains/source/if-true_small_10.rb
Normal 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
|
10
test/mains/source/one-call__8.rb
Normal file
10
test/mains/source/one-call__8.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class Space
|
||||
|
||||
def same( n )
|
||||
return n
|
||||
end
|
||||
def main(arg)
|
||||
return same(8)
|
||||
end
|
||||
|
||||
end
|
16
test/mains/source/recurse-count__1.rb
Normal file
16
test/mains/source/recurse-count__1.rb
Normal 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
|
16
test/mains/source/recurse-fibo__5.rb
Normal file
16
test/mains/source/recurse-fibo__5.rb
Normal 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
|
@ -39,7 +39,7 @@ module Mains
|
||||
def compile(input , file , scp)
|
||||
Risc.boot!
|
||||
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.save "test/#{file}.o"
|
||||
object_file = "/tmp/#{file}.o"
|
||||
|
@ -1,5 +0,0 @@
|
||||
# Method Testing
|
||||
|
||||
Test the calling of several methods (including Builtin)
|
||||
|
||||
All in one class though. Using the Interpreter.
|
@ -1,8 +0,0 @@
|
||||
require_relative '../helper'
|
||||
|
||||
module Methods
|
||||
class MethodsTest < MiniTest::Test
|
||||
include Risc::Ticker
|
||||
def setup;end
|
||||
end
|
||||
end
|
@ -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
|
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user