From 7906d0c317f69e5ea0b359d020bb33acd43416a5 Mon Sep 17 00:00:00 2001 From: Herwin Weststrate Date: Thu, 26 Apr 2018 20:26:07 +0200 Subject: [PATCH 1/2] Implemented two-fer exercise This replaces the old hello-world that is simplified in #69. --- exercises/two-fer/README.md | 10 ++++++++++ exercises/two-fer/example.scm | 7 +++++++ exercises/two-fer/two-fer-test.scm | 25 +++++++++++++++++++++++++ exercises/two-fer/two-fer.scm | 2 ++ 4 files changed, 44 insertions(+) create mode 100644 exercises/two-fer/README.md create mode 100644 exercises/two-fer/example.scm create mode 100644 exercises/two-fer/two-fer-test.scm create mode 100644 exercises/two-fer/two-fer.scm diff --git a/exercises/two-fer/README.md b/exercises/two-fer/README.md new file mode 100644 index 00000000..9b468262 --- /dev/null +++ b/exercises/two-fer/README.md @@ -0,0 +1,10 @@ +`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." diff --git a/exercises/two-fer/example.scm b/exercises/two-fer/example.scm new file mode 100644 index 00000000..583b87c9 --- /dev/null +++ b/exercises/two-fer/example.scm @@ -0,0 +1,7 @@ +(define-module (two-fer) + #:export (two-fer)) + +(define two-fer + (lambda* (#:optional name) + (let ((target (or name "you"))) + (string-concatenate (list "One for " target ", one for me."))))) diff --git a/exercises/two-fer/two-fer-test.scm b/exercises/two-fer/two-fer-test.scm new file mode 100644 index 00000000..c815447f --- /dev/null +++ b/exercises/two-fer/two-fer-test.scm @@ -0,0 +1,25 @@ +;; Load SRFI-64 lightweight testing specification +(use-modules (srfi srfi-64)) + +;; Suppress log file output. To write logs, comment out the following line: +(module-define! (resolve-module '(srfi srfi-64)) 'test-log-to-file #f) + +;; Require module +(add-to-load-path (dirname (current-filename))) +(use-modules (two-fer)) + +(test-begin "two-fer") + +(test-assert "no name given" + (equal? (two-fer) + "One for you, one for me.")) + +(test-assert "a name given" + (equal? (two-fer "Alice") + "One for Alice, one for me.")) + +(test-assert "another name given" + (equal? (two-fer "Bob") + "One for Bob, one for me.")) + +(test-end "two-fer") diff --git a/exercises/two-fer/two-fer.scm b/exercises/two-fer/two-fer.scm new file mode 100644 index 00000000..4d2c169a --- /dev/null +++ b/exercises/two-fer/two-fer.scm @@ -0,0 +1,2 @@ +(define-module (two-fer) + #:export (two-fer)) From 7385fb07d2ffab200eefc39579a837ad02c35b1a Mon Sep 17 00:00:00 2001 From: Herwin Weststrate Date: Thu, 10 May 2018 10:26:08 +0200 Subject: [PATCH 2/2] Add two-fer to config.json --- config.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config.json b/config.json index dfd375f2..bf371ed1 100644 --- a/config.json +++ b/config.json @@ -120,6 +120,14 @@ "topics": null, "unlocked_by": null, "uuid": "9460b65d-dc80-4a95-8782-b395d2cc979e" + }, + { + "core": false, + "difficulty": 1, + "slug": "two-fer", + "topics": null, + "unlocked_by": null, + "uuid": "3ecc2d1c-55e0-45c9-ba35-57d7d8cfd51e" } ], "foregone": [],