start larger tests

This commit is contained in:
Torsten Ruger 2018-04-23 14:05:37 +03:00
parent 1907574c60
commit ef5854c4df
4 changed files with 71 additions and 43 deletions

View File

@ -1,26 +0,0 @@
#require_relative 'helper'
module Rubyx
class TestRubyAdds < MiniTest::Test
# include RubyxTests
def pest_ruby_adds
@string_input = <<HERE
def fibo( n)
a = 0
b = 1
i = 1
while( i < n ) do
result = a + b
a = b
b = result
i+= 1
end
return result
end
HERE
@stdout = "Hello there"
check
end
end
end

View File

@ -5,52 +5,52 @@ module Risc
class SimpleInt < BuiltinTest
def test_add
run_all "5 + 5"
run_input "5 + 5"
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
end
def test_minus
run_all "5 - 5"
run_input "5 - 5"
assert_equal 0 , get_return.value
end
def test_minus_neg
run_all "5 - 15"
run_input "5 - 15"
assert_equal -10 , get_return.value
end
def test_rshift
run_all "#{2**8} >> 3"
run_input "#{2**8} >> 3"
assert_equal 2**5 , get_return.value
end
def test_lshift
run_all "#{2**8} << 3"
run_input "#{2**8} << 3"
assert_equal 2**11 , get_return.value
end
def test_div10
run_all "45.div10"
run_input "45.div10"
assert_equal 4 , get_return.value
end
def test_div4
run_all "45.div4"
run_input "45.div4"
assert_equal 11 , get_return.value
end
def test_mult
run_all "4 * 4"
run_input "4 * 4"
assert_equal 16 , get_return.value
end
def test_smaller_true
run_all "4 < 5"
run_input "4 < 5"
assert_equal Parfait::TrueClass , get_return.class
end
def test_smaller_false
run_all "6 < 5"
run_input "6 < 5"
assert_equal Parfait::FalseClass , get_return.class
end
def test_larger_true
run_all "5 > 4"
run_input "5 > 4"
assert_equal Parfait::TrueClass , get_return.class
end
def test_larger_false
run_all "5 > 6"
run_input "5 > 6"
assert_equal Parfait::FalseClass , get_return.class
end
end

View File

@ -0,0 +1,50 @@
require_relative '../helper'
module Mains
class TestLargerWhile < MiniTest::Test
include Risc::Ticker
def setup;end
def test_ruby_adds
run_input <<HERE
a = 0
b = 20
while( a < b )
a = a + 1
b = b - 1
end
return a
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 10 , get_return.value
end
def pest_ruby_subs
run_input <<HERE
b = 10
while( b > 0 )
b = b - 1
end
return b
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 0 , get_return.value
end
def test_ruby_adds_fibo
run_input <<HERE
n=12
a = 0
b = 1
i = 1
while( i < n )
result = a + b
a = b
b = result
i = i + 1
end
return result
HERE
assert_equal Parfait::Integer , get_return.class
assert_equal 144 , get_return.value
end
end
end

View File

@ -61,11 +61,11 @@ module Risc
end
# collect the classes of all executed istructions
def all_classes
def all_classes(max = 300)
classes = []
tick = 1
begin
while true and (classes.length < 300)
while true and (classes.length < max)
cl = ticks(1).class
tick += 1
classes << cl
@ -80,11 +80,15 @@ module Risc
end
# do the setup, compile and run the input to the end
def run_all(input)
def run_input(input)
@string_input = as_main(input)
do_setup
all_classes
run_all
end
def run_all
@interpreter.tick while(@interpreter.instruction)
end
# for chaning the tests quickly output all instructions that are executed
def show_ticks
classes = all_classes