2018-06-01 18:13:53 +02:00
|
|
|
require_relative "helper"
|
2018-05-10 19:56:12 +02:00
|
|
|
|
|
|
|
module Risc
|
|
|
|
module Position
|
|
|
|
# tests that do no require a boot and only test basic positioning
|
|
|
|
class TestPositionBasic < MiniTest::Test
|
|
|
|
|
2018-06-02 15:12:01 +02:00
|
|
|
def test_init
|
|
|
|
assert_equal ObjectPosition.init(self)
|
|
|
|
end
|
|
|
|
def pest_creation_ok
|
2018-05-23 20:34:49 +02:00
|
|
|
assert ObjectPosition.new(self,0)
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_creation_fail
|
2018-05-10 19:56:12 +02:00
|
|
|
assert_raises {Position.new("0")}
|
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_add
|
2018-05-23 20:34:49 +02:00
|
|
|
res = ObjectPosition.new(self,0) + 5
|
2018-05-10 19:56:12 +02:00
|
|
|
assert_equal 5 , res
|
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_sub
|
2018-05-23 20:34:49 +02:00
|
|
|
res = ObjectPosition.new(self,0) - 1
|
|
|
|
assert_equal -1 , res
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_sub_pos
|
2018-05-23 20:34:49 +02:00
|
|
|
res = ObjectPosition.new(self,0) - ObjectPosition.new(self,0)
|
|
|
|
assert_equal 0 , res
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_set
|
2018-05-10 19:56:12 +02:00
|
|
|
pos = Position.set(self , 5)
|
|
|
|
assert_equal 5 , pos.at
|
|
|
|
end
|
|
|
|
def tet_tos
|
|
|
|
assert_equal "0x10" , Position.set(self).to_s
|
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_reset_ok
|
2018-05-10 19:56:12 +02:00
|
|
|
pos = Position.set(self , 5)
|
|
|
|
pos = Position.set(self , 10)
|
|
|
|
assert_equal 10 , pos.at
|
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_reset_fail
|
2018-05-10 19:56:12 +02:00
|
|
|
Position.set(self , 5)
|
|
|
|
assert_raises{Position.set(self , 10000)}
|
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_raises_set_nil
|
2018-05-10 19:56:12 +02:00
|
|
|
assert_raises { Position.set(self,nil)}
|
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_at
|
2018-05-17 19:13:33 +02:00
|
|
|
pos = Position.set(self , 5)
|
|
|
|
pos = Position.at(5)
|
|
|
|
assert_equal 5 , pos.at
|
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
2018-05-31 16:01:23 +02:00
|
|
|
class TestPositionEvents < MiniTest::Test
|
|
|
|
def setup
|
2018-06-02 15:12:01 +02:00
|
|
|
@position = ObjectPosition.new(self)
|
2018-05-31 16:01:23 +02:00
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_has_register
|
2018-05-31 18:05:53 +02:00
|
|
|
assert @position.register_event(:position_changed , self)
|
2018-05-31 16:01:23 +02:00
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_can_unregister
|
2018-05-31 18:05:53 +02:00
|
|
|
assert @position.register_event(:position_changed ,self)
|
|
|
|
assert @position.unregister_event(:position_changed ,self)
|
2018-05-31 16:01:23 +02:00
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_fires
|
2018-05-31 18:05:53 +02:00
|
|
|
@position.register_event(:position_changed ,self)
|
|
|
|
@position.trigger(:position_changed , @position)
|
2018-05-31 16:01:23 +02:00
|
|
|
assert_equal @position , @trigger
|
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
def pest_no_fire_after_unregister
|
2018-05-31 18:05:53 +02:00
|
|
|
assert @position.register_event(:position_changed ,self)
|
|
|
|
assert @position.unregister_event(:position_changed ,self)
|
|
|
|
@position.trigger(:position_changed , @position)
|
2018-05-31 16:01:23 +02:00
|
|
|
assert_nil @trigger
|
|
|
|
end
|
|
|
|
def position_changed(pos)
|
|
|
|
@trigger = pos
|
|
|
|
end
|
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
end
|