Created
December 3, 2018 14:45
-
-
Save mackwic/3e592867b1d80a785359af7b9969e815 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
import unittest | |
class Dictionnary: | |
def __init__(self): | |
self._words = [] | |
def add(self, word): | |
self._words.append(word) | |
def anagrams(self, word): | |
res = [] | |
for curr_word in self._words: | |
if set(curr_word) == set(word): | |
res = [curr_word] | |
return res | |
class TestDictionnary(unittest.TestCase): | |
def setUp(self): | |
self.dictionnary = Dictionnary() | |
def test_yeild_an_empty_list_when_no_anagram_found(self): | |
self.assertListEqual(self.dictionnary.anagrams('notaword'), []) | |
def test_returns_a_known_anagram(self): | |
self.dictionnary.add('cinema') | |
self.assertListEqual(self.dictionnary.anagrams('iceman'), ['cinema']) | |
def test_returns_any_known_anagram(self): | |
self.dictionnary.add('cinema') | |
self.dictionnary.add('life') | |
self.assertListEqual(self.dictionnary.anagrams('file'), ['life']) | |
def test_returns_several_known_anagrams(self): | |
self.dictionnary.add('cinema') | |
self.dictionnary.add('anemic') | |
self.assertListEqual(self.dictionnary.anagrams('iceman'), ['cinema', 'anemic']) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment