Finished
11def find_anagrams(word, candidates):
2 pass
2 # Edge Case: Handle None inputs
3 if word is None or candidates is None:
4 return []
5
6 # Edge Case: Handle empty candidates list
7 if not candidates:
8 return []
9
10 # Normalize the target word for comparison (lowercase and sorted)
11 normalized_word = sorted(word.lower())
12 anagrams = []
13
14 # Edge Case: Handle empty target word
15 if not word:
16 for candidate in candidates:
17 # Edge Case: Candidate is also empty (not an anagram of itself)
18 if not candidate:
19 continue
20 # Edge Case: Non-empty candidate can't be anagram of empty word
21 else:
22 continue
23
24 for candidate in candidates:
25 # Edge Case: Handle None candidate
26 if candidate is None:
27 continue
28
29 # Edge Case: Candidate is the same word as target (case insensitive)
30 if candidate.lower() == word.lower():
31 continue
32
33 # Edge Case: Different lengths cannot be anagrams
34 if len(candidate) != len(word):
35 continue
36
37 # Check if candidate is an anagram by comparing sorted lowercase letters
38 if sorted(candidate.lower()) == normalized_word:
39 anagrams.append(candidate)
40
41 return anagrams
42# Handled Edge Cases: None inputs, empty candidates list, empty target word, None candidate, identical words (case insensitive), different length strings
Test NameStatus
test_anagrams_must_use_all_letters_exactly_once
Pass
test_detects_anagram
Pass
test_detects_anagrams_case_insensitively
Pass
test_detects_anagrams_using_case_insensitive_possible_matches
Pass
test_detects_anagrams_using_case_insensitive_subject
Pass
test_detects_multiple_anagrams_with_different_case
Pass
test_detects_three_anagrams
Pass
test_detects_two_anagrams
Pass
test_different_characters_may_have_the_same_bytes
Pass
test_does_not_detect_an_anagram_if_the_original_word_is_repeated
Pass
test_does_not_detect_anagram_subsets
Pass
test_does_not_detect_non_anagrams_with_identical_checksum
Pass
test_handles_case_of_greek_letters
Pass
test_no_matches
Pass
test_words_are_not_anagrams_of_themselves
Pass
test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different
Pass
test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different
Pass
test_words_other_than_themselves_can_be_anagrams
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.