rubyx/test/risc/interpreter/test_events.rb

57 lines
1.7 KiB
Ruby
Raw Normal View History

2018-04-01 21:50:15 +02:00
require_relative "helper"
module Risc
class InterpreterEvents < MiniTest::Test
include Ticker
def setup
2018-07-02 22:03:33 +02:00
@string_input = as_main("return 5")
2018-04-01 21:50:15 +02:00
@state_events = {}
@instruction_events = []
super
end
def state_changed( a , b)
@state_events[:state_changed] = [a , b]
end
def instruction_changed(was , is )
@instruction_events << was
end
2018-04-07 17:58:44 +02:00
def length
28
2018-04-07 17:58:44 +02:00
end
def test_state_change
2018-04-01 21:50:15 +02:00
@interpreter.register_event :state_changed , self
2018-04-07 17:58:44 +02:00
ticks length
2018-04-01 21:50:15 +02:00
assert @state_events[:state_changed]
assert_equal 2 , @state_events[:state_changed].length
assert_equal :running, @state_events[:state_changed][0]
@interpreter.unregister_event :state_changed , self
end
def test_instruction_events
2018-04-01 21:50:15 +02:00
@interpreter.register_event :instruction_changed , self
2018-04-07 17:58:44 +02:00
ticks length
assert_equal length , @instruction_events.length
2018-04-01 21:50:15 +02:00
@interpreter.unregister_event :instruction_changed , self
end
def test_chain
#show_ticks # get output of what is
2019-08-23 14:31:22 +02:00
check_chain [Branch, LoadConstant, SlotToReg, SlotToReg, RegToSlot, #5
2019-08-23 18:25:02 +02:00
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #10
RegToSlot, LoadConstant, RegToSlot, FunctionCall, LoadConstant, #15
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #20
2020-03-13 19:18:34 +01:00
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, #25
SlotToReg, Transfer, Syscall, NilClass,] #30
assert_equal ::Integer , get_return.class
assert_equal 5 , get_return
2018-04-01 21:50:15 +02:00
end
def test_length
run_all
assert_equal length , @interpreter.clock
end
2018-04-01 21:50:15 +02:00
end
end