fixed fragment tests

This commit is contained in:
Torsten Ruger 2015-10-27 11:00:48 +02:00
parent 638c367e00
commit 49b25ad971
8 changed files with 33 additions and 62 deletions

View File

@ -1,9 +1,10 @@
require_relative "test_if"
#require_relative "test_foo"
#require_relative "test_hello"
require_relative "test_class"
#require_relative "test_putint"
#require_relative "test_functions"
#require_relative "test_recursive_fibo"
require_relative "test_foo"
require_relative "test_functions"
require_relative "test_hello"
require_relative "test_if"
require_relative "test_putint"
require_relative "test_recursive_fibo"
#require_relative "test_while_fibo"

View File

@ -16,8 +16,7 @@ class Object
end
end
HERE
@expect = [ [SaveReturn,Register::GetSlot,Register::Set,Register::Set,
Register::Set,Register::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
@length = 36
check
end

View File

@ -7,36 +7,28 @@ class TestFunctions < MiniTest::Test
@string_input = <<HERE
class Object
int minus(int a,int b)
return a - b
end
int plus(int a, int b)
return a + b
end
int times(int a, int b)
if( b == 0 )
if_zero( b )
a = 0
else
int m = minus(b, 1)
int m = b - 1
int t = times(a, m)
a = plus(a,t)
a = a + t
end
return a
end
int t_seven()
int tim = times(7,6)
int tim = times(5,3)
tim.putint()
end
int main()
t_seven()
return t_seven()
end
end
HERE
@expect = [[SaveReturn,Register::GetSlot,Register::Set,Register::Set,RegisterTransfer,FunctionCall] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
@length = 179
check
end

View File

@ -11,8 +11,8 @@ class Object
end
end
HERE
@expect = [[SaveReturn,Register::Set,Register::GetSlot,Register::Set,
Register::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn]]
@length = 35
@stdout = "Hello Raisa, I am salama"
check
end
end

View File

@ -16,8 +16,7 @@ class Object
end
end
HERE
@expect = [ [SaveReturn,Register::Set,Register::GetSlot,Register::Set,
Register::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
@length = 30
check
end
end

View File

@ -7,15 +7,15 @@ class TestRecursinveFibo < MiniTest::Test
@string_input = <<HERE
class Object
int fibonaccir( int n )
if( n <= 1 )
return n
else
if_plus( n - 1 )
int tmp
tmp = n - 1
int a = fibonaccir( tmp )
tmp = n - 2
int b = fibonaccir( tmp )
return a + b
else
return n
end
end
int fib_print(int n)
@ -27,8 +27,7 @@ class Object
end
end
HERE
@expect = [[SaveReturn,Register::GetSlot,Register::Set,Register::Set,
Register::Set,Register::Set,RegisterTransfer,FunctionCall] , [RegisterTransfer,GetSlot,FunctionReturn]]
@length = 71
check
end
end

View File

@ -7,16 +7,16 @@ class TestWhileFragment < MiniTest::Test
@string_input = <<HERE
class Object
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
b.putint()
return b
int a = 0
int b = 1
while_plus( n )
int tmp = a
a = b
b = tmp + b
n = n - 1
end
b.putint()
return b
end
int main()
@ -24,25 +24,8 @@ class Object
end
end
HERE
@expect = [ [SaveReturn,Register::GetSlot,Register::Set,Register::Set,
Register::Set,Register::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
@length = 5
check
end
# 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
def ttest_kernel_fibo
int = Register::Integer.new(Register::RegisterMachine.instance.receiver_register)
fibo = @object_space.get_class_by_name(:Object).resolve_method(:fibo)
main = @object_space.main
main.mov int , 10
main.call( fibo )
main.mov( Register::RegisterMachine.instance.receiver_register , Register::RegisterMachine.instance.return_register )
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]
@target = [:Object , :fibo]
write "fibo"
end
end

View File

@ -1,7 +1,7 @@
require_relative 'helper'
module Register
class TestBasicClass < MiniTest::Test
class TestClassStatements < MiniTest::Test
include Statements
def test_class_def
@ -34,7 +34,6 @@ class Object
end
end
HERE
@length = 30
@expect = [Label, SaveReturn,GetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,
RegisterTransfer,FunctionCall,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
@ -62,7 +61,6 @@ class Object
end
end
HERE
@length = 17
@expect = [Label, SaveReturn,GetSlot,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
check
end