2016-12-30 19:48:14 +01:00
|
|
|
require_relative "../helper"
|
|
|
|
|
2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2018-03-28 10:37:17 +02:00
|
|
|
class TestMachineObjects < MiniTest::Test
|
2016-12-30 19:48:14 +01:00
|
|
|
|
|
|
|
def setup
|
2017-01-19 08:02:29 +01:00
|
|
|
@machine = Risc.machine.boot
|
2016-12-30 19:48:14 +01:00
|
|
|
end
|
2018-03-27 17:47:39 +02:00
|
|
|
def test_objects
|
|
|
|
objects = @machine.objects
|
|
|
|
assert_equal Hash , objects.class
|
2018-03-27 18:06:16 +02:00
|
|
|
assert 350 < objects.length
|
2018-03-27 17:47:39 +02:00
|
|
|
end
|
2018-03-31 12:25:59 +02:00
|
|
|
def test_constant_fail
|
|
|
|
assert_raises {@machine.add_constant( 1 )}
|
|
|
|
end
|
|
|
|
def test_constant
|
|
|
|
assert @machine.add_constant( Parfait::Integer.new(5) )
|
|
|
|
end
|
2018-03-28 10:37:17 +02:00
|
|
|
end
|
|
|
|
class TestMachinePositions < MiniTest::Test
|
|
|
|
def setup
|
|
|
|
@machine = Risc.machine.boot
|
2018-03-27 17:47:39 +02:00
|
|
|
@machine.position_all
|
2018-03-27 18:06:16 +02:00
|
|
|
end
|
|
|
|
def test_has_positions
|
|
|
|
@machine.objects.each do |id,obj|
|
2018-05-06 19:04:02 +02:00
|
|
|
assert Position.get(obj)
|
2018-03-27 18:06:16 +02:00
|
|
|
end
|
2016-12-30 19:48:14 +01:00
|
|
|
end
|
2018-04-30 12:28:55 +02:00
|
|
|
end
|
|
|
|
class TestMachineInit < MiniTest::Test
|
|
|
|
def setup
|
|
|
|
@machine = Risc.machine.boot
|
|
|
|
@machine.position_all
|
2018-03-28 12:04:25 +02:00
|
|
|
@machine.create_binary
|
2018-03-27 19:47:41 +02:00
|
|
|
end
|
2018-04-30 12:28:55 +02:00
|
|
|
def test_has_binary
|
|
|
|
assert_equal Parfait::BinaryCode , @machine.binary_init.class
|
|
|
|
end
|
|
|
|
def test_has_jump
|
2018-05-11 17:36:45 +02:00
|
|
|
assert_equal "ea000fb4" , @machine.binary_init.get_word(1).to_s(16)
|
2018-04-30 12:28:55 +02:00
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
def test_pos_bin
|
|
|
|
assert_equal "0x0" , Position.get(@machine.binary_init).to_s
|
|
|
|
end
|
|
|
|
def test_pos_cpu
|
|
|
|
assert_equal 12 , Position.get(@machine.cpu_init).at
|
|
|
|
end
|
|
|
|
def test_cpu_at
|
2018-05-11 17:36:45 +02:00
|
|
|
assert_equal "0x3ee4" , Position.get(@machine.cpu_init.first).to_s
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
def test_cpu_bin
|
|
|
|
assert_equal "0x3ed8" , 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
|
|
|
|
end
|
2016-12-30 19:48:14 +01:00
|
|
|
end
|
|
|
|
end
|