forked from exercism/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanagram_test.py
More file actions
63 lines (46 loc) · 2.36 KB
/
anagram_test.py
File metadata and controls
63 lines (46 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import unittest
from anagram import find_anagrams
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0
class AnagramTest(unittest.TestCase):
def test_no_matches(self):
candidates = ["hello", "world", "zombies", "pants"]
self.assertEqual(find_anagrams("diaper", candidates), [])
def test_detects_two_anagrams(self):
candidates = ["stream", "pigeon", "maters"]
self.assertEqual(
find_anagrams("master", candidates), ["stream", "maters"])
def test_does_not_detect_anagram_subsets(self):
self.assertEqual(find_anagrams("good", ["dog", "goody"]), [])
def test_detects_anagram(self):
candidates = ["enlists", "google", "inlets", "banana"]
self.assertEqual(find_anagrams("listen", candidates), ["inlets"])
def test_detects_three_anagrams(self):
candidates = [
"gallery", "ballerina", "regally", "clergy", "largely", "leading"
]
self.assertEqual(
find_anagrams("allergy", candidates),
["gallery", "regally", "largely"])
def test_does_not_detect_non_anagrams_with_identical_checksum(self):
self.assertEqual(find_anagrams("mass", ["last"]), [])
def test_detects_anagrams_case_insensitively(self):
candidates = ["cashregister", "Carthorse", "radishes"]
self.assertEqual(
find_anagrams("Orchestra", candidates), ["Carthorse"])
def test_detects_anagrams_using_case_insensitive_subject(self):
candidates = ["cashregister", "carthorse", "radishes"]
self.assertEqual(
find_anagrams("Orchestra", candidates), ["carthorse"])
def test_detects_anagrams_using_case_insensitive_possible_matches(self):
candidates = ["cashregister", "Carthorse", "radishes"]
self.assertEqual(
find_anagrams("orchestra", candidates), ["Carthorse"])
def test_does_not_detect_a_anagram_if_the_original_word_is_repeated(self):
self.assertEqual(find_anagrams("go", ["go Go GO"]), [])
def test_anagrams_must_use_all_letters_exactly_once(self):
self.assertEqual(find_anagrams("tapper", ["patter"]), [])
def test_words_are_not_anagrams_of_themselves_case_insensitive(self):
candidates = ["BANANA", "Banana", "banana"]
self.assertEqual(find_anagrams("BANANA", candidates), [])
if __name__ == '__main__':
unittest.main()