class Mocha::Cardinality

def <<(invocation)

def <<(invocation)
  @invocations << invocation
end

def actual_invocations

def actual_invocations
  @invocations.map(&:full_description).join
end

def allowed_any_number_of_times?

def allowed_any_number_of_times?
  required.zero? && infinite?(maximum)
end

def anticipated_times

rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
def anticipated_times
  if allowed_any_number_of_times?
    'allowed any number of times'
  elsif required.zero? && maximum.zero?
    "expected #{count(maximum)}"
  elsif required == maximum
    "expected exactly #{count(required)}"
  elsif infinite?(maximum)
    "expected at least #{count(required)}"
  elsif required.zero?
    "expected at most #{count(maximum)}"
  else
    "expected between #{required} and #{count(maximum)}"
  end
end

def at_least(count)

def at_least(count)
  update(count, INFINITY)
end

def at_most(count)

def at_most(count)
  update(0, count)
end

def count(number)

def count(number)
  case number
  when 0 then 'never'
  when 1 then 'once'
  when 2 then 'twice'
  else "#{number} times"
  end
end

def exactly(count)

def exactly(count)
  update(count, count)
end

def infinite?(number)

def infinite?(number)
  number.respond_to?(:infinite?) && number.infinite?
end

def initialize(required = 0, maximum = INFINITY)

def initialize(required = 0, maximum = INFINITY)
  update(required, maximum)
  @invocations = []
end

def invocations_allowed?

def invocations_allowed?
  @invocations.size < maximum
end

def invocations_never_allowed?

def invocations_never_allowed?
  maximum.zero?
end

def invoked_times

def invoked_times
  "invoked #{count(@invocations.size)}"
end

def needs_verifying?

def needs_verifying?
  !allowed_any_number_of_times?
end

def satisfied?

def satisfied?
  @invocations.size >= required
end

def times(range_or_count)

def times(range_or_count)
  case range_or_count
  when Range then update(range_or_count.first, range_or_count.last)
  else update(range_or_count, range_or_count)
  end
end

def update(required, maximum)

def update(required, maximum)
  @required = required
  @maximum = maximum
  self
end

def used?

def used?
  @invocations.any? || maximum.zero?
end

def verified?

def verified?
  (@invocations.size >= required) && (@invocations.size <= maximum)
end