-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.rb
More file actions
executable file
·29 lines (24 loc) · 809 Bytes
/
simulator.rb
File metadata and controls
executable file
·29 lines (24 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'state_machine'
require 'state'
require 'transition'
require 'rinda/rinda'
require 'exceptions'
class Simulator
include Exceptions
def initialize(state_machine)
@state_machine = state_machine
@initial = state_machine.get_initial()
end
def simulate(input)
current_state = @initial
output = Array.new
input.each do |current_input|
raise IllegalInputException if current_state.transitions[current_input].nil?
transition = current_state.transitions[current_input].first
next_state_name = transition.to
# use Rinda::Tuple because ruby does not have built in support for tuples like e.g. python
output.push(Rinda::Tuple.new([transition.action, next_state_name]))
current_state = @state_machine.get_state(next_state_name)
end
end
end