Created
February 11, 2015 14:10
-
-
Save katiebuilds/f1262008c5e608363d34 to your computer and use it in GitHub Desktop.
Palindromes...passes all tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Katie -
Nice. The only change I'd make is that you don't need lines 12-15. Your == call already returns true or false.