Skip to content

Instantly share code, notes, and snippets.

@SolomonHD
Created February 25, 2015 14:13
Show Gist options
  • Save SolomonHD/156e4b30c04221c6adc5 to your computer and use it in GitHub Desktop.
Save SolomonHD/156e4b30c04221c6adc5 to your computer and use it in GitHub Desktop.
Palindrome
require 'minitest/autorun'
require 'minitest/pride'
def palindrome?(input)
input.downcase!
array = input.split(" ")
array = array.join
input2 = array.to_s
if input2 == input2.reverse
return true
else
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment