fixed fragment tests
This commit is contained in:
parent
638c367e00
commit
49b25ad971
@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
require_relative "test_if"
|
require_relative "test_if"
|
||||||
#require_relative "test_foo"
|
|
||||||
#require_relative "test_hello"
|
|
||||||
require_relative "test_class"
|
require_relative "test_class"
|
||||||
#require_relative "test_putint"
|
require_relative "test_foo"
|
||||||
#require_relative "test_functions"
|
require_relative "test_functions"
|
||||||
#require_relative "test_recursive_fibo"
|
require_relative "test_hello"
|
||||||
|
require_relative "test_if"
|
||||||
|
require_relative "test_putint"
|
||||||
|
require_relative "test_recursive_fibo"
|
||||||
#require_relative "test_while_fibo"
|
#require_relative "test_while_fibo"
|
||||||
|
@ -16,8 +16,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [ [SaveReturn,Register::GetSlot,Register::Set,Register::Set,
|
@length = 36
|
||||||
Register::Set,Register::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,36 +7,28 @@ class TestFunctions < MiniTest::Test
|
|||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
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)
|
int times(int a, int b)
|
||||||
if( b == 0 )
|
if_zero( b )
|
||||||
a = 0
|
a = 0
|
||||||
else
|
else
|
||||||
int m = minus(b, 1)
|
int m = b - 1
|
||||||
int t = times(a, m)
|
int t = times(a, m)
|
||||||
a = plus(a,t)
|
a = a + t
|
||||||
end
|
end
|
||||||
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
int t_seven()
|
int t_seven()
|
||||||
int tim = times(7,6)
|
int tim = times(5,3)
|
||||||
tim.putint()
|
tim.putint()
|
||||||
end
|
end
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
t_seven()
|
return t_seven()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[SaveReturn,Register::GetSlot,Register::Set,Register::Set,RegisterTransfer,FunctionCall] ,
|
@length = 179
|
||||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
|
||||||
check
|
check
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -11,8 +11,8 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[SaveReturn,Register::Set,Register::GetSlot,Register::Set,
|
@length = 35
|
||||||
Register::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn]]
|
@stdout = "Hello Raisa, I am salama"
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,8 +16,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [ [SaveReturn,Register::Set,Register::GetSlot,Register::Set,
|
@length = 30
|
||||||
Register::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,15 +7,15 @@ class TestRecursinveFibo < MiniTest::Test
|
|||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int fibonaccir( int n )
|
int fibonaccir( int n )
|
||||||
if( n <= 1 )
|
if_plus( n - 1 )
|
||||||
return n
|
|
||||||
else
|
|
||||||
int tmp
|
int tmp
|
||||||
tmp = n - 1
|
tmp = n - 1
|
||||||
int a = fibonaccir( tmp )
|
int a = fibonaccir( tmp )
|
||||||
tmp = n - 2
|
tmp = n - 2
|
||||||
int b = fibonaccir( tmp )
|
int b = fibonaccir( tmp )
|
||||||
return a + b
|
return a + b
|
||||||
|
else
|
||||||
|
return n
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
int fib_print(int n)
|
int fib_print(int n)
|
||||||
@ -27,8 +27,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[SaveReturn,Register::GetSlot,Register::Set,Register::Set,
|
@length = 71
|
||||||
Register::Set,Register::Set,RegisterTransfer,FunctionCall] , [RegisterTransfer,GetSlot,FunctionReturn]]
|
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,16 +7,16 @@ class TestWhileFragment < MiniTest::Test
|
|||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
class Object
|
class Object
|
||||||
int fibonaccit(int n)
|
int fibonaccit(int n)
|
||||||
int a = 0
|
int a = 0
|
||||||
int b = 1
|
int b = 1
|
||||||
while( n > 1 )
|
while_plus( n )
|
||||||
int tmp = a
|
int tmp = a
|
||||||
a = b
|
a = b
|
||||||
b = tmp + b
|
b = tmp + b
|
||||||
n = n - 1
|
n = n - 1
|
||||||
end
|
end
|
||||||
b.putint()
|
b.putint()
|
||||||
return b
|
return b
|
||||||
end
|
end
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -24,25 +24,8 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [ [SaveReturn,Register::GetSlot,Register::Set,Register::Set,
|
@length = 5
|
||||||
Register::Set,Register::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
|
||||||
check
|
check
|
||||||
end
|
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
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
|
|
||||||
module Register
|
module Register
|
||||||
class TestBasicClass < MiniTest::Test
|
class TestClassStatements < MiniTest::Test
|
||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def test_class_def
|
def test_class_def
|
||||||
@ -34,7 +34,6 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@length = 30
|
|
||||||
@expect = [Label, SaveReturn,GetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,
|
@expect = [Label, SaveReturn,GetSlot,LoadConstant,SetSlot,LoadConstant,SetSlot,
|
||||||
RegisterTransfer,FunctionCall,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
RegisterTransfer,FunctionCall,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||||
check
|
check
|
||||||
@ -62,7 +61,6 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@length = 17
|
|
||||||
@expect = [Label, SaveReturn,GetSlot,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
@expect = [Label, SaveReturn,GetSlot,GetSlot,Label,RegisterTransfer,GetSlot,FunctionReturn]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user