class TestCaseGenerator::StateMachineContext

Public Class Methods

new(attrs={}) click to toggle source
# File lib/test_case_generator/state_machine.rb, line 49
def initialize(attrs={})
  @attrs = attrs

  @state_list = []
  @path_list = []
  @fork_list = []
  @start_state = attrs[:start_state]
  @reject_block = nil
  @filter_block = nil
end

Public Instance Methods

_items!(out_items, counter, state, options={}) click to toggle source
# File lib/test_case_generator/state_machine.rb, line 102
def _items!(out_items, counter, state, options={})
  return if state.nil?

  count = counter[state.name] || 0
  count += 1
  counter[state.name] = count

  return if count > (options[:limit] || 2)

  Utils.concat! out_items, state.items

  tmp_list0 = []
  @path_list.find_all{|path| path.src_state == state.name}.each do |path|
    tmp_list = []
    Utils.concat! tmp_list, path.items
    _items! tmp_list, counter.clone, @state_list.find{ |s| s.name == path.dest_state}
    tmp_list0.concat tmp_list
  end

  @fork_list.find_all{|fork| fork.state == state.name}.each do |fork|
    Utils.para! tmp_list0, fork.items
  end

  Utils.concat! out_items, tmp_list0
end
add_path(src_state, dest_state, options={}) click to toggle source
# File lib/test_case_generator/state_machine.rb, line 65
def add_path(src_state, dest_state, options={})
  ctx = Path.new(src_state, dest_state, options)
  @path_list << ctx
end
add_state(name, options={}) click to toggle source
# File lib/test_case_generator/state_machine.rb, line 60
def add_state(name, options={})
  ctx = State.new(name, options)
  @state_list << ctx
end
filter(&block) click to toggle source
# File lib/test_case_generator/state_machine.rb, line 74
def filter(&block)
  @filter_block = block
end
fork(state, options={}) click to toggle source
# File lib/test_case_generator/state_machine.rb, line 78
def fork(state, options={})
  @fork_list << Fork.new(state, options)
end
items(options={}) click to toggle source
# File lib/test_case_generator/state_machine.rb, line 90
def items(options={})
  out_items = []
  counter = {}
  _items! out_items, counter, start_state, options
  out_items.uniq!
  out_items.reject! &(@reject_block) unless @reject_block.nil?
  out_items.keep_if &(@filter_block) unless @filter_block.nil?

  p out_items
  out_items
end
reject(&block) click to toggle source
# File lib/test_case_generator/state_machine.rb, line 70
def reject(&block)
  @reject_block = block
end
start_state() click to toggle source
# File lib/test_case_generator/state_machine.rb, line 82
def start_state
  if @start_state.nil?
    @state_list[0]
  else
    @state_list.find{ |state| state.name == @start_state }
  end
end