improve method test
mostly by actually testing main, which is what is checked
This commit is contained in:
parent
cd96e78e2d
commit
c1d31a541d
@ -5,39 +5,29 @@ module Virtual
|
||||
class TestMethods < MiniTest::Test
|
||||
include CodeChecker
|
||||
|
||||
def test_module
|
||||
def test_simplest_function
|
||||
@string_input = <<HERE
|
||||
class Some
|
||||
int foo()
|
||||
class Object
|
||||
int main()
|
||||
return 5
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@output = [[MethodEnter] ,[MethodReturn]]
|
||||
@output = [[MethodEnter,Set] ,[MethodReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
def test_simplest_function
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int foo(int x)
|
||||
return x
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@output = [[MethodEnter] ,[MethodReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
def test_second_simplest_function
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
ref foo(ref x)
|
||||
int main()
|
||||
int x = 5
|
||||
return x
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
||||
@output = [[Virtual::MethodEnter,Set],[Virtual::MethodReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -86,16 +76,17 @@ HERE
|
||||
def test_function_if
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int ofthen(int n)
|
||||
int main()
|
||||
if(0)
|
||||
int isit = 42
|
||||
return 42
|
||||
else
|
||||
int maybenot = 667
|
||||
return 667
|
||||
end
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@output = [[Virtual::MethodEnter] , [Virtual::MethodReturn]]
|
||||
@output = [[MethodEnter,Set,Register::IsZeroBranch] , [Set,Register::AlwaysBranch],
|
||||
[Set],[],[MethodReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
@ -145,7 +136,8 @@ HERE
|
||||
def test_function_return_if
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int retvar(int n)
|
||||
int main()
|
||||
int n = 10
|
||||
if( n > 5)
|
||||
return 10
|
||||
else
|
||||
@ -154,45 +146,29 @@ class Object
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
||||
@output = [[MethodEnter,Set,Set,Register::GetSlot,Register::GetSlot,
|
||||
Register::OperatorInstruction,Register::IsZeroBranch],
|
||||
[Set,Register::AlwaysBranch],[Set],[],[MethodReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
def test_function_return_while
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int retvar(int n)
|
||||
while( n > 5) do
|
||||
int main()
|
||||
int n = 10
|
||||
while( n > 5)
|
||||
n = n + 1
|
||||
return n
|
||||
end
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
def test_function_big_while
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int puts(int i)
|
||||
return 0
|
||||
end
|
||||
int fibonaccit(int n)
|
||||
int a = 0
|
||||
int b = 1
|
||||
while( n > 1 )
|
||||
int tmp = a
|
||||
a = b
|
||||
b = tmp + b
|
||||
puts(b)
|
||||
n = n - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@output = [[Virtual::MethodEnter],[Virtual::MethodReturn]]
|
||||
@output = [[MethodEnter,Set],
|
||||
[Set,Register::GetSlot,Register::GetSlot,Register::OperatorInstruction,
|
||||
Register::IsZeroBranch,Set,Register::GetSlot,Register::GetSlot,
|
||||
Register::OperatorInstruction,Set,Register::AlwaysBranch] ,
|
||||
[],[MethodReturn]]
|
||||
check
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user