fix interpreter tests to use classes (not strings)

and fix for the change in call sequence
This commit is contained in:
Torsten Ruger 2017-01-04 21:36:46 +02:00
parent 3f24409093
commit 49da77f996
9 changed files with 112 additions and 101 deletions

View File

@ -18,34 +18,36 @@ HERE
def test_chain
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end
def test_get
assert_equal Register::SlotToReg , ticks(4).class
assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r2 )
assert Integer , @interpreter.get_register( :r2 ).class
end
def test_transfer
transfer = ticks 16
assert_equal Register::RegisterTransfer , transfer.class
transfer = ticks 19
assert_equal RegisterTransfer , transfer.class
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
end
def test_call
ret = ticks(15)
assert_equal Register::FunctionReturn , ret.class
ret = ticks(18)
assert_equal FunctionReturn , ret.class
object = @interpreter.get_register( ret.register )
link = object.get_internal_word( ret.index )
assert_equal Register::Label , link.class
assert_equal Label , link.class
end
def test_adding
done_op = ticks(12)
assert_equal Register::OperatorInstruction , done_op.class
assert_equal OperatorInstruction , done_op.class
left = @interpreter.get_register(done_op.left)
rr = done_op.right
right = @interpreter.get_register(rr)
@ -53,8 +55,8 @@ HERE
assert_equal Fixnum , right.class
assert_equal 7 , right
assert_equal 12 , left
done_tr = ticks(4)
assert_equal Register::RegisterTransfer , done_tr.class
done_tr = ticks(1)
assert_equal RegToSlot , done_tr.class
result = @interpreter.get_register(done_op.left)
assert_equal result , 12
end

View File

@ -21,44 +21,45 @@ HERE
def test_chain
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg",
"RegToSlot","LoadConstant","SlotToReg","RegToSlot","LoadConstant",
"RegToSlot","RegisterTransfer","FunctionCall","Label","SlotToReg",
"SlotToReg","SlotToReg","SlotToReg","SlotToReg","RegToByte",
"Label","FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg",
"Label","FunctionReturn","RegisterTransfer","Syscall","NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot,
RegisterTransfer, FunctionCall, Label, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
SlotToReg, RegToByte, Label, FunctionReturn, RegisterTransfer,
SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot,
Label, FunctionReturn, RegisterTransfer, Syscall, NilClass]
end
def test_branch
was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class
assert_equal Branch , ticks(1).class
assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction"
end
def test_load
assert_equal Register::LoadConstant , ticks(3).class
assert_equal LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol
end
def test_get
assert_equal Register::SlotToReg , ticks(4).class
assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class
end
def test_call
assert_equal Register::FunctionCall , ticks(8).class
assert_equal FunctionCall , ticks(8).class
end
def test_exit
done = ticks(45)
done = ticks(50)
assert_equal NilClass , done.class
end
def test_reg_to_byte
done = ticks(35)
assert_equal Register::RegToByte , done.class
done = ticks(37)
assert_equal RegToByte , done.class
assert_equal "h".ord , @interpreter.get_register(done.register)
end

View File

@ -34,20 +34,22 @@ HERE
end
def test_if
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"SlotToReg","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg",
"RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall",
"Label","SlotToReg","SlotToReg","LoadConstant","OperatorInstruction",
"IsZero","SlotToReg","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","SlotToReg","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label",
"SlotToReg","SlotToReg","RegisterTransfer","Syscall","RegisterTransfer",
"RegisterTransfer","RegToSlot","Label","FunctionReturn","RegisterTransfer",
"SlotToReg","SlotToReg","Branch","Label","Label",
"FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label",
"FunctionReturn","RegisterTransfer","Syscall","NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
LoadConstant, OperatorInstruction, IsZero, SlotToReg, LoadConstant,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall,
Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegisterTransfer, Syscall, RegisterTransfer, RegisterTransfer,
RegToSlot, Label, FunctionReturn, RegisterTransfer, SlotToReg,
SlotToReg, Branch, Label, Label, FunctionReturn,
RegisterTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg,
RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end
end
end

View File

