get the label int to work consistently

still need to use it in the return
This commit is contained in:
Torsten Ruger
2018-05-30 10:54:18 +03:00
parent 074ec34659
commit 0dc89c772a
9 changed files with 41 additions and 32 deletions

View File

@ -13,21 +13,6 @@ module Arm
true
end
end
class FakeInt
attr_reader :value
def initialize(val)
set_value(val)
end
def is_a?(clazz)
clazz == Parfait::Integer
end
def byte_length
4
end
def set_value(val)
@value = val
end
end
module ArmHelper
def setup
@machine = Arm::ArmMachine

View File

@ -3,7 +3,7 @@ require_relative "../helper"
module Risc
class TestInstructions < MiniTest::Test
def setup
@label = Label.new("test" , "test",nil)
@label = Label.new("test" , "test",FakeInt.new(5))
@branch = Branch.new("test" , @label)
@instruction = Instruction.new("test")
end
@ -19,7 +19,7 @@ module Risc
assert @label.to_s.include?("Label")
end
def test_label_tos2
assert Label.new(nil,nil,nil).to_s.include?("Label")
assert Label.new("nil",nil,FakeInt.new(2)).to_s.include?("Label")
end
def test_last_empty
assert_equal @instruction, @instruction.last
@ -55,7 +55,7 @@ module Risc
assert_nil @instruction.next(2)
end
def test_label_is_method
label = Label.new("test" , "Object.test" , nil)
label = Label.new("test" , "Object.test" , FakeInt.new(5))
assert label.is_method
end
def test_label_is_not_method

View File

@ -52,7 +52,7 @@ module Risc
end
def test_pc1
@interpreter.tick
assert_equal 17952 , @interpreter.pc
assert_equal 18392 , @interpreter.pc
end
def test_tick2
@interpreter.tick
@ -66,7 +66,7 @@ module Risc
def test_pc2
@interpreter.tick
@interpreter.tick
assert_equal 17956 , @interpreter.pc
assert_equal 18396 , @interpreter.pc
end
def test_tick_14_jump
14.times {@interpreter.tick}

View File

@ -29,10 +29,10 @@ module Risc
assert_equal 0 , Position.get(@machine.cpu_init).at
end
def test_cpu_at
assert_equal "0x555c" , Position.get(@machine.cpu_init.first).to_s
assert_equal "0x5714" , Position.get(@machine.cpu_init.first).to_s
end
def test_cpu_bin
assert_equal "0x5554" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s
assert_equal "0x570c" , Position.get(Position.get(@machine.cpu_init.first).binary).to_s
end
def test_cpu_label
assert_equal Position::InstructionPosition , Position.get(@machine.cpu_init.first).class

15
test/support/fake_int.rb Normal file
View File

@ -0,0 +1,15 @@
class FakeInt
attr_reader :value
def initialize(val)
set_value(val)
end
def is_a?(clazz)
clazz == Parfait::Integer
end
def byte_length
4
end
def set_value(val)
@value = val
end
end