-
-
Save 7wQvRTU2/3c95e82943d2640986fe6bf53a73cb01 to your computer and use it in GitHub Desktop.
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 AnagramCheck | |
def initialize (word1, word2) | |
@argument = word1, word2 | |
@word1 = word1.gsub(/[!@#$%^&*'.\s]/,"").upcase.split('') | |
@word2 = word2.gsub(/[!@#$%^&*'.\s]/,"").upcase.split('') | |
end | |
def word_check | |
words = @word1, @word2 | |
vowels = ["A", "E", "I", "O", "U", "Y"] | |
words.each do |word| | |
puts word.inspect | |
if !word.any? {|letter| vowels.include?(letter)} | |
#how to call original argument variable? | |
#why does return "#{words[i].join('')} isn't a real word" give "undefined local variable words" as an error in rspec? | |
return "Enter a real word!" | |
end | |
end | |
return anagram_check() | |
end | |
def anagram_check | |
anagram = @word1 - @word2 | |
if @word1.length === @word2.length && anagram === [] | |
return "Anagram!" | |
else | |
return antigram_check() | |
end | |
end | |
def antigram_check | |
antigram = @word1 - @word2 | |
if antigram.length === @word1.length | |
return "Antigram!" | |
else return ("Not an Anagram or an Antigram but " + (@word1 - antigram).join(',') + " " + "are alike") | |
end | |
end | |
end |
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
require ('rspec') | |
require('anagram_test') | |
require ('pry') | |
describe('#anagram_check') do | |
it("checks to see if inputted words are anagrams") do | |
testing = AnagramCheck.new("steal", "least") | |
expect(testing.anagram_check()).to(eq("Anagram!")) | |
end | |
it("returns true if 2 words are an anagram of each other regardless of case") do | |
testing = AnagramCheck.new("sTeaL", "LeASt") | |
expect(testing.anagram_check()).to(eq("Anagram!")) | |
end | |
it("returns true if 2 phrases are an anagram of eachother, regardless of special characters and spacing") do | |
testing = AnagramCheck.new("Jim Morrison!", "Mr. Mojo Risin'") | |
expect(testing.anagram_check()).to(eq("Anagram!")) | |
end | |
it("returns similar letters if not an anagram") do | |
testing = AnagramCheck.new("quick", "quack'") | |
expect(testing.anagram_check()).to(eq("Not an Anagram or an Antigram but " + (@word1 - antigram).join(',') + " " + "are alike")) | |
end | |
end | |
describe('#word_check') do | |
it("checks to see if inputted words are real words") do | |
testing = AnagramCheck.new("zrrb", "Least") | |
expect(testing.word_check()).to(eq("Enter a real word!")) | |
end | |
end | |
describe('#antigram_check') do | |
it("checks to see if inputted words are antigrams") do | |
testing = AnagramCheck.new("Barn", "Fly") | |
expect(testing.antigram_check()).to(eq("Antigram!")) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment