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

Sync anagram tests #352

Merged
merged 3 commits into from
Apr 24, 2024
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
5 changes: 5 additions & 0 deletions exercises/practice/anagram/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ 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"
Expand Down
114 changes: 68 additions & 46 deletions exercises/practice/anagram/anagram-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,91 @@

;;; Code:


(load-file "anagram.el")
(declare-function anagrams-for "anagram.el" (subject candidates))


(ert-deftest no-matches ()
(should (equal '() (anagrams-for
"diaper"
'("hello" "world" "zombies" "pants")))))
(should (equal (anagrams-for "diaper" '("hello" "world" "zombies" "pants"))
'())))


(ert-deftest detects-two-anagrams ()
(should (equal (anagrams-for "solemn" '("lemons" "cherry" "melons"))
'("lemons" "melons"))))

(ert-deftest detect-simple-anagram ()
(should (equal '("tan") (anagrams-for
"ant"
'("tan" "stand" "at")))))

(ert-deftest does-not-confuse-different-duplicates ()
(should (equal '() (anagrams-for
"galea"
'("eagle")))))
(ert-deftest does-not-detect-anagram-subsets ()
(should (equal (anagrams-for "good" '("dog" "goody"))
'())))

(ert-deftest eliminate-anagram-subsets ()
(should (equal '() (anagrams-for
"good"
'("dog" "goody")))))

(ert-deftest detect-anagram ()
(should (equal '("inlets") (anagrams-for
"listen"
'("enlists" "google" "inlets" "banana")))))

(ert-deftest multiple-anagrams ()
(should (equal '("gallery" "regally" "largely")
(anagrams-for
"allergy"
'("gallery" "ballerina" "regally" "clergy" "largely" "leading")))))

(ert-deftest case-insensitive-anagrams ()
(should (equal '("Carthorse")
(anagrams-for
"Orchestra"
'("cashregister" "Carthorse" "radishes")))))
(should (equal (anagrams-for "listen" '("enlists" "google" "inlets" "banana"))
'("inlets"))))


(ert-deftest detects-three-anagrams ()
(should (equal (anagrams-for "allergy"
'("gallery" "ballerina" "regally" "clergy" "largely" "leading"))
'("gallery" "regally" "largely"))))


(ert-deftest detects-multiple-anagrams-with-different-case ()
(should (equal (anagrams-for "nose" '("Eons" "ONES"))
'("Eons" "ONES"))))


(ert-deftest does-not-detect-non-anagram-with-identical-checksum ()
(should (equal (anagrams-for "mass" '("last"))
'())))


(ert-deftest detects-anagrams-case-insensitively ()
(should (equal (anagrams-for "Orchestra" '("cashregister" "Carthorse" "radishes"))
'("Carthorse"))))


(ert-deftest detects-anagrams-using-case-insensitive-subject ()
(should (equal (anagrams-for "Orchestra" '("cashregister" "carthorse" "radishes"))
'("carthorse"))))


(ert-deftest detects-anagrams-using-case-insensitive-possible-matches ()
(should (equal (anagrams-for "orchestra" '("cashregister" "Carthorse" "radishes"))
'("Carthorse"))))


(ert-deftest does-not-detect-anagram-if-original-word-is-repeated ()
(should (equal (anagrams-for "go" '("goGoGO"))
'())))


(ert-deftest anagrams-must-use-all-letters-exactly-once ()
(should (equal (anagrams-for "tapper" '("patter"))
'())))


(ert-deftest word-is-not-own-anagram ()
(should (equal '()
(anagrams-for
"BANANA"
'("BANANA")))))
(should (equal (anagrams-for "BANANA" '("BANANA"))
'())))


(ert-deftest word-is-not-own-anagram-if-letter-case-is-partially-different ()
(should (equal '()
(anagrams-for
"BANANA"
'("Banana")))))
(should (equal (anagrams-for "BANANA" '("Banana"))
'())))


(ert-deftest word-is-not-own-anagram-if-letter-case-is-completely-different ()
(should (equal '()
(anagrams-for
"BANANA"
'("banana")))))
(should (equal (anagrams-for "BANANA" '("banana"))
'())))


(ert-deftest words-other-than-themselves-can-be-anagrams ()
(should (equal '("Silent")
(anagrams-for
"LISTEN"
'("Listen" "Silent" "LISTEN")))))
(should (equal (anagrams-for "LISTEN" '("LISTEN" "Silent"))
'("Silent"))))


(provide 'anagram-test)
;;; anagram-test.el ends here
7 changes: 5 additions & 2 deletions exercises/practice/anagram/anagram.el
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

;;; Commentary:

(defun anagrams-for (subject candidates)
;;; Code:
)


(defun anagrams-for (subject candidates)
(error "Delete this S-Expression and write your own implementation"))


(provide 'anagram)
;;; anagram.el ends here