commit 5fb38c0bcc5930435ac4d8ff7442d9a8854be03d
parent 931b7618a4964d77652c294cf527db890cb4be61
Author: dwrz <dwrz@dwrz.net>
Date: Sun, 6 Jan 2019 21:13:23 +0000
Add elisp/two-fer
Diffstat:
3 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/elisp/two-fer/README.md b/elisp/two-fer/README.md
@@ -0,0 +1,19 @@
+# Two Fer
+
+`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
+
+```text
+"One for X, one for me."
+```
+
+When X is a name or "you".
+
+If the given name is "Alice", the result should be "One for Alice, one for me."
+If no name is given, the result should be "One for you, one for me."
+
+## Source
+
+[https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
diff --git a/elisp/two-fer/two-fer-test.el b/elisp/two-fer/two-fer-test.el
@@ -0,0 +1,21 @@
+;;; two-fer-test.el --- Tests for Two-fer (exercism)
+
+;;; Commentary:
+;; Common test data version: 1.2.0 4fc1acb
+
+;;; Code:
+
+(load-file "two-fer.el")
+
+(ert-deftest no-name-given ()
+ (should (equal (two-fer) "One for you, one for me.")))
+
+(ert-deftest a-name-given ()
+ (should (equal (two-fer "Alice") "One for Alice, one for me.")))
+
+(ert-deftest another-name-given ()
+ (should (equal (two-fer "Bob") "One for Bob, one for me.")))
+
+(provide 'two-fer-test)
+
+;;; two-fer-test.el ends here
diff --git a/elisp/two-fer/two-fer.el b/elisp/two-fer/two-fer.el
@@ -0,0 +1,15 @@
+;;; two-fer.el --- Two-fer Exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(provide 'two-fer)
+
+(defun two-fer(&optional name)
+ "Return a twofer phrase as a formatted string.
+NAME, if provided, is used to specify the first recipient;
+it defaults to 'you'."
+ (if (not name) (setq name "you"))
+ (format "One for %s, one for me." name))
+;;; two-fer.el ends here