Module: Philiprehberger::Approx::RSpecMatchers

Defined in:
lib/philiprehberger/approx/rspec_matchers.rb

Defined Under Namespace

Classes: BeApproxMatcher, BeApproxWithinMatcher

Instance Method Summary collapse

Instance Method Details

#be_approx(expected, epsilon: Float::EPSILON) ⇒ Object

Matcher for approximate equality using epsilon

Examples:

expect(1.0).to be_approx(1.0 + 1e-10)
expect(1.0).to be_approx(1.05, epsilon: 0.1)


11
12
13
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 11

def be_approx(expected, epsilon: Float::EPSILON)
  BeApproxMatcher.new(expected, epsilon)
end

#be_approx_within(expected, abs: nil, rel: nil, percent: nil) ⇒ Object

Matcher for approximate equality using abs, rel, or percent tolerance

Examples:

expect(1.0).to be_approx_within(1.001, abs: 0.01)
expect(1_000_000.0).to be_approx_within(1_000_001.0, rel: 1e-5)
expect(100.0).to be_approx_within(105.0, percent: 10)


21
22
23
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 21

def be_approx_within(expected, abs: nil, rel: nil, percent: nil)
  BeApproxWithinMatcher.new(expected, abs, rel, percent)
end