From 6aafff35dfbe6370336db56909f72587320e376d Mon Sep 17 00:00:00 2001 From: Benjamin Reynolds Date: Sun, 21 Oct 2018 14:23:25 -0500 Subject: [PATCH] Implement new two-fer exercise --- exercises/two-fer/README.md | 44 ++++++++++++++++++++++++++++++ exercises/two-fer/example.rkt | 6 ++++ exercises/two-fer/two-fer-test.rkt | 22 +++++++++++++++ exercises/two-fer/two-fer.rkt | 3 ++ 4 files changed, 75 insertions(+) create mode 100644 exercises/two-fer/README.md create mode 100644 exercises/two-fer/example.rkt create mode 100644 exercises/two-fer/two-fer-test.rkt create mode 100644 exercises/two-fer/two-fer.rkt diff --git a/exercises/two-fer/README.md b/exercises/two-fer/README.md new file mode 100644 index 00000000..0f47ad43 --- /dev/null +++ b/exercises/two-fer/README.md @@ -0,0 +1,44 @@ +# Two Fer + +`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." + + +* * * * + +For installation and learning resources, refer to the +[exercism Racket page](http://exercism.io/languages/racket). + +You can run the provided tests through DrRacket, or via the command line. + +To run the test through DrRacket, simply open the test file and click the 'Run' button in the upper right. + +To run the test from the command line, run the test from the exercise directory with the following command: + +``` +raco test two-fer-test.rkt +``` + +which will display the following: + +``` +raco test: (submod "two-fer-test.rkt" test) +2 success(es) 0 failure(s) 0 error(s) 2 test(s) run +0 +2 tests passed +``` + +## Source + +[https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/two-fer/example.rkt b/exercises/two-fer/example.rkt new file mode 100644 index 00000000..fb054828 --- /dev/null +++ b/exercises/two-fer/example.rkt @@ -0,0 +1,6 @@ +#lang racket + +(provide two-fer) + +(define (two-fer [name "you"]) + (string-append "One for " name ", one for me.")) diff --git a/exercises/two-fer/two-fer-test.rkt b/exercises/two-fer/two-fer-test.rkt new file mode 100644 index 00000000..fa602076 --- /dev/null +++ b/exercises/two-fer/two-fer-test.rkt @@ -0,0 +1,22 @@ +#lang racket + +(require "two-fer.rkt") + +(module+ test + (require rackunit rackunit/text-ui) + + (define suite + (test-suite + "two fer tests" + + (test-equal? "no name given" + (two-fer) + "One for you, one for me.") + (test-equal? "a name given" + (two-fer "Alice") + "One for Alice, one for me.") + (test-equal? "another name given" + (two-fer "Bob") + "One for Bob, one for me."))) + + (run-tests suite)) diff --git a/exercises/two-fer/two-fer.rkt b/exercises/two-fer/two-fer.rkt new file mode 100644 index 00000000..fa408241 --- /dev/null +++ b/exercises/two-fer/two-fer.rkt @@ -0,0 +1,3 @@ +#lang racket + +(provide two-fer)