Class: Dither::TestCase

Inherits:
Set
  • Object
show all
Defined in:
lib/dither/test_case.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bound_param_poolObject

Returns the value of attribute bound_param_pool.



5
6
7
# File 'lib/dither/test_case.rb', line 5

def bound_param_pool
  @bound_param_pool
end

#unbound_param_poolObject

Returns the value of attribute unbound_param_pool.



5
6
7
# File 'lib/dither/test_case.rb', line 5

def unbound_param_pool
  @unbound_param_pool
end

Class Method Details

.create(bound_param_pool, unbound_param_pool, params) ⇒ Object



7
8
9
10
11
12
# File 'lib/dither/test_case.rb', line 7

def self.create(bound_param_pool, unbound_param_pool, params)
  test_case = TestCase.new(params)
  test_case.bound_param_pool = bound_param_pool
  test_case.unbound_param_pool = unbound_param_pool
  test_case
end

Instance Method Details

#<=>(test_case) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/dither/test_case.rb', line 22

def <=>(test_case)
  result = 0
  l = length <= test_case.length ? length : test_case.length
  self.zip(test_case)[0...l].each do |arr|
    first, second = arr
    result = first <=> second
    break if result != 0
  end
  result
end

#contains_unbound?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dither/test_case.rb', line 14

def contains_unbound?
  self.any?(&:unbound?)
end

#create_unbound(i) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/dither/test_case.rb', line 33

def create_unbound(i)
  bound_params = self.reject(&:unbound?).map(&:i)
  ((0..i).to_a - bound_params).each do |a|
    self << unbound_param_pool[a]
  end
  self
end

#merge_without_conflict(i, test_case, &block) ⇒ Object

return nil if there is a conflict return self if no conflict



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dither/test_case.rb', line 51

def merge_without_conflict(i, test_case, &block)
  new_elements = []
  self.to_ipog_array(i).zip(test_case.to_ipog_array(i))
    .each_with_index do |arr, a|
    first, second = arr

    if first.nil? && second.nil?
      new_elements << unbound_param_pool[a]
    elsif (first == second) || second.nil?
      next
    elsif first.nil?
      new_elements << bound_param_pool[a][second]
    else
      return nil
    end
  end

  new_self = self.clone
  new_elements.each { |a| new_self << a }

  return nil if block_given? && block.call(new_self)

  new_elements.each do |a|
    self.delete(unbound_param_pool[a.i]) unless a.unbound?
    self << a
  end
  self
end

#to_ipog_array(i) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/dither/test_case.rb', line 41

def to_ipog_array(i)
  arr = Array.new(i)
  self.each do |param|
    arr[param.i] = param.j unless param.unbound?
  end
  arr
end

#unboundObject



18
19
20
# File 'lib/dither/test_case.rb', line 18

def unbound
  self.select(&:unbound?)
end