Module: Dither::IPOGHelper
Instance Method Summary collapse
- #init_params(user_params, previously_tested) ⇒ Object
- #initialize(params, opts = {}) ⇒ Object
-
#maximize_coverage(i, test_case, pi) ⇒ Object
return nil if unable to satisfy constraints.
- #violates_constraints?(params) ⇒ Boolean
Instance Method Details
#init_params(user_params, previously_tested) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dither/ipog_helper.rb', line 24 def init_params(user_params, previously_tested) tmp = [] @input_params = user_params user_params.each_with_index { |e, i| tmp << [i, e] } @orig_params = tmp.sort_by { |a| a[1].length } .reverse! orig_param_map = {} @map_to_orig_index = {} @orig_params.each_with_index do |e, i| @map_to_orig_index[i] = e[0] orig_param_map[e[0]] = {} end @params = [] @unbound_param_pool = [] orig_params.each_with_index do |e, i| @params << (0...e[1].length).map do |j| local_param = Param.new(i, j) orig_param_map[e[0]][e[1][j]] = local_param local_param end @unbound_param_pool << UnboundParam.new(i) end @tested = [] previously_tested.each do |a| local_params = [] a.each_with_index do |e, i| local_params << orig_param_map[i][e] end @tested << TestCase.create(params, unbound_param_pool, local_params) end params end |
#initialize(params, opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dither/ipog_helper.rb', line 8 def initialize(params, opts = {}) init_params(params, (opts[:previously_tested] || [])) @t = opts[:t] unless opts[:constraints].nil? @constraints = opts[:constraints].map(&:to_a) .map { |a| a.map { |b| @params[@map_to_orig_index.key(b[0])][b[1]] } } .map(&:to_set) end raise Dither::Error, 't must be >= 2' if opts[:t] < 2 raise Dither::Error, 't must be <= params.length' if opts[:t] > params.length params.each do |param| raise Dither::Error, 'param length must be > 1' if param.length < 2 end end |
#maximize_coverage(i, test_case, pi) ⇒ Object
return nil if unable to satisfy constraints
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dither/ipog_helper.rb', line 62 def maximize_coverage(i, test_case, pi) current_max = 0 current_max_j = 0 current_matches = [] (0...params[i].length).each do |j| current_param = params[i][j] test_case << current_param unless violates_constraints?(test_case) matches = pi.select { |a| a.subset?(test_case) } count = matches.count if count > current_max current_max = count current_max_j = j current_matches = matches end end test_case.delete(current_param) end return nil if violates_constraints?(test_case) test_case << params[i][current_max_j] current_matches end |
#violates_constraints?(params) ⇒ Boolean
89 90 91 92 |
# File 'lib/dither/ipog_helper.rb', line 89 def violates_constraints?(params) return false if constraints.nil? constraints.any? { |b| b.subset?(params) } end |