From ee28d1242919a2758af0d8dd77fb055827f6e9c9 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 24 Apr 2018 19:57:14 +0300 Subject: [PATCH] bit more comparison testing --- .../conditional/test_if_greater_or.rb | 36 +++++++++++ .../conditional/test_if_smaller_or.rb | 36 +++++++++++ test/risc/interpreter/while/test_while_cmp.rb | 59 +++++++++++++++++++ test/risc/mains/test_adds.rb | 8 +-- 4 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 test/risc/interpreter/conditional/test_if_greater_or.rb create mode 100644 test/risc/interpreter/conditional/test_if_smaller_or.rb create mode 100644 test/risc/interpreter/while/test_while_cmp.rb diff --git a/test/risc/interpreter/conditional/test_if_greater_or.rb b/test/risc/interpreter/conditional/test_if_greater_or.rb new file mode 100644 index 00000000..b2e4a032 --- /dev/null +++ b/test/risc/interpreter/conditional/test_if_greater_or.rb @@ -0,0 +1,36 @@ +require_relative "../helper" + +module Risc + class InterpreterIfGreaterOr < MiniTest::Test + include Ticker + + def setup + @string_input = as_main 'if( 5 >= 5 ); return "then";else;return "else";end' + super + end + + def test_if + #show_main_ticks # get output of what is in main + check_main_chain [Label, LoadConstant, LoadConstant, SlotToReg, RegToSlot, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg, + RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, + RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label, + SlotToReg, SlotToReg, SlotToReg, SlotToReg, SlotToReg, + OperatorInstruction, IsMinus, LoadConstant, Branch, Label, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, + LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, FunctionReturn, Transfer, Syscall, NilClass] + assert_equal Parfait::Word , get_return.class + assert_equal "then" , get_return.to_string + end + def test_exit + done = main_ticks(69) + assert_equal Syscall , done.class + end + end +end diff --git a/test/risc/interpreter/conditional/test_if_smaller_or.rb b/test/risc/interpreter/conditional/test_if_smaller_or.rb new file mode 100644 index 00000000..62b429a3 --- /dev/null +++ b/test/risc/interpreter/conditional/test_if_smaller_or.rb @@ -0,0 +1,36 @@ +require_relative "../helper" + +module Risc + class InterpreterIfSmallerOr < MiniTest::Test + include Ticker + + def setup + @string_input = as_main 'if( 5 <= 5 ); return "then";else;return "else";end' + super + end + + def test_if + #show_main_ticks # get output of what is in main + check_main_chain [Label, LoadConstant, LoadConstant, SlotToReg, RegToSlot, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg, + RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, + RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label, + SlotToReg, SlotToReg, SlotToReg, SlotToReg, SlotToReg, + OperatorInstruction, IsMinus, LoadConstant, Branch, Label, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, + LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, FunctionReturn, Transfer, Syscall, NilClass] + assert_equal Parfait::Word , get_return.class + assert_equal "then" , get_return.to_string + end + def test_exit + done = main_ticks(69) + assert_equal Syscall , done.class + end + end +end diff --git a/test/risc/interpreter/while/test_while_cmp.rb b/test/risc/interpreter/while/test_while_cmp.rb new file mode 100644 index 00000000..c3379762 --- /dev/null +++ b/test/risc/interpreter/while/test_while_cmp.rb @@ -0,0 +1,59 @@ +require_relative "../helper" + +module Risc + class InterpreterWhileCmp < MiniTest::Test + include Ticker + + def setup + @string_input = as_main 'a = 0; while( 0 >= a); a = 1 + a;end;return a' + super + end + + def test_if + #show_main_ticks # get output of what is in main + check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, Label, + LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot, + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, + RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot, + LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, + SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, + RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label, + SlotToReg, SlotToReg, SlotToReg, SlotToReg, SlotToReg, + OperatorInstruction, IsMinus, LoadConstant, Branch, Label, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, + LoadConstant, OperatorInstruction, IsZero, LoadConstant, LoadConstant, + SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + RegToSlot, SlotToReg, RegToSlot, LoadConstant, SlotToReg, + RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg, + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, + LoadConstant, FunctionCall, Label, SlotToReg, SlotToReg, + SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, LoadConstant, + SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, + FunctionReturn, SlotToReg, SlotToReg, RegToSlot, Branch, + Label, LoadConstant, LoadConstant, SlotToReg, RegToSlot, + RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg, + RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, + SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, + SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall, + Label, SlotToReg, SlotToReg, SlotToReg, SlotToReg, + SlotToReg, OperatorInstruction, IsMinus, Label, LoadConstant, + Label, RegToSlot, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, + RegToSlot, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, + IsZero, Label, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, + FunctionReturn, Transfer, Syscall, NilClass] + assert_kind_of Parfait::Integer , get_return + assert_equal 1 , get_return.value + end + def test_exit + done = main_ticks(183) + assert_equal Syscall , done.class + end + end +end diff --git a/test/risc/mains/test_adds.rb b/test/risc/mains/test_adds.rb index 5f2b2b63..e2152b39 100644 --- a/test/risc/mains/test_adds.rb +++ b/test/risc/mains/test_adds.rb @@ -18,10 +18,10 @@ HERE assert_equal Parfait::Integer , get_return.class assert_equal 10 , get_return.value end - def pest_ruby_subs + def test_ruby_subs run_input < 0 ) + while( b >= 1 ) b = b - 1 end return b @@ -31,7 +31,7 @@ HERE end def test_ruby_adds_fibo run_input <