diff --git a/src/rhymes_with/rhymes.py b/src/rhymes_with/rhymes.py index 222b020..1bff2b1 100644 --- a/src/rhymes_with/rhymes.py +++ b/src/rhymes_with/rhymes.py @@ -1,4 +1,11 @@ def does_rhyme(word1: str, word2: str, length: int = 3) -> bool: + """ + :returns: True if word1 and word2 rhymes. + """ + return does_perfectly_rhyme(word1, word2) or does_pararhyme(word1, word2) + + +def does_perfectly_rhyme(word1: str, word2: str, length: int = 3) -> bool: """ :returns: True iff word1 and word2 has the same ending up to length. @@ -7,6 +14,26 @@ def does_rhyme(word1: str, word2: str, length: int = 3) -> bool: return word1[-length:] == word2[-length:] +def does_pararhyme(word1: str, word2: str) -> bool: + """ + :returns: True if word1 and word2 has mathcing + consonants. + """ + + if not (len(word1) == len(word2)): + return False + + for letter1, letter2 in zip(word1, word2): + if not letter1 == letter2 and not is_vowels(letter1, letter2): + return False + return True + + +def is_vowels(letter1, letter2): + vovels = ["a", "e", "i", "o", "u"] + return letter1 in vovels and letter2 in vovels + + def filter_rhymes(word: str, dictionary: [str]) -> [str]: """ :returns: the strings in dictionary that does_rhyme diff --git a/tests/test_rhymes.py b/tests/test_rhymes.py index 71c219e..c8ea41a 100644 --- a/tests/test_rhymes.py +++ b/tests/test_rhymes.py @@ -3,3 +3,11 @@ def test_cook_rhymes_with_book(): assert does_rhyme("book", "cook") + + +def test_tick_pararhymes_with_tock(): + assert does_rhyme("tick", "tock") + + +def test_ticks_does_not_pararhymes_with_tock(): + assert not does_rhyme("ticks", "tock")