summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2021-11-23 21:23:47 -0500
committerKjetil Orbekk <kj@orbekk.com>2021-11-23 21:23:47 -0500
commit5218079d3f20b16514aa10d2c21824fd391d1f0d (patch)
treecbe33e95a3da97945e676dfaab1529c68459a753
parentedba00dfa6f8d5e625207bfeff936595dd794934 (diff)
bob exercise
-rw-r--r--exercism/emacs-lisp/bob/.exercism/config.json26
-rw-r--r--exercism/emacs-lisp/bob/.exercism/metadata.json1
-rw-r--r--exercism/emacs-lisp/bob/HELP.md41
-rw-r--r--exercism/emacs-lisp/bob/README.md39
-rw-r--r--exercism/emacs-lisp/bob/bob-test.el111
-rw-r--r--exercism/emacs-lisp/bob/bob.el60
-rw-r--r--exercism/emacs-lisp/run-exercises.el7
7 files changed, 285 insertions, 0 deletions
diff --git a/exercism/emacs-lisp/bob/.exercism/config.json b/exercism/emacs-lisp/bob/.exercism/config.json
new file mode 100644
index 0000000..08a3f68
--- /dev/null
+++ b/exercism/emacs-lisp/bob/.exercism/config.json
@@ -0,0 +1,26 @@
+{
+ "blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.",
+ "authors": [
+ "canweriotnow"
+ ],
+ "contributors": [
+ "benreyn",
+ "kytrinyx",
+ "stefanv",
+ "vermiculus",
+ "yurrriq"
+ ],
+ "files": {
+ "solution": [
+ "bob.el"
+ ],
+ "test": [
+ "bob-test.el"
+ ],
+ "example": [
+ ".meta/example.el"
+ ]
+ },
+ "source": "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial.",
+ "source_url": "http://pine.fm/LearnToProgram/?Chapter=06"
+}
diff --git a/exercism/emacs-lisp/bob/.exercism/metadata.json b/exercism/emacs-lisp/bob/.exercism/metadata.json
new file mode 100644
index 0000000..f869e6c
--- /dev/null
+++ b/exercism/emacs-lisp/bob/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"emacs-lisp","exercise":"bob","id":"131571282eee4963adc8c49ca05911b1","url":"https://exercism.org/tracks/emacs-lisp/exercises/bob","handle":"orbekk","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/exercism/emacs-lisp/bob/HELP.md b/exercism/emacs-lisp/bob/HELP.md
new file mode 100644
index 0000000..b2848b0
--- /dev/null
+++ b/exercism/emacs-lisp/bob/HELP.md
@@ -0,0 +1,41 @@
+# Help
+
+## Running the tests
+
+Tests can be run several ways:
+
+1. Interactively and individually, with `M-x ert RET test-name RET`
+2. Interactively and all at once, with `M-x ert RET t RET`
+3. From the terminal, in batch mode, with `emacs -batch -l ert -l my-test.el -f ert-run-tests-batch-and-exit`
+4. Other options can be found in the docs, `C-h i m ert RET`
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit bob.el` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Emacs Lisp track's documentation](https://exercism.org/docs/tracks/emacs-lisp)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [The Emacs Wiki](http://emacswiki.org/) is invaluable. Spend lots of time here.
+- [The Emacs Editor](http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html) is the official manual for GNU Emacs.
+- IRC - there are [freenode](https://freenode.net/) channels for `#emacs`, `#prelude`, and many Emacs
+ packages, and many helpful folks around. And with emacs, IRC is as close as
+ `M-x erc`.
+- [Exercism Support](https://gitter.im/exercism/support) Gitter chat is also a good place to get help from the
+ exercism community.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/elisp) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file
diff --git a/exercism/emacs-lisp/bob/README.md b/exercism/emacs-lisp/bob/README.md
new file mode 100644
index 0000000..42b85c4
--- /dev/null
+++ b/exercism/emacs-lisp/bob/README.md
@@ -0,0 +1,39 @@
+# Bob
+
+Welcome to Bob on Exercism's Emacs Lisp Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Bob is a lackadaisical teenager. In conversation, his responses are very limited.
+
+Bob answers 'Sure.' if you ask him a question, such as "How are you?".
+
+He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).
+
+He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
+
+He says 'Fine. Be that way!' if you address him without actually saying
+anything.
+
+He answers 'Whatever.' to anything else.
+
+Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
+
+## Source
+
+### Created by
+
+- @canweriotnow
+
+### Contributed to by
+
+- @benreyn
+- @kytrinyx
+- @stefanv
+- @vermiculus
+- @yurrriq
+
+### Based on
+
+Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=06 \ No newline at end of file
diff --git a/exercism/emacs-lisp/bob/bob-test.el b/exercism/emacs-lisp/bob/bob-test.el
new file mode 100644
index 0000000..701f510
--- /dev/null
+++ b/exercism/emacs-lisp/bob/bob-test.el
@@ -0,0 +1,111 @@
+;;; bob-test.el --- ERT tests for Bob (exercism)
+
+;;; Commentary:
+;; Common test data version: 1.2.0 6dc2014
+
+;;; Code:
+
+(load-file "bob.el")
+
+
+(ert-deftest responds-to-stating-something ()
+ (should (string= "Whatever." (response-for "Tom-ay-to, tom-aaaah-to."))))
+
+(ert-deftest responds-to-shouting ()
+ (should
+ (string= "Whoa, chill out!" (response-for "WATCH OUT!"))))
+
+(ert-deftest responds-to-shouting-gibberish ()
+ (should
+ (string= "Whoa, chill out!" (response-for "FCECDFCAAB"))))
+
+(ert-deftest responds-to-asking-a-question ()
+ (should
+ (string= "Sure." (response-for "Does this cryogenic chamber make me look fat?"))))
+
+(ert-deftest responds-to-asking-a-numeric-question ()
+ (should
+ (string= "Sure." (response-for "You are, what, like 15?"))))
+
+(ert-deftest responds-to-asking-gibberish ()
+ (should
+ (string= "Sure." (response-for "fffbbcbeab?"))))
+
+(ert-deftest responds-to-talking-forcefully ()
+ (should
+ (string= "Whatever." (response-for "Let's go make out behind the gym!"))))
+
+(ert-deftest responds-to-using-acronyms-in-regular-speech ()
+ (should
+ (string= "Whatever." (response-for "It's OK if you don't want to go to the DMV."))))
+
+(ert-deftest responds-to-forceful-question ()
+ (should
+ (string= "Calm down, I know what I'm doing!" (response-for "WHAT THE HELL WERE YOU THINKING?"))))
+
+(ert-deftest responds-to-shouting-numbers ()
+ (should
+ (string= "Whoa, chill out!" (response-for "1, 2, 3, GO!"))))
+
+(ert-deftest responds-to-only-numbers ()
+ (should
+ (string= "Whatever." (response-for "1, 2, 3"))))
+
+(ert-deftest responds-to-questions-with-only-numbers ()
+ (should
+ (string= "Sure." (response-for "4?"))))
+
+(ert-deftest responds-to-shouting-with-special-chars ()
+ (should
+ (string= "Whoa, chill out!" (response-for "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"))))
+
+(ert-deftest responds-to-shouting-with-no-exclamation-mark ()
+ (should
+ (string= "Whoa, chill out!" (response-for "I HATE YOU"))))
+
+(ert-deftest responds-to-statement-containing-question-mark ()
+ (should
+ (string= "Whatever." (response-for "Ending with ? means a question."))))
+
+(ert-deftest responds-to-non-letters-with-question ()
+ (should
+ (string= "Sure." (response-for ":) ?"))))
+
+(ert-deftest responds-to-prattling-on ()
+ (should
+ (string= "Sure." (response-for "Wait! Hang on. Are you going to be OK?"))))
+
+(ert-deftest responds-to-silence ()
+ (should
+ (string= "Fine. Be that way!" (response-for ""))))
+
+(ert-deftest responds-to-prolonged-silence ()
+ (should
+ (string= "Fine. Be that way!" (response-for " "))))
+
+(ert-deftest responds-to-alternate-silence ()
+ (should
+ (string= "Fine. Be that way!" (response-for "\t\t\t\t\t\t\t\t\t\t"))))
+
+(ert-deftest responds-to-multiple-line-question ()
+ (should
+ (string= "Whatever." (response-for "\nDoes this cryogenic chamber make me look fat?\nno"))))
+
+(ert-deftest responds-to-starting-with-whitespace ()
+ (should
+ (string= "Whatever." (response-for " hmmmmmmm..."))))
+
+(ert-deftest responds-to-ending-with-whitespace ()
+ (should
+ (string= "Sure." (response-for "Okay if like my spacebar quite a bit? "))))
+
+(ert-deftest responds-to-other-whitespace ()
+ (should
+ (string= "Fine. Be that way!" (response-for "\n\r \t"))))
+
+(ert-deftest responds-to-non-question-ending-with-whitespace ()
+ (should
+ (string= "Whatever." (response-for "This is a statement ending with whitespace "))))
+
+(provide 'bob-test)
+;;;bob-test.el ends here
diff --git a/exercism/emacs-lisp/bob/bob.el b/exercism/emacs-lisp/bob/bob.el
new file mode 100644
index 0000000..1482772
--- /dev/null
+++ b/exercism/emacs-lisp/bob/bob.el
@@ -0,0 +1,60 @@
+;;; bob.el --- Bob exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+(require 'cl-macs)
+(require 'seq)
+
+(cl-defstruct (utterance (:constructor utterance-create)
+ (:copier nil))
+ is-question
+ has-uppercase
+ all-uppercase
+ has-content)
+
+(defun utterance-is-yelling (utterance)
+ (and (utterance-has-uppercase utterance)
+ (utterance-all-uppercase utterance)))
+
+(defun update-utterance (utterance c)
+ (let ((s (string c))
+ (case-fold-search nil))
+ (unless (string-match-p "[[:space:]]" s)
+ (setf (utterance-is-question utterance) (eql ?? c))
+ (setf (utterance-has-content utterance) t)
+
+ (when (string-match-p "[[:upper:]]" s)
+ (setf (utterance-has-uppercase utterance) t))
+
+ (when (string-match-p "[[:lower:]]" s)
+ (setf (utterance-all-uppercase utterance) nil)))
+
+ utterance))
+
+(defun response-for (message)
+ (let* ((utterance
+ (seq-reduce
+ 'update-utterance
+ message
+ (utterance-create
+ :is-question nil
+ :has-uppercase nil
+ :all-uppercase t
+ :has-content nil)))
+ (is-question (utterance-is-question utterance))
+ (is-yelling (utterance-is-yelling utterance)))
+ (cond
+ ((not (utterance-has-content utterance))
+ "Fine. Be that way!")
+ ((and is-question is-yelling)
+ "Calm down, I know what I'm doing!")
+ ((and is-question (not is-yelling))
+ "Sure.")
+ ((and (not is-question) is-yelling)
+ "Whoa, chill out!" )
+ ((and (not is-question) (not is-yelling))
+ "Whatever." ))))
+
+(provide 'bob)
+;;; bob.el ends here
diff --git a/exercism/emacs-lisp/run-exercises.el b/exercism/emacs-lisp/run-exercises.el
index b243f0e..5095afa 100644
--- a/exercism/emacs-lisp/run-exercises.el
+++ b/exercism/emacs-lisp/run-exercises.el
@@ -59,4 +59,11 @@
(kj-display "RNA transcription"
(to-rna "GGACGGATTCTG"))
+(load-file "bob/bob.el")
+(kj-display "Teenager bob"
+ (response-for "What do you think?")
+ (response-for "WHAT?")
+ (response-for "WHAT!")
+ (response-for "Okay"))
+
(provide 'hello)