move parfait tests to some

after renaming compiler to soml
it’s where they wanna be
also will allow for unifying test helpers and testing fragments
remotely too
This commit is contained in:
Torsten Ruger
2015-11-18 12:14:31 +02:00
parent 3efdf420a4
commit 18f9ea019e
33 changed files with 4 additions and 4 deletions

View File

@ -0,0 +1,36 @@
require_relative '../../helper'
require "register/interpreter"
# Fragments are small programs that we run through the interpreter and really only check
# - the no. of instructions processed
# - the stdout output
module Fragments
def setup
@stdout = ""
end
def check
machine = Register.machine.boot
machine.parse_and_compile @string_input
machine.collect
@interpreter = Register::Interpreter.new
@interpreter.start machine.init
count = 0
begin
count += 1
#puts interpreter.instruction
@interpreter.tick
end while( ! @interpreter.instruction.nil?)
assert_equal @length , count
assert_equal @stdout , @interpreter.stdout
end
def check_return val
check
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
assert_equal val , @interpreter.get_register(:r0).return_value
end
end

View File

@ -0,0 +1,11 @@
require_relative "test_if"
require_relative "test_class"
require_relative "test_functions"
require_relative "test_hello"
require_relative "test_if"
require_relative "test_putint"
require_relative "test_recursive_fibo"
require_relative "test_return"
require_relative "test_while_fibo"
require_relative "test_word"

View File

@ -0,0 +1,24 @@
require_relative 'helper'
module Register
class TestBasicClass < MiniTest::Test
include Fragments
def test_class_def
@string_input = <<HERE
class Bar
int buh()
return 1
end
end
class Object
int main()
return 1
end
end
HERE
@length = 15
check
end
end
end

View File

@ -0,0 +1,65 @@
require_relative 'helper'
class TestFunctions < MiniTest::Test
include Fragments
def test_functions
@string_input = <<HERE
class Object
int times(int a, int b)
if_zero( b + 0)
a = 0
else
int m = b - 1
int t = times(a, m)
a = a + t
end
return a
end
int t_seven()
int tim = times(8,10)
tim.putint()
return tim
end
int main()
return t_seven()
end
end
HERE
@length = 505
check_return 80
end
def test_class_method
@string_input = <<HERE
class Object
int self.some()
return 5
end
int main()
return Object.some()
end
end
HERE
@length = 33
check_return 5
end
def test_class_method_fails
@string_input = <<HERE
class Object
int main()
return Object.som()
end
end
HERE
assert_raises {check}
end
end

View File

@ -0,0 +1,18 @@
require_relative 'helper'
class TestHello < MiniTest::Test
include Fragments
def test_hello
@string_input = <<HERE
class Object
int main()
"Hello Raisa, I am salama".putstring()
end
end
HERE
@length = 37
@stdout = "Hello Raisa, I am salama"
check
end
end

View File

@ -0,0 +1,60 @@
require_relative 'helper'
class TestIf < MiniTest::Test
include Fragments
def test_if_plus
@string_input = <<HERE
class Object
int main()
int n = 10
if_plus( n - 12)
return 3
else
return 4
end
end
end
HERE
@length = 25
check_return 4
end
def test_if_zero
@string_input = <<HERE
class Object
int main()
int n = 10
if_zero(n - 10 )
"10".putstring()
end
end
end
HERE
@length = 47
@stdout = "10"
check
end
def test_if_minus
@string_input = <<HERE
class Object
int itest(int n)
if_minus( n - 12)
"then".putstring()
else
"else".putstring()
end
end
int main()
itest(20)
end
end
HERE
@length = 62
@stdout = "else"
check
end
end

View File

@ -0,0 +1,22 @@
require_relative 'helper'
class TestPutint < MiniTest::Test
include Fragments
def test_putint
@string_input = <<HERE
class Integer
int putint()
return 1
end
end
class Object
int main()
42.putint()
end
end
HERE
@length = 32
check
end
end

View File

@ -0,0 +1,34 @@
require_relative 'helper'
class TestRecursinveFibo < MiniTest::Test
include Fragments
def test_recursive_fibo
@string_input = <<HERE
class Object
int fibonaccir( int n )
if_plus( n - 2 )
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)
int fib = fibonaccir( n )
fib.putint()
return fib
end
int main()
return fib_print(8)
end
end
HERE
@length = 2525
check_return 21
end
end

View File

@ -0,0 +1,51 @@
require_relative 'helper'
class TestReturn < MiniTest::Test
include Fragments
def test_return1
@string_input = <<HERE
class Object
int main()
return 5
end
end
HERE
@length = 15
check_return 5
end
def test_return2
@string_input = <<HERE
class Object
int foo(int x)
return x
end
int main()
return foo( 5 )
end
end
HERE
@length = 35
check_return 5
end
def test_return3
@string_input = <<HERE
class Object
int foo(int x)
int a = 5
return a
end
int main()
return foo( 4 )
end
end
HERE
@length = 39
check_return 5
end
end

View File

@ -0,0 +1,44 @@
require_relative 'helper'
class TestWhileFragment < MiniTest::Test
include Fragments
def fibo num
@string_input = <<HERE
class Object
int fibonaccit(int n)
int a = 0
int b = 1
while_plus( n - 2)
n = n - 1
int tmp = a
a = b
b = tmp + b
end
b.putint()
return b
end
int main()
return fibonaccit( 100 )
end
end
HERE
@string_input.sub!( "100" , num.to_s )
end
def test_while_fibo48
fibo 48
@length = 1241
# this is not the correct fibo, just what comes from wrapping (smaller than below)
check_return 512559680
end
# highest 32 bit fibo
def test_while_fibo47
fibo 47
@length = 1216
check_return 2971215073
end
end

View File

@ -0,0 +1,23 @@
require_relative 'helper'
class TestWord < MiniTest::Test
include Fragments
def test_word_new
@string_input = <<HERE
class Object
Word self.new()
return nil
end
end
class Object
int main()
Word w = Word.new()
end
end
HERE
@length = 34
@stdout = ""
check
end
end