Skip to content

Commit

Permalink
Sync anagram tests (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras authored May 6, 2024
1 parent 11bffb1 commit fd47135
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 37 deletions.
24 changes: 24 additions & 0 deletions exercises/practice/anagram/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,36 @@ description = "detects anagrams using case-insensitive possible matches"

[7cc195ad-e3c7-44ee-9fd2-d3c344806a2c]
description = "does not detect an anagram if the original word is repeated"
include = false

[630abb71-a94e-4715-8395-179ec1df9f91]
description = "does not detect an anagram if the original word is repeated"
reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c"

[9878a1c9-d6ea-4235-ae51-3ea2befd6842]
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"

4 changes: 4 additions & 0 deletions exercises/practice/anagram/src/anagram.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(defmodule anagram
(export (find 2)))

; Please implement the find function
91 changes: 54 additions & 37 deletions exercises/practice/anagram/test/anagram-tests.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,57 @@
(include-lib "ltest/include/ltest-macros.lfe")

(deftest no-matches
(is-equal () (anagram:find "diaper" '("hello" "world" "zombies" "pants"))))

(deftest detect-simple-anagram
(is-equal '("tan") (anagram:find "ant" '("tan" "stand" "at"))))

(deftest does-not-confuse-different-duplicates
(is-equal () (anagram:find "galea" '("eagle"))))

(deftest eliminate-angram-subsets
(is-equal () (anagram:find "good" '("dog" "goody"))))

(deftest detect-anagram
(is-equal
'("inlets")
(anagram:find "listen" '("enlists" "google" "inlets" "banana"))))

(deftest multiple-anagrams
(is-equal
'("gallery" "regally" "largely")
(anagram:find
"allergy"
'("gallery" "ballerina" "regally" "clergy" "largely" "leading"))))

(deftest case-insensitive-subject
(is-equal
'("carthorse")
(anagram:find "Orchestra" '("cashregister" "carthorse" "radishes"))))

(deftest case-insensitive-candidate
(is-equal
'("Carthorse")
(anagram:find "Orchestra" '("cashregister" "Carthorse" "radishes"))))

(deftest does-not-detect-a-word-as-its-own-anagram
(is-equal
'("cron")
(anagram:find "corn" '("corn" "dark" "Corn" "rank" "CORN" "cron" "park"))))
(is-equal '()
(anagram:find "diaper" '("hello" "world" "zombies" "pants"))))

(deftest detects-two-anagrams
(is-equal '("lemons" "melons")
(anagram:find "solemn" '("lemons" "cherry" "melons"))))

(deftest does-not-detect-anagram-subsets
(is-equal '() (anagram:find "good" '("dog" "goody"))))

(deftest detects-anagram
(is-equal '("inlets")
(anagram:find "listen" '("enlists" "google" "inlets" "banana"))))

(deftest detects-three-anagrams
(is-equal '("gallery" "regally" "largely")
(anagram:find "allergy"
'("gallery" "ballerina" "regally" "clergy" "largely" "leading"))))

(deftest detects-multiple-anagrams-with-different-case
(is-equal '("Eons" "ONES") (anagram:find "nose" '("Eons" "ONES"))))

(deftest does-not-detect-non-anagrams-with-identical-checksum
(is-equal '() (anagram:find "mass" '("last"))))

(deftest detects-anagrams-case-insensitively
(is-equal '("Carthorse")
(anagram:find "Orchestra" '("cashregister" "Carthorse" "radishes"))))

(deftest detects-anagrams-using-case-insensitive-subject
(is-equal '("carthorse")
(anagram:find "Orchestra" '("cashregister" "carthorse" "radishes"))))

(deftest detects-anagrams-using-case-insensitive-possible-matches
(is-equal '("Carthorse")
(anagram:find "orchestra" '("cashregister" "Carthorse" "radishes"))))

(deftest does-not-detect-an-anagram-if-the-original-word-is-repeated
(is-equal '() (anagram:find "go" '("goGoGO"))))

(deftest anagrams-must-use-all-letters-exactly-once
(is-equal '() (anagram:find "tapper" '("patter"))))

(deftest words-are-not-anagrams-of-themselves
(is-equal '() (anagram:find "BANANA" '("BANANA"))))

(deftest words-are-not-anagrams-of-themselves-even-if-letter-case-is-partially-different
(is-equal '() (anagram:find "BANANA" '("Banana"))))

(deftest words-are-not-anagrams-of-themselves-even-if-letter-case-is-completely-different
(is-equal '() (anagram:find "BANANA" '("banana"))))

(deftest words-other-than-themselves-can-be-anagrams
(is-equal '("Silent") (anagram:find "LISTEN" '("LISTEN" "Silent"))))

0 comments on commit fd47135

Please sign in to comment.