rubyx/test/fragments/test_while_fibo.rb

44 lines
1.3 KiB
Ruby
Raw Normal View History

require_relative 'helper'
class TestWhileFragment < MiniTest::Test
include Fragments
def test_while_fibo
@string_input = <<HERE
2015-09-20 16:52:26 +03:00
int fibonaccit(int n)
int a = 0
int b = 1
while( n > 1 )
int tmp = a
a = b
b = tmp + b
n = n - 1
end
2014-06-07 23:22:32 +03:00
b.putint()
return b
2015-09-20 16:52:26 +03:00
end
2014-06-07 23:22:32 +03:00
fibonaccit( 10 )
HERE
2015-07-19 13:31:13 +03:00
@expect = [Virtual::Return ]
check
end
2014-06-05 16:27:25 +03:00
# a hand coded version of the fibonachi numbers (moved to kernel to be able to call it)
# not my hand off course, found in the net from a basic introduction
2015-07-19 13:31:13 +03:00
def ttest_kernel_fibo
int = Register::Integer.new(Virtual::RegisterMachine.instance.receiver_register)
2015-05-16 12:54:11 +03:00
fibo = @object_space.get_class_by_name(:Object).resolve_method(:fibo)
main = @object_space.main
main.mov int , 10
main.call( fibo )
main.mov( Virtual::RegisterMachine.instance.receiver_register , Virtual::RegisterMachine.instance.return_register )
2015-05-16 12:54:11 +03:00
putint = @object_space.get_class_by_name(:Object).resolve_method(:putint)
main.call( putint )
@should = [0x0,0x40,0x2d,0xe9,0x1,0x0,0x52,0xe3,0x2,0x0,0xa0,0xd1,0x7,0x0,0x0,0xda,0x1,0x30,0xa0,0xe3,0x0,0x40,0xa0,0xe3,0x4,0x30,0x83,0xe0,0x4,0x40,0x43,0xe0,0x1,0x20,0x42,0xe2,0x1,0x0,0x52,0xe3,0xfa,0xff,0xff,0x1a,0x3,0x0,0xa0,0xe1,0x0,0x80,0xbd,0xe8]
2014-06-05 16:27:25 +03:00
@target = [:Object , :fibo]
write "fibo"
end
end