Created
October 5, 2016 12:48
-
-
Save jangeador/a6a236b7621fd9e894a0027dd7606d93 to your computer and use it in GitHub Desktop.
rmotr.com assignment 3
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
import unittest | |
def find_anagrams(list_of_strings, word): | |
anagrams = [] | |
for test_word in list_of_strings: | |
if ''.join(sorted(test_word)) == ''.join(sorted(word)): | |
anagrams.append(test_word) | |
return anagrams | |
class AnagramsTestCase(unittest.TestCase): | |
def test_multiple_matches(self): | |
self.assertEqual(find_anagrams(["spare", "hello", "pears", "world", "reaps"], "parse"), | |
["spare", "pears", "reaps"]) | |
def test_one_match(self): | |
self.assertEqual(find_anagrams(["spared", "hello", "appears", "world", "reaps"], "parse"), | |
["reaps"]) | |
def test_no_matches(self): | |
self.assertEqual(find_anagrams(["spared", "hello", "appears", "world", "teaps"], "parse"), | |
[]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment