putting tests into module

This commit is contained in:
Torsten Ruger 2017-01-03 22:42:40 +02:00
parent da58ce30e3
commit 8aee761b73
11 changed files with 453 additions and 434 deletions

View File

@ -1,7 +1,8 @@
require_relative "../helper"
require "register/interpreter"
module Ticker
module Register
module Ticker
include AST::Sexp
def setup
@ -60,4 +61,5 @@ module Ticker
end
exit(1)
end
end
end

View File

@ -1,15 +1,16 @@
require_relative "helper"
class AddTest < MiniTest::Test
module Register
class AddTest < MiniTest::Test
include Ticker
def setup
@string_input = <<HERE
class Space
class Space
int main()
return 5 + 7
end
end
end
HERE
@input = s(:statements, s(:return, s(:operator_value, :+, s(:int, 5), s(:int, 7))))
super
@ -57,4 +58,5 @@ HERE
result = @interpreter.get_register(done_op.left)
assert_equal result , 12
end
end
end

View File

@ -1,15 +1,16 @@
require_relative "helper"
class TestInterpretRegToByte < MiniTest::Test
module Register
class TestInterpretRegToByte < MiniTest::Test
include Ticker
def setup
@string_input = <<HERE
class Space
class Space
int main()
"Hello".set_internal_byte(1,104)
end
end
end
HERE
@input = s(:statements, s(:call,
s(:name, :set_internal_byte),
@ -61,4 +62,5 @@ HERE
assert_equal "h".ord , @interpreter.get_register(done.register)
end
end
end

View File

@ -1,12 +1,13 @@
require_relative "helper"
class IfCalledTest < MiniTest::Test
module Register
class IfCalledTest < MiniTest::Test
include Ticker
include Compiling
def setup
@string_input = <<HERE
class Space
class Space
int itest(int n)
if_zero( n - 12)
"then".putstring()
@ -18,7 +19,7 @@ class Space
int main()
itest(20)
end
end
end
HERE
@input = s(:statements, s(:call, s(:name, :itest), s(:arguments, s(:int, 20))))
super
@ -48,4 +49,5 @@ HERE
"FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label",
"FunctionReturn","RegisterTransfer","Syscall","NilClass"]
end
end
end

View File

@ -1,6 +1,7 @@
require_relative "helper"
class AddChange < MiniTest::Test
module Register
class AddChange < MiniTest::Test
include Ticker
def setup
@ -42,4 +43,5 @@ class AddChange < MiniTest::Test
"RegisterTransfer","Syscall","NilClass"]
end
end
end

View File

@ -1,17 +1,17 @@
require_relative "helper"
class MultTest < MiniTest::Test
module Register
class MultTest < MiniTest::Test
include Ticker
include AST::Sexp
def setup
@string_input = <<HERE
class Space
class Space
int main()
return #{2**31} * #{2**31}
end
end
end
HERE
@input = s(:statements, s(:return, s(:operator_value, :*, s(:int, 2147483648), s(:int, 2147483648))))
super
@ -35,4 +35,5 @@ HERE
assert @interpreter.flags[:zero]
end
end
end

View File

@ -1,15 +1,16 @@
require_relative "helper"
class PlusTest < MiniTest::Test
module Register
class PlusTest < MiniTest::Test
include Ticker
def setup
@string_input = <<HERE
class Space
class Space
int main()
return #{2**62 - 1} + 1
end
end
end
HERE
@input = s(:statements, s(:return, s(:operator_value, :+, s(:int, 4611686018427387903), s(:int, 1))))
super
@ -33,4 +34,5 @@ HERE
ticks( 12 )
assert @interpreter.flags[:zero]
end
end
end

View File

@ -1,15 +1,16 @@
require_relative "helper"
class TestPuts < MiniTest::Test
module Register
class TestPuts < MiniTest::Test
include Ticker
def setup
@string_input = <<HERE
class Space
class Space
int main()
"Hello again".putstring()
end
end
end
HERE
@input = s(:statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "Hello again"))))
super
@ -65,4 +66,5 @@ HERE
assert_equal NilClass , done.class
assert_equal "Hello again" , @interpreter.stdout
end
end
end

View File

@ -1,15 +1,16 @@
require_relative "helper"
class TestInterpretByteToReg < MiniTest::Test
module Register
class TestInterpretByteToReg < MiniTest::Test
include Ticker
def setup
@string_input = <<HERE
class Space
class Space
int main()
"Hello".get_internal_byte(1)
end
end
end
HERE
@input = s(:statements, s(:call,
s(:name, :get_internal_byte),
@ -61,4 +62,5 @@ HERE
assert_equal "H".ord , @interpreter.get_register(done.register)
end
end
end

View File

@ -1,12 +1,13 @@
require_relative "helper"
class IfSimpleTest < MiniTest::Test
module Register
class IfSimpleTest < MiniTest::Test
include Ticker
include Compiling
def setup
@string_input = <<HERE
class Space
class Space
int main()
if_zero( 10 - 12)
"then".putstring()
@ -14,7 +15,7 @@ class Space
"else".putstring()
end
end
end
end
HERE
@input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))),
s(:true_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "then")))),
@ -36,4 +37,5 @@ HERE
"Label","Label","FunctionReturn","RegisterTransfer","Syscall",
"NilClass"]
end
end
end

View File

@ -5,7 +5,7 @@ module Register
def test_simple_collect
Machine.new.boot
objects = Register::Collector.collect_space
assert ((352 == objects.length) or (420 == objects.length)) , objects.length.to_s
assert ((352 == objects.length) or (419 == objects.length)) , objects.length.to_s
end
end
end