Files
python/exercises/practice/anagram/anagram_test.py
BethanyG be794198e1 [Resistor Color Expert]: Corrected Small Typos (#3469)
* Corrected small typos around resistor bands.

* Due to failing CI, alterations to the test generator script were needed.
The generated vs submitted diff now skips the first three lines of the file
so that the generation date is not picked up and flagged as needing regeneration.

Sadly, a workaround was also needed to prevent Python difflib from noting the difference
anyways and producing an empty "false positive" diff.

All templates and test files also needed to be altered to ensure that the first three
lines of every test file will always be the autogeneration comment and date.

Hopefully, this will now stop the CI failures without creating any subtle additional bugs.

* Touch up to bowling template.  Added back the error raising utility.
* Touch up to two-bucket template to add back in error raising utility.
[no important files changed]
2023-07-21 16:54:40 -07:00

96 lines
3.7 KiB
Python

# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/anagram/canonical-data.json
# File last updated on 2023-07-20
import unittest
from anagram import (
find_anagrams,
)
class AnagramTest(unittest.TestCase):
def test_no_matches(self):
candidates = ["hello", "world", "zombies", "pants"]
expected = []
self.assertCountEqual(find_anagrams("diaper", candidates), expected)
def test_detects_two_anagrams(self):
candidates = ["lemons", "cherry", "melons"]
expected = ["lemons", "melons"]
self.assertCountEqual(find_anagrams("solemn", candidates), expected)
def test_does_not_detect_anagram_subsets(self):
candidates = ["dog", "goody"]
expected = []
self.assertCountEqual(find_anagrams("good", candidates), expected)
def test_detects_anagram(self):
candidates = ["enlists", "google", "inlets", "banana"]
expected = ["inlets"]
self.assertCountEqual(find_anagrams("listen", candidates), expected)
def test_detects_three_anagrams(self):
candidates = ["gallery", "ballerina", "regally", "clergy", "largely", "leading"]
expected = ["gallery", "regally", "largely"]
self.assertCountEqual(find_anagrams("allergy", candidates), expected)
def test_detects_multiple_anagrams_with_different_case(self):
candidates = ["Eons", "ONES"]
expected = ["Eons", "ONES"]
self.assertCountEqual(find_anagrams("nose", candidates), expected)
def test_does_not_detect_non_anagrams_with_identical_checksum(self):
candidates = ["last"]
expected = []
self.assertCountEqual(find_anagrams("mass", candidates), expected)
def test_detects_anagrams_case_insensitively(self):
candidates = ["cashregister", "Carthorse", "radishes"]
expected = ["Carthorse"]
self.assertCountEqual(find_anagrams("Orchestra", candidates), expected)
def test_detects_anagrams_using_case_insensitive_subject(self):
candidates = ["cashregister", "carthorse", "radishes"]
expected = ["carthorse"]
self.assertCountEqual(find_anagrams("Orchestra", candidates), expected)
def test_detects_anagrams_using_case_insensitive_possible_matches(self):
candidates = ["cashregister", "Carthorse", "radishes"]
expected = ["Carthorse"]
self.assertCountEqual(find_anagrams("orchestra", candidates), expected)
def test_does_not_detect_an_anagram_if_the_original_word_is_repeated(self):
candidates = ["go Go GO"]
expected = []
self.assertCountEqual(find_anagrams("go", candidates), expected)
def test_anagrams_must_use_all_letters_exactly_once(self):
candidates = ["patter"]
expected = []
self.assertCountEqual(find_anagrams("tapper", candidates), expected)
def test_words_are_not_anagrams_of_themselves(self):
candidates = ["BANANA"]
expected = []
self.assertCountEqual(find_anagrams("BANANA", candidates), expected)
def test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different(
self,
):
candidates = ["Banana"]
expected = []
self.assertCountEqual(find_anagrams("BANANA", candidates), expected)
def test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different(
self,
):
candidates = ["banana"]
expected = []
self.assertCountEqual(find_anagrams("BANANA", candidates), expected)
def test_words_other_than_themselves_can_be_anagrams(self):
candidates = ["LISTEN", "Silent"]
expected = ["Silent"]
self.assertCountEqual(find_anagrams("LISTEN", candidates), expected)