From 9ebec329bf25548f21401f7e3690012845348d29 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sun, 21 Nov 2021 07:22:08 -0500 Subject: exercism elisp exercises --- elisp/flake.nix | 16 ++++++++ .../emacs-lisp/hello-world/.exercism/config.json | 25 ++++++++++++ .../emacs-lisp/hello-world/.exercism/metadata.json | 1 + exercism/emacs-lisp/hello-world/HELP.md | 41 +++++++++++++++++++ exercism/emacs-lisp/hello-world/README.md | 37 +++++++++++++++++ .../emacs-lisp/hello-world/hello-world-test.el | 15 +++++++ exercism/emacs-lisp/hello-world/hello-world.el | 4 ++ exercism/emacs-lisp/run-exercises.el | 36 +++++++++++++++++ exercism/emacs-lisp/two-fer/.exercism/config.json | 22 +++++++++++ .../emacs-lisp/two-fer/.exercism/metadata.json | 1 + exercism/emacs-lisp/two-fer/HELP.md | 41 +++++++++++++++++++ exercism/emacs-lisp/two-fer/README.md | 46 ++++++++++++++++++++++ exercism/emacs-lisp/two-fer/two-fer-test.el | 21 ++++++++++ exercism/emacs-lisp/two-fer/two-fer.el | 13 ++++++ exercism/flake.nix | 16 ++++++++ 15 files changed, 335 insertions(+) create mode 100644 elisp/flake.nix create mode 100644 exercism/emacs-lisp/hello-world/.exercism/config.json create mode 100644 exercism/emacs-lisp/hello-world/.exercism/metadata.json create mode 100644 exercism/emacs-lisp/hello-world/HELP.md create mode 100644 exercism/emacs-lisp/hello-world/README.md create mode 100644 exercism/emacs-lisp/hello-world/hello-world-test.el create mode 100644 exercism/emacs-lisp/hello-world/hello-world.el create mode 100644 exercism/emacs-lisp/run-exercises.el create mode 100644 exercism/emacs-lisp/two-fer/.exercism/config.json create mode 100644 exercism/emacs-lisp/two-fer/.exercism/metadata.json create mode 100644 exercism/emacs-lisp/two-fer/HELP.md create mode 100644 exercism/emacs-lisp/two-fer/README.md create mode 100644 exercism/emacs-lisp/two-fer/two-fer-test.el create mode 100644 exercism/emacs-lisp/two-fer/two-fer.el create mode 100644 exercism/flake.nix diff --git a/elisp/flake.nix b/elisp/flake.nix new file mode 100644 index 0000000..b68fbf2 --- /dev/null +++ b/elisp/flake.nix @@ -0,0 +1,16 @@ +{ + inputs = { + utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05"; + }; + + outputs = { self, nixpkgs, utils }: + # Note: This has only been tested on x86_64-linux. + utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages."${system}"; + in rec { + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ exercism ]; + }; + }); +} diff --git a/exercism/emacs-lisp/hello-world/.exercism/config.json b/exercism/emacs-lisp/hello-world/.exercism/config.json new file mode 100644 index 0000000..683e6a2 --- /dev/null +++ b/exercism/emacs-lisp/hello-world/.exercism/config.json @@ -0,0 +1,25 @@ +{ + "blurb": "The classical introductory exercise. Just say \"Hello, World!\"", + "authors": [ + "canweriotnow" + ], + "contributors": [ + "benreyn", + "konrad", + "kytrinyx", + "vermiculus" + ], + "files": { + "solution": [ + "hello-world.el" + ], + "test": [ + "hello-world-test.el" + ], + "example": [ + ".meta/example.el" + ] + }, + "source": "This is an exercise to introduce users to using Exercism", + "source_url": "http://en.wikipedia.org/wiki/%22Hello,_world!%22_program" +} diff --git a/exercism/emacs-lisp/hello-world/.exercism/metadata.json b/exercism/emacs-lisp/hello-world/.exercism/metadata.json new file mode 100644 index 0000000..8c77a7c --- /dev/null +++ b/exercism/emacs-lisp/hello-world/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"emacs-lisp","exercise":"hello-world","id":"dda6cfc056f94482ac16f4bbcfca0b9c","url":"https://exercism.org/tracks/emacs-lisp/exercises/hello-world","handle":"orbekk","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/exercism/emacs-lisp/hello-world/HELP.md b/exercism/emacs-lisp/hello-world/HELP.md new file mode 100644 index 0000000..8af8f70 --- /dev/null +++ b/exercism/emacs-lisp/hello-world/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 hello-world.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/hello-world/README.md b/exercism/emacs-lisp/hello-world/README.md new file mode 100644 index 0000000..be8ab4f --- /dev/null +++ b/exercism/emacs-lisp/hello-world/README.md @@ -0,0 +1,37 @@ +# Hello World + +Welcome to Hello World on Exercism's Emacs Lisp Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +The classical introductory exercise. Just say "Hello, World!". + +["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is +the traditional first program for beginning programming in a new language +or environment. + +The objectives are simple: + +- Write a function that returns the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +## Source + +### Created by + +- @canweriotnow + +### Contributed to by + +- @benreyn +- @konrad +- @kytrinyx +- @vermiculus + +### Based on + +This is an exercise to introduce users to using Exercism - http://en.wikipedia.org/wiki/%22Hello,_world!%22_program \ No newline at end of file diff --git a/exercism/emacs-lisp/hello-world/hello-world-test.el b/exercism/emacs-lisp/hello-world/hello-world-test.el new file mode 100644 index 0000000..f5f6ce0 --- /dev/null +++ b/exercism/emacs-lisp/hello-world/hello-world-test.el @@ -0,0 +1,15 @@ +;;; hello-world-test.el --- Tests for Hello World (exercism) + +;;; Commentary: +;; Common test data version: 1.1.0 be3ae66 + +;;; Code: + +(load-file "hello-world.el") + +(ert-deftest hello-world-test () + (should (string= (hello) "Hello, World!"))) + +(provide 'hello-world-test) + +;;; hello-world-test.el ends here diff --git a/exercism/emacs-lisp/hello-world/hello-world.el b/exercism/emacs-lisp/hello-world/hello-world.el new file mode 100644 index 0000000..6f0dd39 --- /dev/null +++ b/exercism/emacs-lisp/hello-world/hello-world.el @@ -0,0 +1,4 @@ +(defun hello () + "Hello, World!") + +(provide 'hello-world) diff --git a/exercism/emacs-lisp/run-exercises.el b/exercism/emacs-lisp/run-exercises.el new file mode 100644 index 0000000..38b097b --- /dev/null +++ b/exercism/emacs-lisp/run-exercises.el @@ -0,0 +1,36 @@ +(defmacro in-test-window (&rest body) + `(save-selected-window + (switch-to-buffer-other-window "*kj/test*") + ,@body)) + +(macroexpand '(in-test-window (insert "hello") (insert "world"))) + +(defun setup-test-window () + (in-test-window + (erase-buffer))) + +(defun kj-writeln (msg) + (in-test-window + (insert (concat msg "\n")))) + +(setup-test-window) + +(kj-writeln + (in-test-window + (insert (propertize "* Emacs tests" 'face 'org-level-1)))) + +(defmacro kj-display (title &rest code) + `(progn + (kj-writeln (propertize (concat "** " ,title) 'face 'org-level-2)) + (kj-writeln (propertize "Code:" 'face 'italic)) + (kj-writeln (format "%s" ',@code)) + (kj-writeln (propertize "Output:" 'face 'italic)) + (kj-writeln (format "%s" ,@code)))) + +(load-file "hello-world/hello-world.el") +(kj-display "Hello" (hello)) + +(load-file "two-fer/two-fer.el") +(kj-display "Two-fer" (two-fer "Annie")) + +(provide 'hello) diff --git a/exercism/emacs-lisp/two-fer/.exercism/config.json b/exercism/emacs-lisp/two-fer/.exercism/config.json new file mode 100644 index 0000000..c028175 --- /dev/null +++ b/exercism/emacs-lisp/two-fer/.exercism/config.json @@ -0,0 +1,22 @@ +{ + "blurb": "Create a sentence of the form \"One for X, one for me.\"", + "authors": [ + "benreyn" + ], + "contributors": [ + "bcfurtado", + "vermiculus" + ], + "files": { + "solution": [ + "two-fer.el" + ], + "test": [ + "two-fer-test.el" + ], + "example": [ + ".meta/example.el" + ] + }, + "source_url": "https://github.com/exercism/problem-specifications/issues/757" +} diff --git a/exercism/emacs-lisp/two-fer/.exercism/metadata.json b/exercism/emacs-lisp/two-fer/.exercism/metadata.json new file mode 100644 index 0000000..8384cf5 --- /dev/null +++ b/exercism/emacs-lisp/two-fer/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"emacs-lisp","exercise":"two-fer","id":"6644d4098ca9402c828512e2d21aa0ff","url":"https://exercism.org/tracks/emacs-lisp/exercises/two-fer","handle":"orbekk","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/exercism/emacs-lisp/two-fer/HELP.md b/exercism/emacs-lisp/two-fer/HELP.md new file mode 100644 index 0000000..bf6a559 --- /dev/null +++ b/exercism/emacs-lisp/two-fer/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 two-fer.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/two-fer/README.md b/exercism/emacs-lisp/two-fer/README.md new file mode 100644 index 0000000..2cf660d --- /dev/null +++ b/exercism/emacs-lisp/two-fer/README.md @@ -0,0 +1,46 @@ +# Two Fer + +Welcome to Two Fer on Exercism's Emacs Lisp Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +`Two-fer` or `2-fer` is short for two for one. One for you and one for me. + +Given a name, return a string with the message: + +```text +One for name, one for me. +``` + +Where "name" is the given name. + +However, if the name is missing, return the string: + +```text +One for you, one for me. +``` + +Here are some examples: + +|Name |String to return +|:-------|:------------------ +|Alice |One for Alice, one for me. +|Bob |One for Bob, one for me. +| |One for you, one for me. +|Zaphod |One for Zaphod, one for me. + +## Source + +### Created by + +- @benreyn + +### Contributed to by + +- @bcfurtado +- @vermiculus + +### Based on + +https://github.com/exercism/problem-specifications/issues/757 \ No newline at end of file diff --git a/exercism/emacs-lisp/two-fer/two-fer-test.el b/exercism/emacs-lisp/two-fer/two-fer-test.el new file mode 100644 index 0000000..f21c756 --- /dev/null +++ b/exercism/emacs-lisp/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 (string= (two-fer) "One for you, one for me."))) + +(ert-deftest a-name-given () + (should (string= (two-fer "Alice") "One for Alice, one for me."))) + +(ert-deftest another-name-given () + (should (string= (two-fer "Bob") "One for Bob, one for me."))) + +(provide 'two-fer-test) + +;;; two-fer-test.el ends here diff --git a/exercism/emacs-lisp/two-fer/two-fer.el b/exercism/emacs-lisp/two-fer/two-fer.el new file mode 100644 index 0000000..dda2502 --- /dev/null +++ b/exercism/emacs-lisp/two-fer/two-fer.el @@ -0,0 +1,13 @@ +;;; two-fer.el --- Two-fer Exercise (exercism) + +;;; Commentary: + +;;; Code: + +(defun two-fer (&optional name) + "Display a message for NAME." + (or name (setq name "you")) + (format "One for %s, one for me." name)) + +(provide 'two-fer) +;;; two-fer.el ends here diff --git a/exercism/flake.nix b/exercism/flake.nix new file mode 100644 index 0000000..b68fbf2 --- /dev/null +++ b/exercism/flake.nix @@ -0,0 +1,16 @@ +{ + inputs = { + utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05"; + }; + + outputs = { self, nixpkgs, utils }: + # Note: This has only been tested on x86_64-linux. + utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages."${system}"; + in rec { + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ exercism ]; + }; + }); +} -- cgit v1.2.3