fix interpreter overflow issue
flag set for bigness, result reduced tests for + and * fixed fibs tests
This commit is contained in:
@ -28,17 +28,17 @@ HERE
|
||||
@string_input.sub!( "100" , num.to_s )
|
||||
end
|
||||
|
||||
def test_while_fibo100
|
||||
fibo 100
|
||||
@length = 2345
|
||||
#TODO bug, int max is 92 ruby converts to biginteger.
|
||||
check_return 354224848179261915075
|
||||
def test_while_fibo94
|
||||
fibo 91
|
||||
@length = 2138
|
||||
# this is not the correct fibo, just what comes from wrapping (smaller than below)
|
||||
check_return 48360591948142405
|
||||
end
|
||||
|
||||
def test_while_fibo92
|
||||
fibo 92
|
||||
@length = 2161
|
||||
check_return 7540113804746346429
|
||||
def test_while_fibo90
|
||||
fibo 90
|
||||
@length = 2115
|
||||
check_return 2880067194370816120
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -21,6 +21,11 @@ module Ticker
|
||||
end
|
||||
end
|
||||
|
||||
def check_return val
|
||||
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
|
||||
assert_equal val , @interpreter.get_register(:r0).return_value
|
||||
end
|
||||
|
||||
def ticks num
|
||||
last = nil
|
||||
num.times do
|
||||
|
@ -1,4 +1,5 @@
|
||||
require_relative "test_add"
|
||||
require_relative "test_if"
|
||||
require_relative "test_puts"
|
||||
require_relative "test_ops"
|
||||
require_relative "test_plus"
|
||||
require_relative "test_mult"
|
||||
|
@ -1,6 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
class AddTest < MiniTest::Test
|
||||
class IfTest < MiniTest::Test
|
||||
include Ticker
|
||||
|
||||
def setup
|
||||
|
@ -1,6 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
class AddTest < MiniTest::Test
|
||||
class MultTest < MiniTest::Test
|
||||
include Ticker
|
||||
include AST::Sexp
|
||||
|
||||
@ -8,35 +8,29 @@ class AddTest < MiniTest::Test
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int main()
|
||||
return 5 + 10
|
||||
return #{2**31} * #{2**31}
|
||||
end
|
||||
end
|
||||
HERE
|
||||
super
|
||||
end
|
||||
|
||||
def test_add
|
||||
#show_ticks # get output of what is
|
||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
||||
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
|
||||
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
|
||||
"RegisterTransfer","Syscall","NilClass"]
|
||||
end
|
||||
|
||||
def test_mult
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int main()
|
||||
return 5 * 10
|
||||
end
|
||||
end
|
||||
HERE
|
||||
setup
|
||||
#show_ticks # get output of what is
|
||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
||||
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
|
||||
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
|
||||
"RegisterTransfer","Syscall","NilClass"]
|
||||
check_return 0
|
||||
end
|
||||
def test_overflow
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:overflow]
|
||||
end
|
||||
|
||||
def test_zero
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:zero]
|
||||
end
|
||||
|
||||
end
|
35
test/interpreter/test_plus.rb
Normal file
35
test/interpreter/test_plus.rb
Normal file
@ -0,0 +1,35 @@
|
||||
require_relative "helper"
|
||||
|
||||
class PlusTest < MiniTest::Test
|
||||
include Ticker
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int main()
|
||||
return #{2**62 - 1} + 1
|
||||
end
|
||||
end
|
||||
HERE
|
||||
super
|
||||
end
|
||||
|
||||
def test_add
|
||||
#show_ticks # get output of what is
|
||||
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
||||
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
|
||||
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
|
||||
"RegisterTransfer","Syscall","NilClass"]
|
||||
check_return 0
|
||||
end
|
||||
|
||||
def test_overflow
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:overflow]
|
||||
end
|
||||
|
||||
def test_zero
|
||||
ticks( 12 )
|
||||
assert @interpreter.flags[:zero]
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user