Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created May 16, 2021 05:08
Show Gist options
  • Save JoshCheek/9da433dde2263cdfa18ef8f94365d3a6 to your computer and use it in GitHub Desktop.
Save JoshCheek/9da433dde2263cdfa18ef8f94365d3a6 to your computer and use it in GitHub Desktop.
Some ways to pass mutant tests
# alternative solutions to https://blog.arkency.com/semantic-blind-spot-in-ruby-case-statement/
class CaseWhen
def call(number)
boundaries = [0, 4, 8, 11]
messages = ['low value', 'medium value', 'high value']
boundaries.each_cons(2).zip messages do |(low, high), desc|
return desc if low <= number && number < high
end
'invalid value'
end
end
class CaseWhen
def call(number)
case number
when 11.., ...0
'invalid value'
when ..3
'low value'
when ..7
'medium value'
else
'high value'
end
end
class CaseWhen
def call(number)
return 'low value' if 0.equal? number/4
return 'medium value' if 0.equal? number/8
return 'high value' if 0.equal? number/11
'invalid value'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment