renaming and test fixing
This commit is contained in:
@ -6,4 +6,7 @@ module Risc
|
||||
4
|
||||
end
|
||||
end
|
||||
class DummyInstruction < Dummy
|
||||
include Util::List
|
||||
end
|
||||
end
|
||||
|
@ -14,8 +14,10 @@ module Risc
|
||||
pos = CodeListener.init(@binary)
|
||||
assert_equal pos, Position.get(@binary)
|
||||
end
|
||||
def test_init_fail
|
||||
assert_raises{ CodeListener.init( @method)}
|
||||
end
|
||||
def test_init_returns_position
|
||||
|
||||
assert_equal Position , CodeListener.init(@binary).class
|
||||
end
|
||||
def test_init_listner
|
||||
|
@ -7,11 +7,14 @@ module Risc
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
#Position.set(@binary , 0 , Parfait.object_space.get_main)
|
||||
@label = Risc.label("hi","ho")
|
||||
@label = DummyInstruction.new
|
||||
end
|
||||
def test_init
|
||||
assert InstructionListener.init(@label , @binary)
|
||||
end
|
||||
def test_init_fail
|
||||
assert_raises {InstructionListener.init(@label , nil)}
|
||||
end
|
||||
def pest_set_instr
|
||||
pos = Position.set( @label , 8 , @binary)
|
||||
assert_equal InstructionPosition , pos.class
|
||||
|
@ -4,8 +4,11 @@ module Risc
|
||||
# tests that do no require a boot and only test basic positioning
|
||||
class TestPosition < MiniTest::Test
|
||||
|
||||
def setup
|
||||
@pos = Position.new(self , -1)
|
||||
end
|
||||
def test_new
|
||||
assert Position.new(self , -1)
|
||||
assert @pos
|
||||
end
|
||||
def test_next_slot
|
||||
mov = Arm::ArmMachine.mov(:r1 , :r1)
|
||||
@ -13,73 +16,68 @@ module Risc
|
||||
assert_equal 4, position.next_slot
|
||||
end
|
||||
def test_has_get_code
|
||||
assert_nil Position.new(self , -1).get_code
|
||||
assert_nil @pos.get_code
|
||||
end
|
||||
def test_has_listeners_helper
|
||||
assert_equal Array , Position.new(self,-1).position_listeners.class
|
||||
assert_equal Array , @pos.position_listeners.class
|
||||
end
|
||||
def test_listeners_empty
|
||||
assert Position.new(self,-1).position_listeners.empty?
|
||||
assert @pos.position_listeners.empty?
|
||||
end
|
||||
def test_has_listener_helper
|
||||
pos = Position.new(self,-1)
|
||||
pos.position_listener( self )
|
||||
assert_equal 1 , pos.position_listeners.length
|
||||
@pos.position_listener( self )
|
||||
assert_equal 1 , @pos.position_listeners.length
|
||||
end
|
||||
def test_set
|
||||
assert_equal 0 , @pos.set(0)
|
||||
end
|
||||
end
|
||||
class TestPositionMath < MiniTest::Test
|
||||
|
||||
def pest_creation_fail
|
||||
assert_raises {Position.new("0")}
|
||||
def setup
|
||||
@pos = Position.new(self , 5)
|
||||
end
|
||||
def pest_add
|
||||
res = Position.new(self,0) + 5
|
||||
assert_equal 5 , res
|
||||
def test_add
|
||||
res = @pos + 5
|
||||
assert_equal 10 , res
|
||||
end
|
||||
def pest_sub
|
||||
res = Position.new(self,0) - 1
|
||||
assert_equal -1 , res
|
||||
def test_sub
|
||||
res = @pos - 3
|
||||
assert_equal 2 , res
|
||||
end
|
||||
def pest_sub_pos
|
||||
res = Position.new(self,0) - Position.new(self,0)
|
||||
assert_equal 0 , res
|
||||
def test_sub_pos
|
||||
res = @pos - Position.new(@pos,4)
|
||||
assert_equal 1 , res
|
||||
end
|
||||
def pest_set
|
||||
pos = Position.set(self , 5)
|
||||
assert_equal 5 , pos.at
|
||||
def test_tos
|
||||
assert_equal "0x5" , @pos.to_s
|
||||
end
|
||||
def tet_tos
|
||||
assert_equal "0x10" , Position.set(self).to_s
|
||||
def test_reset_ok
|
||||
pos = @pos.set(10)
|
||||
assert_equal 10 , pos
|
||||
end
|
||||
def pest_reset_ok
|
||||
pos = Position.set(self , 5)
|
||||
pos = Position.set(self , 10)
|
||||
assert_equal 10 , pos.at
|
||||
end
|
||||
def pest_reset_fail
|
||||
Position.set(self , 5)
|
||||
assert_raises{Position.set(self , 10000)}
|
||||
end
|
||||
def pest_raises_set_nil
|
||||
assert_raises { Position.set(self,nil)}
|
||||
end
|
||||
def pest_at
|
||||
pos = Position.set(self , 5)
|
||||
def test_at
|
||||
pos = Position.at(5)
|
||||
assert_equal 5 , pos.at
|
||||
end
|
||||
end
|
||||
class TestPositionEvents < MiniTest::Test
|
||||
def setup
|
||||
@position = Position.new(self)
|
||||
Position.clear_positions
|
||||
@instruciton = DummyInstruction.new
|
||||
@position = Position.new(@instruction , 0)
|
||||
@listener = PositionListener.new( @instruction )
|
||||
end
|
||||
def pest_has_register
|
||||
assert @position.position_listener( self)
|
||||
def test_has_register
|
||||
assert @position.position_listener( @instruction )
|
||||
end
|
||||
def pest_can_unregister
|
||||
def test_can_unregister
|
||||
listener = PositionListener.new(self)
|
||||
assert @position.position_listener(listener)
|
||||
assert @position.unregister_event(:position_changed ,listener)
|
||||
end
|
||||
def pest_fires
|
||||
@object = @instruction
|
||||
@position.position_listener(self)
|
||||
@position.trigger(:position_changed , @position)
|
||||
assert_equal @position , @trigger
|
||||
|
Reference in New Issue
Block a user