Created
June 7, 2017 23:01
-
-
Save leandroh/dba786bc48e4a2a602e11f2507ebaa12 to your computer and use it in GitHub Desktop.
Check if two words are anagram in Ruby
This file contains 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
class Anagram | |
def is_anagram?(one, other) | |
one.downcase.chars.sort.join == other.downcase.chars.sort.join | |
end | |
end | |
require 'minitest/autorun' | |
describe Anagram do | |
before do | |
@anagram = Anagram.new | |
end | |
describe '.is_it?' do | |
describe 'when asked if it is an anagram' do | |
it 'must respond positively' do | |
one = 'amor' | |
other = 'roma' | |
@anagram.is_anagram?(one, other).must_equal true | |
end | |
end | |
describe 'when asked if a capital letter is an anagram' do | |
it 'must respond positively' do | |
one = 'Celia' | |
other = 'Alice' | |
@anagram.is_anagram?(one, other).must_equal true | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment