Skip to content

Commit

Permalink
anagram: Update test cases (#443)
Browse files Browse the repository at this point in the history
Updates the test cases according to the canonical test data
and stores the test data version.
  • Loading branch information
behrtam authored Apr 2, 2017
1 parent 6084141 commit 7a84127
Showing 1 changed file with 52 additions and 48 deletions.
100 changes: 52 additions & 48 deletions exercises/anagram/anagram_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,73 @@
from anagram import detect_anagrams


# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.1

class AnagramTests(unittest.TestCase):
def test_no_matches(self):
self.assertEqual(
[],
detect_anagrams('diaper', 'hello world zombies pants'.split())
)
candidates = ["hello", "world", "zombies", "pants"]
self.assertEqual(detect_anagrams("diaper", candidates), [])

def test_detect_simple_anagram(self):
self.assertEqual(
['tan'],
detect_anagrams('ant', 'tan stand at'.split())
)
def test_detects_simple_anagram(self):
candidates = ["tan", "stand", "at"]
self.assertEqual(detect_anagrams("ant", candidates), ["tan"])

def test_detect_multiple_anagrams(self):
self.assertEqual(
['stream', 'maters'],
detect_anagrams('master', 'stream pigeon maters'.split())
)
def test_does_not_detect_false_positives(self):
self.assertEqual(detect_anagrams("galea", ["eagle"]), [])

def test_does_not_confuse_different_duplicates(self):
def test_detects_two_anagrams(self):
candidates = ["stream", "pigeon", "maters"]
self.assertEqual(
[],
detect_anagrams('galea', ['eagle'])
)
detect_anagrams("master", candidates), ["stream", "maters"])

def test_eliminate_anagram_subsets(self):
self.assertEqual(
[],
detect_anagrams('good', 'dog goody'.split())
)
def test_does_not_detect_anagram_subsets(self):
self.assertEqual(detect_anagrams("good", ["dog", "goody"]), [])

def test_detect_anagram(self):
self.assertEqual(
['inlets'],
detect_anagrams('listen', 'enlists google inlets banana'.split())
)
def test_detects_anagram(self):
candidates = ["enlists", "google", "inlets", "banana"]
self.assertEqual(detect_anagrams("listen", candidates), ["inlets"])

def test_multiple_anagrams(self):
def test_detects_three_anagrams(self):
candidates = [
"gallery", "ballerina", "regally", "clergy", "largely", "leading"
]
self.assertEqual(
'gallery regally largely'.split(),
detect_anagrams(
'allergy',
'gallery ballerina regally clergy largely leading'.split()
)
)

def test_anagrams_are_case_insensitive(self):
detect_anagrams("allergy", candidates),
["gallery", "regally", "largely"])

def test_does_not_detect_identical_words(self):
candidates = ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"]
self.assertEqual(detect_anagrams("corn", candidates), ["cron"])

def test_does_not_detect_non_anagrams_with_identical_checksum(self):
self.assertEqual(detect_anagrams("mass", ["last"]), [])

def test_detects_anagrams_case_insensitively(self):
candidates = ["cashregister", "Carthorse", "radishes"]
self.assertEqual(
['Carthorse'],
detect_anagrams('Orchestra',
'cashregister Carthorse radishes'.split())
)
detect_anagrams("Orchestra", candidates), ["Carthorse"])

def test_same_word_isnt_anagram(self):
def test_detects_anagrams_using_case_insensitive_subjec(self):
candidates = ["cashregister", "carthorse", "radishes"]
self.assertEqual(
[],
detect_anagrams('banana', ['banana'])
)
detect_anagrams("Orchestra", candidates), ["carthorse"])

def test_detects_anagrams_using_case_insensitive_possible_matches(self):
candidates = ["cashregister", "Carthorse", "radishes"]
self.assertEqual(
[],
detect_anagrams('go', 'go Go GO'.split())
)
detect_anagrams("orchestra", candidates), ["Carthorse"])

def test_does_not_detect_a_word_as_its_own_anagram(self):
self.assertEqual(detect_anagrams("banana", ["Banana"]), [])

def test_does_not_detect_a_anagram_if_the_original_word_is_repeated(self):
self.assertEqual(detect_anagrams("go", ["go Go GO"]), [])

def test_anagrams_must_use_all_letters_exactly_once(self):
self.assertEqual(detect_anagrams("tapper", ["patter"]), [])

def test_capital_word_is_not_own_anagram(self):
self.assertEqual(detect_anagrams("BANANA", ["Banana"]), [])


if __name__ == '__main__':
Expand Down

0 comments on commit 7a84127

Please sign in to comment.