Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented two-fer exercise #74

Merged
merged 2 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))