Skip to content

Instantly share code, notes, and snippets.

@aellispierce
Last active August 29, 2015 14:15
Show Gist options
  • Save aellispierce/5f9badce12902cb57a68 to your computer and use it in GitHub Desktop.
Save aellispierce/5f9badce12902cb57a68 to your computer and use it in GitHub Desktop.
Palindrome Puzzle
def palindrome?(word)
if word.downcase == word.downcase.reverse
result = true
else
result = false
end
result
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment