Sha256: dfa7ec80489fc3e8e3c3bb6cdb7bbc511c9a795994ba27333f223681c7ce6eee

Contents?: true

Size: 1.9 KB

Versions: 27

Compression:

Stored size: 1.9 KB

Contents

module Dither
  class TestCase < Set

    attr_accessor :bound_param_pool, :unbound_param_pool

    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

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

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

    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

    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

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

    # return nil if there is a conflict
    # return self if no conflict
    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
  end # TestCase
end # Dither

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
dither-0.1.5 lib/dither/test_case.rb
dither-0.1.5-java lib/dither/test_case.rb
dither-0.1.4-java lib/dither/test_case.rb
dither-0.1.4 lib/dither/test_case.rb
dither-0.1.3-java lib/dither/test_case.rb
dither-0.1.3 lib/dither/test_case.rb
dither-0.1.2-java lib/dither/test_case.rb
dither-0.1.2 lib/dither/test_case.rb
dither-0.1.1 lib/dither/test_case.rb
dither-0.1.1-java lib/dither/test_case.rb
dither-0.0.15 lib/dither/test_case.rb
dither-0.0.15-java lib/dither/test_case.rb
dither-0.0.14 lib/dither/test_case.rb
dither-0.0.14-java lib/dither/test_case.rb
dither-0.0.13-java lib/dither/test_case.rb
dither-0.0.13 lib/dither/test_case.rb
dither-0.0.12-java lib/dither/test_case.rb
dither-0.0.12 lib/dither/test_case.rb
dither-0.0.11-java lib/dither/test_case.rb
dither-0.0.11 lib/dither/test_case.rb