From 5b2c7745fe62ec89637912e59f229eed213c8067 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 18 Aug 2018 20:06:15 +0300 Subject: [PATCH] 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 --- test/mains/source/call-call__7.rb | 9 ++++ test/mains/source/if-false_large_20.rb | 13 ++++++ test/mains/source/if-true_small_10.rb | 13 ++++++ test/mains/source/one-call__8.rb | 10 +++++ test/mains/source/recurse-count__1.rb | 16 +++++++ test/mains/source/recurse-fibo__5.rb | 16 +++++++ test/mains/source/{subs__0.rb => while__0.rb} | 0 test/mains/test_arm.rb | 2 +- test/risc/methods/README.md | 5 --- test/risc/methods/helper.rb | 8 ---- test/risc/methods/test_call_cond.rb | 30 ------------- test/risc/methods/test_call_fibo.rb | 43 ------------------- test/risc/methods/test_call_simple.rb | 31 ------------- 13 files changed, 78 insertions(+), 118 deletions(-) create mode 100644 test/mains/source/call-call__7.rb create mode 100644 test/mains/source/if-false_large_20.rb create mode 100644 test/mains/source/if-true_small_10.rb create mode 100644 test/mains/source/one-call__8.rb create mode 100644 test/mains/source/recurse-count__1.rb create mode 100644 test/mains/source/recurse-fibo__5.rb rename test/mains/source/{subs__0.rb => while__0.rb} (100%) delete mode 100644 test/risc/methods/README.md delete mode 100644 test/risc/methods/helper.rb delete mode 100644 test/risc/methods/test_call_cond.rb delete mode 100644 test/risc/methods/test_call_fibo.rb delete mode 100644 test/risc/methods/test_call_simple.rb diff --git a/test/mains/source/call-call__7.rb b/test/mains/source/call-call__7.rb new file mode 100644 index 00000000..644fd894 --- /dev/null +++ b/test/mains/source/call-call__7.rb @@ -0,0 +1,9 @@ +class Space + def same( n ) + return n + end + def main(arg) + a = same(8 - 1) + return a + end +end diff --git a/test/mains/source/if-false_large_20.rb b/test/mains/source/if-false_large_20.rb new file mode 100644 index 00000000..ff6fcea4 --- /dev/null +++ b/test/mains/source/if-false_large_20.rb @@ -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 diff --git a/test/mains/source/if-true_small_10.rb b/test/mains/source/if-true_small_10.rb new file mode 100644 index 00000000..fea1607b --- /dev/null +++ b/test/mains/source/if-true_small_10.rb @@ -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 diff --git a/test/mains/source/one-call__8.rb b/test/mains/source/one-call__8.rb new file mode 100644 index 00000000..6bb9bead --- /dev/null +++ b/test/mains/source/one-call__8.rb @@ -0,0 +1,10 @@ +class Space + + def same( n ) + return n + end + def main(arg) + return same(8) + end + +end diff --git a/test/mains/source/recurse-count__1.rb b/test/mains/source/recurse-count__1.rb new file mode 100644 index 00000000..24f977b1 --- /dev/null +++ b/test/mains/source/recurse-count__1.rb @@ -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 diff --git a/test/mains/source/recurse-fibo__5.rb b/test/mains/source/recurse-fibo__5.rb new file mode 100644 index 00000000..cbcab0f4 --- /dev/null +++ b/test/mains/source/recurse-fibo__5.rb @@ -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 diff --git a/test/mains/source/subs__0.rb b/test/mains/source/while__0.rb similarity index 100% rename from test/mains/source/subs__0.rb rename to test/mains/source/while__0.rb diff --git a/test/mains/test_arm.rb b/test/mains/test_arm.rb index 2e857fcb..d72ace61 100644 --- a/test/mains/test_arm.rb +++ b/test/mains/test_arm.rb @@ -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" diff --git a/test/risc/methods/README.md b/test/risc/methods/README.md deleted file mode 100644 index 1a1d3b4c..00000000 --- a/test/risc/methods/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Method Testing - -Test the calling of several methods (including Builtin) - -All in one class though. Using the Interpreter. diff --git a/test/risc/methods/helper.rb b/test/risc/methods/helper.rb deleted file mode 100644 index 918f88d4..00000000 --- a/test/risc/methods/helper.rb +++ /dev/null @@ -1,8 +0,0 @@ -require_relative '../helper' - -module Methods - class MethodsTest < MiniTest::Test - include Risc::Ticker - def setup;end - end -end diff --git a/test/risc/methods/test_call_cond.rb b/test/risc/methods/test_call_cond.rb deleted file mode 100644 index 55ec8f20..00000000 --- a/test/risc/methods/test_call_cond.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative 'helper' - -module Methods - class TestCallCond < MethodsTest - - def if_cond( arg ) - str = <