Skip to content

Commit

Permalink
Merge pull request #74 from herwinw/two-fer
Browse files Browse the repository at this point in the history
Implemented two-fer exercise
  • Loading branch information
benreyn authored May 10, 2018
2 parents 0baa733 + 7385fb0 commit 836b32f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
10 changes: 10 additions & 0 deletions exercises/two-fer/README.md
Original file line number Diff line number Diff line change
@@ -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."
7 changes: 7 additions & 0 deletions exercises/two-fer/example.scm
Original file line number Diff line number Diff line change
@@ -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.")))))
25 changes: 25 additions & 0 deletions exercises/two-fer/two-fer-test.scm
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 2 additions & 0 deletions exercises/two-fer/two-fer.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(define-module (two-fer)
#:export (two-fer))

0 comments on commit 836b32f

Please sign in to comment.