Skip to content

Instantly share code, notes, and snippets.

@katiebuilds
Created February 11, 2015 14:10
Show Gist options
  • Save katiebuilds/f1262008c5e608363d34 to your computer and use it in GitHub Desktop.
Save katiebuilds/f1262008c5e608363d34 to your computer and use it in GitHub Desktop.
Palindromes...passes all tests
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts one parameter. The method should return true if
# the string passed to it is a palindrome. It should return false if the string
# is not a palindrome
# WRITE YOUR CODE HERE.
def palindrome?(string)
s = string.downcase.split.join
if s.reverse == s
return true
else
return false
end
end
class StringPalindromePuzzle < MiniTest::Test
def test_words
assert palindrome?("tacocat")
assert palindrome?("anna")
assert palindrome?("racecar")
end
def test_bad_words
refute palindrome?("ruby")
refute palindrome?("cowboy")
refute palindrome?("Ruby")
refute palindrome?("Cowboy")
end
def test_capitalization
assert palindrome?("Tacocat")
assert palindrome?("Anna")
assert palindrome?("RacEcAr")
end
def test_sentences
assert palindrome?("Stressed desserts")
assert palindrome?("Stop on no pots")
refute palindrome?("The quick brown fox")
end
def test_spaces
assert palindrome?("Mad as Adam")
assert palindrome?("Sums are not set as a test on Erasmus")
refute palindrome?("Where the heck did you get these sentences?")
end
end
@masonfmatthews
Copy link

Katie -

Nice. The only change I'd make is that you don't need lines 12-15. Your == call already returns true or false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment