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

Update anagram tests #286

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions exercises/practice/anagram/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ description = "anagrams must use all letters exactly once"

[85757361-4535-45fd-ac0e-3810d40debc1]
description = "words are not anagrams of themselves (case-insensitive)"
include = false

[68934ed0-010b-4ef9-857a-20c9012d1ebf]
description = "words are not anagrams of themselves"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[589384f3-4c8a-4e7d-9edc-51c3e5f0c90e]
description = "words are not anagrams of themselves even if letter case is partially different"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[ba53e423-7e02-41ee-9ae2-71f91e6d18e6]
description = "words are not anagrams of themselves even if letter case is completely different"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[a0705568-628c-4b55-9798-82e4acde51ca]
description = "words other than themselves can be anagrams"
include = false

[33d3f67e-fbb9-49d3-a90e-0beb00861da7]
description = "words other than themselves can be anagrams"
reimplements = "a0705568-628c-4b55-9798-82e4acde51ca"
89 changes: 68 additions & 21 deletions exercises/practice/anagram/anagram-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,89 @@
(require rackunit rackunit/text-ui))

(module+ test
(define allergies '("gallery" "ballerina" "regally" "clergy" "largely" "leading"))

(define suite
(test-suite
"anagram tests"

(test-equal? "no-matches"
(anagrams-for "diaper" '("hello" "world" "zombies" "pants"))
(anagrams-for "diaper"
'("hello" "world" "zombies" "pants"))
'())

(test-equal? "detect simple anagram"
(anagrams-for "ant" '("tan" "stand" "at"))
'("tan"))

(test-equal? "does not confuse different duplicates"
(anagrams-for "galea" '("eagle"))
'())
(test-equal? "detects two anagrams"
(anagrams-for "solemn"
'("lemons" "cherry" "melons"))
'("lemons" "melons"))

(test-equal? "eliminate anagram subsets"
(anagrams-for "good" '("dog" "goody"))
(test-equal? "does not detect anagram subsets"
(anagrams-for "good"
'("dog" "goody"))
'())

(test-equal? "detect anagram"
(anagrams-for "listen"'("enlists" "google" "inlets" "banana"))
(test-equal? "detects anagram"
(anagrams-for "listen"
'("enlists" "google" "inlets" "banana"))
'("inlets"))

(test-equal? "multiple-anagrams"
(anagrams-for "allergy" allergies)
(test-equal? "detects three anagrams"
(anagrams-for "allergy"
'("gallery" "ballerina" "regally" "clergy" "largely" "leading"))
'("gallery" "regally" "largely"))

(test-equal? "case-insensitive-anagrams"
(anagrams-for "Orchestra" '("cashregister" "Carthorse" "radishes"))
(test-equal? "detects multiple anagrams with different case"
(anagrams-for "nose"
'("Eons" "ONES"))
'("Eons" "ONES"))

(test-equal? "does not detect non-anagrams with identical checksum"
(anagrams-for "mass"
'("last"))
'())

(test-equal? "detects anagrams case-insensitively"
(anagrams-for "Orchestra"
'("cashregister" "Carthorse" "radishes"))
'("Carthorse"))

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

(test-equal? "detects anagrams using case-insensitive possible matches"
(anagrams-for "orchestra"
'("cashregister" "Carthorse" "radishes"))
'("Carthorse"))

(test-equal? "does not detect an anagram if the original word is repeated"
(anagrams-for "go"
'("go Go GO"))
'())

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

(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"
(anagrams-for "BANANA"
'("Banana"))
'())

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


(test-equal? "word is not own anagram"
(anagrams-for "banana"'("banana"))
'())))
(test-equal? "words other than themselves can be anagrams"
(anagrams-for "LISTEN"
'("LISTEN" "Silent"))
'("Silent"))))

(run-tests suite))
2 changes: 1 addition & 1 deletion exercises/practice/anagram/anagram.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

(provide anagrams-for)

(define (anagrams-for string possibilities)
(define (anagrams-for subject candidates)
(error "Not implemented yet"))