diff --git a/test/risc/mains/README.md b/test/mains/README.md similarity index 100% rename from test/risc/mains/README.md rename to test/mains/README.md diff --git a/test/mains/adds.rb b/test/mains/adds.rb new file mode 100644 index 00000000..c65f5cca --- /dev/null +++ b/test/mains/adds.rb @@ -0,0 +1,7 @@ +a = 0 +b = 20 +while( a < b ) + a = a + 1 + b = b - 1 +end +return a diff --git a/test/mains/fibo.rb b/test/mains/fibo.rb new file mode 100644 index 00000000..ba5f94ae --- /dev/null +++ b/test/mains/fibo.rb @@ -0,0 +1,11 @@ +n = 6 +a = 0 +b = 1 +i = 1 +while( i < n ) + result = a + b + a = b + b = result + i = i + 1 +end +return result diff --git a/test/risc/mains/helper.rb b/test/mains/helper.rb similarity index 54% rename from test/risc/mains/helper.rb rename to test/mains/helper.rb index 5578e9c7..024f30fc 100644 --- a/test/risc/mains/helper.rb +++ b/test/mains/helper.rb @@ -4,5 +4,10 @@ module Mains class MainsTest < MiniTest::Test include Risc::Ticker def setup;end + + def run_main_file(file) + input = File.read("test/mains/#{file}.rb") + run_main(input) + end end end diff --git a/test/mains/subs.rb b/test/mains/subs.rb new file mode 100644 index 00000000..65b3cf5f --- /dev/null +++ b/test/mains/subs.rb @@ -0,0 +1,5 @@ +b = 10 +while( b >= 1 ) + b = b - 1 +end +return b diff --git a/test/mains/test_adds.rb b/test/mains/test_adds.rb new file mode 100644 index 00000000..4470b088 --- /dev/null +++ b/test/mains/test_adds.rb @@ -0,0 +1,19 @@ +require_relative 'helper' + +module Mains + class TestAdds < MainsTest + + def test_ruby_adds + run_main_file "adds" + assert_equal 10 , get_return + end + def test_ruby_subs + run_main_file "subs" + assert_equal 0 , get_return + end + def test_ruby_adds_fibo + run_main_file "fibo" + assert_equal 8 , get_return + end + end +end diff --git a/test/risc/mains/test_puts.rb b/test/mains/test_puts.rb similarity index 100% rename from test/risc/mains/test_puts.rb rename to test/mains/test_puts.rb diff --git a/test/risc/mains/test_adds.rb b/test/risc/mains/test_adds.rb deleted file mode 100644 index 4c9ad3ee..00000000 --- a/test/risc/mains/test_adds.rb +++ /dev/null @@ -1,45 +0,0 @@ -require_relative 'helper' - -module Mains - class TestAdds < MainsTest - - def test_ruby_adds - run_main <= 1 ) - b = b - 1 - end - return b -HERE - assert_equal 0 , get_return - end - def test_ruby_adds_fibo - run_main <