summary refs log tree commit diff stats
path: root/emacs-lisp/anagram
diff options
context:
space:
mode:
Diffstat (limited to 'emacs-lisp/anagram')
-rw-r--r--emacs-lisp/anagram/README.md13
-rw-r--r--emacs-lisp/anagram/anagram-test.el54
-rw-r--r--emacs-lisp/anagram/anagram.el14
3 files changed, 81 insertions, 0 deletions
diff --git a/emacs-lisp/anagram/README.md b/emacs-lisp/anagram/README.md
new file mode 100644
index 0000000..88d0118
--- /dev/null
+++ b/emacs-lisp/anagram/README.md
@@ -0,0 +1,13 @@
+# Anagram
+
+Given a word and a list of possible anagrams, select the correct sublist.
+
+Given `"listen"` and a list of candidates like `"enlists" "google"
+"inlets" "banana"` the program should return a list containing
+`"inlets"`.
+## Source
+
+Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
diff --git a/emacs-lisp/anagram/anagram-test.el b/emacs-lisp/anagram/anagram-test.el
new file mode 100644
index 0000000..1fa4a94
--- /dev/null
+++ b/emacs-lisp/anagram/anagram-test.el
@@ -0,0 +1,54 @@
+;;; anagram-test.el --- Tests for Anagram (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(load-file "anagram.el")
+
+(ert-deftest no-matches ()
+  (should (equal '() (anagrams-for
+                      "diaper"
+                      '("hello" "world" "zombies" "pants")))))
+
+(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 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")))))
+
+(ert-deftest word-is-not-own-anagram ()
+  (should (equal '()
+                 (anagrams-for
+                  "banana"
+                  '("banana")))))
+
+
+(provide 'anagram-test)
+;;; anagram-test.el ends here
diff --git a/emacs-lisp/anagram/anagram.el b/emacs-lisp/anagram/anagram.el
new file mode 100644
index 0000000..0d0c333
--- /dev/null
+++ b/emacs-lisp/anagram/anagram.el
@@ -0,0 +1,14 @@
+;;; anagram.el --- Anagram (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'cl-lib)
+
+(defun anagrams-for(word list)
+  (list "tan"))
+
+
+(provide 'anagram)
+;;; anagram.el ends here