class Sus::BeWithin
def call(assertions, subject)
def call(assertions, subject) assertions.nested(self) do |assertions| assertions.assert(subject < @tolerance, self) end end
def initialize(tolerance)
def initialize(tolerance) @tolerance = tolerance end
def of(value)
def of(value) tolerance = @tolerance.abs return Bounded.new(Range.new(value - tolerance, value + tolerance)) end
def percent_of(value)
def percent_of(value) tolerance = Rational(@tolerance, 100) return Bounded.new(Range.new(value - value * tolerance, value + value * tolerance)) end
def print(output)
def print(output) output.write("be within ", :variable, @tolerance, :reset) end