Class: ErgomentumRspec::Matchers::Array::StrictlyDecreasing

Inherits:
Object
  • Object
show all
Defined in:
lib/ergomentum_rspec/matchers/array/be_strictly_decreasing.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



25
26
27
# File 'lib/ergomentum_rspec/matchers/array/be_strictly_decreasing.rb', line 25

def description
  "be strictly decreasing"
end

#failure_messageObject



17
18
19
# File 'lib/ergomentum_rspec/matchers/array/be_strictly_decreasing.rb', line 17

def failure_message
  "expected array #{@actual.inspect} to be strictly decreasing"
end

#failure_message_when_negatedObject



21
22
23
# File 'lib/ergomentum_rspec/matchers/array/be_strictly_decreasing.rb', line 21

def failure_message_when_negated
  "expected array #{@actual.inspect} to not be strictly decreasing"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/ergomentum_rspec/matchers/array/be_strictly_decreasing.rb', line 11

def matches?(actual)
  @actual = actual
  derivative = actual.each_cons(2).map { |x, y| y <=> x }
  derivative.all?(&:negative?)
end