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

Fix test for Common Lisp - Anagram #847

Merged
merged 1 commit into from
Jan 26, 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
11 changes: 7 additions & 4 deletions exercises/practice/anagram/anagram-test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
;; Define and enter a new FiveAM test-suite
(def-suite* anagram-suite)

(defun set-equal-p (set0 set1)
(null (set-exclusive-or set0 set1 :test #'equal)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some thought perhaps #'string-equal would be good here? As type-checking/documentation that these are unordered collections of strings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having reconsidered a little - I think #'equal is a reasonable choice.


(test no-matches
(is (equal nil
(anagram:anagrams-for "diaper" '("hello" "world" "zombies" "pants")))))

(test detects-two-anagrams
(is (equal '("lemons" "melons")
(is (set-equal-p '("lemons" "melons")
(anagram:anagrams-for "solemn" '("lemons" "cherry" "melons")))))

(test does-not-detect-anagram-subsets
Expand All @@ -32,13 +35,13 @@
'("enlists" "google" "inlets" "banana")))))

(test detects-three-anagrams
(is (equal '("gallery" "regally" "largely")
(is (set-equal-p '("gallery" "regally" "largely")
(anagram:anagrams-for "allergy"
'("gallery" "ballerina" "regally" "clergy"
"largely" "leading")))))

(test detects-multiple-anagrams-with-different-case
(is (equal '("Eons" "ONES") (anagram:anagrams-for "nose" '("Eons" "ONES")))))
(is (set-equal-p '("Eons" "ONES") (anagram:anagrams-for "nose" '("Eons" "ONES")))))

(test does-not-detect-non-anagrams-with-identical-checksum
(is (equal nil (anagram:anagrams-for "mass" '("last")))))
Expand Down Expand Up @@ -77,7 +80,7 @@
(is (equal '("Silent") (anagram:anagrams-for "LISTEN" '("LISTEN" "Silent")))))

(test handles-case-of-greek-letters
(is (equal '("ΒΓΑ" "γβα") (anagram:anagrams-for "ΑΒΓ" '("ΒΓΑ" "ΒΓΔ" "γβα" "αβγ")))))
(is (set-equal-p '("ΒΓΑ" "γβα") (anagram:anagrams-for "ΑΒΓ" '("ΒΓΑ" "ΒΓΔ" "γβα" "αβγ")))))

(test different-characters-may-have-the-same-bytes
(is (equal nil (anagram:anagrams-for "a⬂" '("€a")))))
Expand Down