test other int methods

harness for testing compiler in a method (before just in a case)
This commit is contained in:
Torsten Ruger 2018-04-19 19:59:48 +03:00
parent a98d7630fb
commit 7d9132ee36
4 changed files with 42 additions and 22 deletions

View File

@ -5,8 +5,6 @@ module Risc
class BuiltinTest < MiniTest::Test
include Ticker
def setup
@string_input = as_main(main)
super
end
end
end

View File

@ -1,19 +0,0 @@
require_relative "helper"
module Risc
module Builtin
class PlusTest < BuiltinTest
def main
"return 5 + 5"
end
def test_add
#show_main_ticks # get output of what is
run_all
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
end
end
end
end

View File

@ -0,0 +1,34 @@
require_relative "helper"
module Risc
module Builtin
class SimpleInt < BuiltinTest
def test_add
run_all "5 + 5"
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
end
def test_minus
run_all "5 - 5"
assert_equal 0 , get_return.value
end
def test_minus_neg
run_all "5 - 15"
assert_equal -10 , get_return.value
end
def test_div10
run_all "45.div10"
assert_equal 4 , get_return.value
end
def test_div4
run_all "45.div4"
assert_equal 11 , get_return.value
end
def test_mult
run_all "4 * 4"
assert_equal 16 , get_return.value
end
end
end
end

View File

@ -14,6 +14,7 @@ module Risc
@interpreter = Interpreter.new
@interpreter.start Risc.machine.risc_init
end
alias :do_setup :setup
# must be after boot, but before main compile, to define method
def do_clean_compile
@ -77,7 +78,13 @@ module Risc
end
classes
end
alias :run_all :all_classes
# do the setup, compile and run the input to the end
def run_all(input)
@string_input = as_main(input)
do_setup
all_classes
end
# for chaning the tests quickly output all instructions that are executed
def show_ticks
classes = all_classes