Sha256: e8bfbdb69b684b629be94584c30f1589f5e041f2ed8c98755fd7501e34affd31

Contents?: true

Size: 749 Bytes

Versions: 3

Compression:

Stored size: 749 Bytes

Contents

module RSpec::Matchers::BuiltIn
  class BeWithin

    def of(expected)
      @expected = expected
      @unit     = ''
      if expected.is_a?(NMatrix)
        @tolerance = if @delta.is_a?(NMatrix)
                       @delta.clone
                     elsif @delta.is_a?(Array)
                       NMatrix.new(:dense, expected.shape, @delta, expected.dtype)
                     else
                       NMatrix.ones_like(expected) * @delta
                     end
      else
        @tolerance = @delta
      end

      self
    end

    def percent_of(expected)
      @expected  = expected
      @unit      = '%'
      @tolerance = @expected.abs * @delta / 100.0 # <- only change is to reverse abs and @delta
      self
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nmatrix-0.0.9 spec/rspec_monkeys.rb
nmatrix-0.0.8 spec/rspec_monkeys.rb
nmatrix-0.0.7 spec/rspec_monkeys.rb