@ -31,16 +31,17 @@ module Register
def test_instruction_events
@interpreter.register_event :instruction_changed , self
ticks 30
assert_equal 17 , @instruction_events.length
assert_equal 20 , @instruction_events.length
@interpreter.unregister_event :instruction_changed , self
end
def test_chain
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end
end

View File

@ -19,10 +19,11 @@ HERE
def test_mult
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
check_return 0
end
def test_overflow

View File

@ -18,10 +18,11 @@ HERE
def test_add
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
check_return 0
end

View File

@ -18,51 +18,52 @@ HERE
def test_chain
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"SlotToReg","SlotToReg","RegToSlot","LoadConstant","RegToSlot",
"RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg",
"RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer","RegToSlot",
"Label","FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg",
"Label","FunctionReturn","RegisterTransfer","Syscall","NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer,
FunctionCall, Label, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, RegisterTransfer, Syscall, RegisterTransfer,
RegisterTransfer, RegToSlot, Label, FunctionReturn, RegisterTransfer,
SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot,
Label, FunctionReturn, RegisterTransfer, Syscall, NilClass]
end
def test_branch
was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class
assert_equal Branch , ticks(1).class
assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction"
end
def test_load
assert_equal Register::LoadConstant , ticks(3).class
assert_equal LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol
end
def test_get
assert_equal Register::SlotToReg , ticks(4).class
assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class
end
def test_call
assert_equal Register::FunctionCall , ticks(8).class
assert_equal FunctionCall , ticks(8).class
end
def test_putstring
done = ticks(27)
assert_equal Register::Syscall , done.class
done = ticks(29)
assert_equal Syscall , done.class
assert_equal "Hello again" , @interpreter.stdout
end
def test_return
done = ticks(32)
assert_equal Register::FunctionReturn , done.class
assert Register::Label , @interpreter.instruction.class
assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}"
done = ticks(34)
assert_equal FunctionReturn , done.class
assert Label , @interpreter.instruction.class
assert @interpreter.instruction.is_a?(Instruction) , "not instruction #{@interpreter.instruction}"
end
def test_exit
done = ticks(42)
done = ticks(45)
assert_equal NilClass , done.class
assert_equal "Hello again" , @interpreter.stdout
end

View File

@ -21,44 +21,45 @@ HERE
def test_chain
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg",
"RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall",
"Label","SlotToReg","SlotToReg","SlotToReg","ByteToReg",
"RegToSlot","Label","FunctionReturn","RegisterTransfer","SlotToReg",
"SlotToReg","Label","FunctionReturn","RegisterTransfer","Syscall",
"NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, ByteToReg, RegToSlot, Label, FunctionReturn,
RegisterTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg,
RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end
def test_branch
was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class
assert_equal Branch , ticks(1).class
assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction"
end
def test_load
assert_equal Register::LoadConstant , ticks(3).class
assert_equal LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol
end
def test_get
assert_equal Register::SlotToReg , ticks(4).class
assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class
end
def test_call
assert_equal Register::FunctionCall , ticks(8).class
assert_equal FunctionCall , ticks(8).class
end
def test_exit
done = ticks(41)
done = ticks(46)
assert_equal NilClass , done.class
end
def test_byte_to_reg
done = ticks(30)
assert_equal Register::ByteToReg , done.class
done = ticks(32)
assert_equal ByteToReg , done.class
assert_equal "H".ord , @interpreter.get_register(done.register)
end

View File

@ -26,16 +26,17 @@ HERE
def test_if
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","IsZero","SlotToReg","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","SlotToReg",
"SlotToReg","RegToSlot","LoadConstant","RegToSlot","RegisterTransfer",
"FunctionCall","Label","SlotToReg","SlotToReg","RegisterTransfer",
"Syscall","RegisterTransfer","RegisterTransfer","RegToSlot","Label",
"FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Branch",
"Label","Label","FunctionReturn","RegisterTransfer","Syscall",
"NilClass"]
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
LoadConstant, OperatorInstruction, IsZero, SlotToReg, LoadConstant,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall,
Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegisterTransfer, Syscall, RegisterTransfer, RegisterTransfer,
RegToSlot, Label, FunctionReturn, RegisterTransfer, SlotToReg,
SlotToReg, Branch, Label, LoadConstant, SlotToReg,
RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end
end
end