Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make anagram order-independent #411

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions exercises/practice/anagram/anagram-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
'())

(test-equal? "detects two anagrams"
(anagrams-for "solemn"
'("lemons" "cherry" "melons"))
(sort (anagrams-for "solemn"
'("lemons" "cherry" "melons"))
string<?)
'("lemons" "melons"))

(test-equal? "does not detect anagram subsets"
Expand All @@ -31,13 +32,21 @@
'("inlets"))

(test-equal? "detects three anagrams"
(anagrams-for "allergy"
'("gallery" "ballerina" "regally" "clergy" "largely" "leading"))
'("gallery" "regally" "largely"))
(sort (anagrams-for "allergy"
'("gallery"
"ballerina"
"regally"
"clergy"
"largely"
"leading"))
string<?)

'("gallery" "largely" "regally"))

(test-equal? "detects multiple anagrams with different case"
(anagrams-for "nose"
'("Eons" "ONES"))
(sort (anagrams-for "nose"
'("Eons" "ONES"))
string<?)
'("Eons" "ONES"))

(test-equal? "does not detect non-anagrams with identical checksum"
Expand All @@ -50,12 +59,12 @@
'("cashregister" "Carthorse" "radishes"))
'("Carthorse"))

(test-equal? "detects anagrams using case-insensitive subject"
(test-equal? "detects anagrams using case-insensitive subject"
(anagrams-for "Orchestra"
'("cashregister" "carthorse" "radishes"))
'("carthorse"))

(test-equal? "detects anagrams using case-insensitive possible matches"
(test-equal? "detects anagrams using case-insensitive possible matches"
(anagrams-for "orchestra"
'("cashregister" "Carthorse" "radishes"))
'("Carthorse"))
Expand All @@ -65,27 +74,26 @@
'("goGoGO"))
'())

(test-equal? "anagrams must use all letters exactly once"
(test-equal? "anagrams must use all letters exactly once"
(anagrams-for "tapper"
'("patter"))
'())

(test-equal? "words are not anagrams of themselves"
(test-equal? "words are not anagrams of themselves"
(anagrams-for "BANANA"
'("BANANA"))
'())

(test-equal? "words are not anagrams of themselves even if letter case is partially different"
(test-equal? "words are not anagrams of themselves even if letter case is partially different"
(anagrams-for "BANANA"
'("Banana"))
'())

(test-equal? "words are not anagrams of themselves even if letter case is completely different"
(test-equal? "words are not anagrams of themselves even if letter case is completely different"
(anagrams-for "BANANA"
'("banana"))
'())


(test-equal? "words other than themselves can be anagrams"
(anagrams-for "LISTEN"
'("LISTEN" "Silent"))
Expand Down