Sha256: 3839b2d9103fd4c1abc8dc35d243efbaf97107b6a21e957852e6f3e216583f33

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

class NumericValues < ValuesBase

  def self.numerics_in_range(range)
    self.verify_range_not_empty('range', range)
    self.verify_kind_of('range.first', Numeric, range.first)
    self.verify_kind_of('range.last', Numeric, range.last)
    {
        :min_value => range.first,
        :max_value => range.last
    }
  end

  def self.numerics_not_in_range(range)
    self.verify_range_not_empty('range', range)
    if range.first > range.last
      inverted = true
      first, last = range.last, range.first
    else
      inverted = false
      first, last = range.first, range.last
    end
    case
      when first.respond_to?(:pred)
        too_small = first.pred
      when first.respond_to?(:prev_float)
        self.verify_finite_numeric(inverted ? 'range.last' : 'range.first', first)
        too_small = first.prev_float
      else
        raise TypeError.new(first)
    end
    case
      when last.respond_to?(:succ)
        too_large = last.succ
      when last.respond_to?(:next_float)
        self.verify_finite_numeric(inverted ? 'range.first' : 'range.last', last)
        too_large = last.next_float
      else
        raise ArgumentError.new(last)
    end
    {
        :too_small => too_small,
        :too_large => too_large,
    }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
test_values-0.4.0 lib/test_values/numeric_values.rb