Class: TestCaseGenerator::StateMachineContext
- Inherits:
-
Object
- Object
- TestCaseGenerator::StateMachineContext
- Defined in:
- lib/test_case_generator/state_machine.rb
Instance Method Summary collapse
- #_items!(out_items, counter, state, options = {}) ⇒ Object
- #add_path(src_state, dest_state, options = {}) ⇒ Object
- #add_state(name, options = {}) ⇒ Object
- #filter(&block) ⇒ Object
- #fork(state, options = {}) ⇒ Object
-
#initialize(attrs = {}) ⇒ StateMachineContext
constructor
A new instance of StateMachineContext.
- #items(options = {}) ⇒ Object
- #reject(&block) ⇒ Object
- #start_state ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ StateMachineContext
Returns a new instance of StateMachineContext.
49 50 51 52 53 54 55 56 57 58 |
# 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 |
Instance Method Details
#_items!(out_items, counter, state, options = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/test_case_generator/state_machine.rb', line 102 def _items!(out_items, counter, state, ={}) return if state.nil? count = counter[state.name] || 0 count += 1 counter[state.name] = count return if count > ([: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 = {}) ⇒ Object
65 66 67 68 |
# File 'lib/test_case_generator/state_machine.rb', line 65 def add_path(src_state, dest_state, ={}) ctx = Path.new(src_state, dest_state, ) @path_list << ctx end |
#add_state(name, options = {}) ⇒ Object
60 61 62 63 |
# File 'lib/test_case_generator/state_machine.rb', line 60 def add_state(name, ={}) ctx = State.new(name, ) @state_list << ctx end |
#filter(&block) ⇒ Object
74 75 76 |
# File 'lib/test_case_generator/state_machine.rb', line 74 def filter(&block) @filter_block = block end |
#fork(state, options = {}) ⇒ Object
78 79 80 |
# File 'lib/test_case_generator/state_machine.rb', line 78 def fork(state, ={}) @fork_list << Fork.new(state, ) end |
#items(options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/test_case_generator/state_machine.rb', line 90 def items(={}) out_items = [] counter = {} _items! out_items, counter, start_state, 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) ⇒ Object
70 71 72 |
# File 'lib/test_case_generator/state_machine.rb', line 70 def reject(&block) @reject_block = block end |
#start_state ⇒ Object
82 83 84 85 86 87 88 |
# 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 |