Sha256: 1abf77e3c1d9b4b237a814ccbd8c6cb6b85eeaafd83f075debbbb8dc3d781bc6

Contents?: true

Size: 946 Bytes

Versions: 23

Compression:

Stored size: 946 Bytes

Contents

class WithinMatcher
  defm match(expected, actual)
    delta = expected[0]
    num = expected[1]
    self.result = abs(num - actual)
    return self.result <= delta
  end

  defm failure_message_for_match(expected, actual)
    delta = expected[0]
    num = expected[1]
    actual_str = printf("%f", actual)
    delta_str = printf("%f", delta)
    num_str = printf("%f", num)
    result_str = printf('%f', self.result)
    return "expected “#{actual_str}” to be within +/- “#{delta_str}” of “#{num_str}”, delta was “#{result_str}”"
  end

  defm failure_message_for_mismatch(expected, actual)
    delta = expected[0]
    num = expected[1]
    actual_str = printf("%f", actual)
    delta_str = printf("%f", delta)
    num_str = printf("%f", num)
    result_str = printf('%f', self.result)
    return "expected “#{actual_str}” to not be within +/- “#{delta_str}” of “#{num_str}”, delta was “#{result_str}”"
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
speckle-0.1.26 lib/matchers/within_matcher.riml
speckle-0.1.25 lib/matchers/within_matcher.riml
speckle-0.1.24 lib/matchers/within_matcher.riml
speckle-0.1.23 lib/matchers/within_matcher.riml
speckle-0.1.22 lib/matchers/within_matcher.riml
speckle-0.1.21 lib/matchers/within_matcher.riml
speckle-0.1.20 lib/matchers/within_matcher.riml
speckle-0.1.19 lib/matchers/within_matcher.riml
speckle-0.1.18 lib/matchers/within_matcher.riml
speckle-0.1.17 lib/matchers/within_matcher.riml
speckle-0.1.16 lib/matchers/within_matcher.riml
speckle-0.1.15 lib/matchers/within_matcher.riml
speckle-0.1.14 lib/matchers/within_matcher.riml
speckle-0.1.13 lib/matchers/within_matcher.riml
speckle-0.1.12 lib/matchers/within_matcher.riml
speckle-0.1.11 lib/matchers/within_matcher.riml
speckle-0.1.10 lib/matchers/within_matcher.riml
speckle-0.1.9 lib/matchers/within_matcher.riml
speckle-0.1.8 lib/matchers/within_matcher.riml
speckle-0.1.7 lib/matchers/within_matcher.riml