Class: SignedZeroMatcher

Inherits:
Object show all
Defined in:
lib/mspec/matchers/signed_zero.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_sign) ⇒ SignedZeroMatcher

Returns a new instance of SignedZeroMatcher


2
3
4
# File 'lib/mspec/matchers/signed_zero.rb', line 2

def initialize(expected_sign)
  @expected_sign = expected_sign
end

Instance Method Details

#failure_messageObject


11
12
13
# File 'lib/mspec/matchers/signed_zero.rb', line 11

def failure_message
  ["Expected #{@actual}", "to be #{"-" if @expected_sign == -1}0.0"]
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)

6
7
8
9
# File 'lib/mspec/matchers/signed_zero.rb', line 6

def matches?(actual)
  @actual = actual
  (1.0/actual).infinite? == @expected_sign
end

#negative_failure_messageObject


15
16
17
# File 'lib/mspec/matchers/signed_zero.rb', line 15

def negative_failure_message
  ["Expected #{@actual}", "not to be #{"-" if @expected_sign == -1}0.0"]
end