-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c943bda
commit 8977040
Showing
2 changed files
with
125 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,93 @@ | ||
(ns anagram-test | ||
(:require [clojure.test :refer [deftest is]] | ||
(:require [clojure.test :refer [deftest testing is]] | ||
anagram)) | ||
|
||
(deftest no-matches | ||
(is (= [] | ||
(anagram/anagrams-for "diaper" ["hello" "world" "zombies" "pants"])))) | ||
(testing "No matches" | ||
(is (= [] | ||
(anagram/anagrams-for "diaper" ["hello" "world" "zombies" "pants"]))))) | ||
|
||
(deftest detect-simple-anagram | ||
(is (= ["tan"] (anagram/anagrams-for "ant" ["tan" "stand" "at"])))) | ||
(deftest detects-two-anagrams | ||
(testing "Detects two anagrams" | ||
(is (= ["lemons", "melons"] | ||
(anagram/anagrams-for "solemn" ["lemons", "cherry", "melons"]))))) | ||
|
||
(deftest does-not-confuse-different-duplicates | ||
(is (= [] (anagram/anagrams-for "galea" ["eagle"])))) | ||
(deftest does-not-detect-anagram-subsets | ||
(testing "Does not detect anagram subsets" | ||
(is (= [] | ||
(anagram/anagrams-for "good" ["dog", "goody"]))))) | ||
|
||
(deftest eliminate-anagram-subsets | ||
(is (= [] (anagram/anagrams-for "good" ["dog" "goody"])))) | ||
(deftest detects-anagram | ||
(testing "Detects anagram" | ||
(is (= ["inlets"] | ||
(anagram/anagrams-for "listen" ["enlists", "google", "inlets", "banana"]))))) | ||
|
||
(deftest detect-anagram | ||
(is (= ["inlets"] | ||
(let [coll ["enlists" "google" "inlets" "banana"]] | ||
(anagram/anagrams-for "listen" coll))))) | ||
(deftest detects-three-anagrams | ||
(testing "Detects three anagrams" | ||
(is (= ["gallery", "regally", "largely"] | ||
(anagram/anagrams-for "allergy" ["gallery", "ballerina", "regally", "clergy", "largely", "leading"]))))) | ||
|
||
(deftest multiple-anagrams | ||
(is (= ["gallery" "regally" "largely"] | ||
(let [coll ["gallery" "ballerina" "regally" | ||
"clergy" "largely" "leading"]] | ||
(anagram/anagrams-for "allergy" coll))))) | ||
(deftest detects-multiple-anagrams-with-different-case | ||
(testing "Detects multiple anagrams with different case" | ||
(is (= ["Eons", "ONES"] | ||
(anagram/anagrams-for "nose" ["Eons", "ONES"]))))) | ||
|
||
(deftest case-insensitive-anagrams | ||
(is (= ["Carthorse"] | ||
(let [coll ["cashregister" "Carthorse" "radishes"]] | ||
(anagram/anagrams-for "Orchestra" coll))))) | ||
(deftest does-not-detect-non-anagrams-with-identical-checksum | ||
(testing "Does not detect non-anagrams with identical checksum" | ||
(is (= [] | ||
(anagram/anagrams-for "mass" ["last"]))))) | ||
|
||
(deftest word-is-not-own-anagram | ||
(is (= [] (anagram/anagrams-for "banana" ["banana"])))) | ||
(deftest detects-anagrams-case-insensitively | ||
(testing "Detects anagrams case-insensitively" | ||
(is (= ["Carthorse"] | ||
(anagram/anagrams-for "Orchestra" ["cashregister", "Carthorse", "radishes"]))))) | ||
|
||
(deftest capital-word-is-not-own-anagram | ||
(is (= [] (anagram/anagrams-for "BANANA" ["banana"])))) | ||
(deftest detects-anagrams-using-case-insensitive-subject | ||
(testing "Detects anagrams using case-insensitive subject" | ||
(is (= ["carthorse"] | ||
(anagram/anagrams-for "Orchestra" ["cashregister", "carthorse", "radishes"]))))) | ||
|
||
(deftest detects-anagrams-using-case-insensitive-possible-matches | ||
(testing "Detects anagrams using case-insensitive possible matches" | ||
(is (= ["Carthorse"] | ||
(anagram/anagrams-for "orchestra" ["cashregister", "Carthorse", "radishes"]))))) | ||
|
||
(deftest does-not-detect-anagram-if-original-word-is-repeated | ||
(testing "Does not detect an anagram if the original word is repeated" | ||
(is (= [] | ||
(anagram/anagrams-for "go" ["goGoGO"]))))) | ||
|
||
(deftest anagrams-must-use-all-letters-exactly-once | ||
(testing "Anagrams must use all letters exactly once" | ||
(is (= [] | ||
(anagram/anagrams-for "tapper" ["patter"]))))) | ||
|
||
(deftest words-are-not-anagrams-of-themselves | ||
(testing "Words are not anagrams of themselves" | ||
(is (= [] | ||
(anagram/anagrams-for "BANANA" ["BANANA"]))))) | ||
|
||
(deftest words-are-not-anagrams-of-themselves-even-if-letter-case-is-partially-different | ||
(testing "Words are not anagrams of themselves even if letter case is partially different" | ||
(is (= [] | ||
(anagram/anagrams-for "BANANA" ["Banana"]))))) | ||
|
||
(deftest words-are-not-anagrams-of-themselves-even-if-letter-case-is-completely-different | ||
(testing "Words are not anagrams of themselves even if letter case is completely different" | ||
(is (= [] | ||
(anagram/anagrams-for "BANANA" ["banana"]))))) | ||
|
||
(deftest words-other-than-themselves-can-be-anagrams | ||
(testing "Words other than themselves can be anagrams" | ||
(is (= ["Silent"] | ||
(anagram/anagrams-for "LISTEN" ["LISTEN", "Silent"]))))) | ||
|
||
(deftest handles-greek-letters | ||
(testing "Handles case of greek letters" | ||
(is (= ["ΒΓΑ", "γβα"] | ||
(anagram/anagrams-for "ΑΒΓ" ["ΒΓΑ", "ΒΓΔ", "γβα", "αβγ"]))))) | ||
|
||
(deftest different-characters-may-have-same-bytes | ||
(testing "Different characters may have the same bytes" | ||
(is (= [] | ||
(anagram/anagrams-for "a⬂" ["€a"]))))) |