2018-06-06 09:19:18 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestPositionMath < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
2018-06-15 21:00:49 +02:00
|
|
|
@pos = Position.new(self).set(5)
|
2018-06-06 09:19:18 +02:00
|
|
|
end
|
|
|
|
def test_add
|
|
|
|
res = @pos + 5
|
|
|
|
assert_equal 10 , res
|
|
|
|
end
|
|
|
|
def test_sub
|
|
|
|
res = @pos - 3
|
|
|
|
assert_equal 2 , res
|
|
|
|
end
|
|
|
|
def test_sub_pos
|
2018-06-15 21:00:49 +02:00
|
|
|
res = @pos - Position.new(@pos).set(4)
|
2018-06-06 09:19:18 +02:00
|
|
|
assert_equal 1 , res
|
|
|
|
end
|
|
|
|
def test_lg
|
2018-06-15 21:00:49 +02:00
|
|
|
assert @pos > Position.new(@pos).set(2)
|
2018-06-06 09:19:18 +02:00
|
|
|
end
|
|
|
|
def test_tos
|
|
|
|
assert_equal "0x5" , @pos.to_s
|
|
|
|
end
|
|
|
|
def test_reset_ok
|
|
|
|
pos = @pos.set(10)
|
2018-06-15 21:00:49 +02:00
|
|
|
assert_equal 10 , pos.at
|
2018-06-06 09:19:18 +02:00
|
|
|
end
|
2018-06-07 18:27:44 +02:00
|
|
|
def test_object_class_test
|
|
|
|
assert_equal :object , @pos.object_class
|
|
|
|
end
|
|
|
|
def test_object_class_instr
|
2018-06-15 21:00:49 +02:00
|
|
|
assert_equal :instruction , Position.new(Label.new("hi","ho",FakeAddress.new(1))).set(4).object_class
|
2018-06-07 18:27:44 +02:00
|
|
|
end
|
2018-06-06 09:19:18 +02:00
|
|
|
def test_at
|
|
|
|
pos = Position.at(5)
|
|
|
|
assert_equal 5 , pos.at
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|