diff --git a/config.json b/config.json index 8ce12fb4..ad354dff 100644 --- a/config.json +++ b/config.json @@ -14,6 +14,16 @@ "strings" ] }, + { + "slug": "two-fer", + "uuid": "0118175a-761f-4d05-8857-fe93745f490f", + "core": true, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "strings" + ] + }, { "slug": "bob", "uuid": "11ce2a73-3f43-4b14-b755-6c52dc71bdda", diff --git a/exercises/two-fer/README.md b/exercises/two-fer/README.md new file mode 100644 index 00000000..567b68f1 --- /dev/null +++ b/exercises/two-fer/README.md @@ -0,0 +1,48 @@ +# 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." + + +## Elm Installation + +Refer to the [Exercism help page](http://exercism.io/languages/elm) for Elm +installation and learning resources. + +## Writing the Code + +The first time you start an exercise, you'll need to ensure you have the +appropriate dependencies installed. Thankfully, Elm makes that easy for you and +will install dependencies when you try to run tests or build the code. + +Execute the tests with: + +```bash +$ elm-test +``` + +Automatically run tests again when you save changes: + +```bash +$ elm-test --watch +``` + +As you work your way through the test suite, be sure to remove the `skip <|` +calls from each test until you get them all passing! + +## Source + +[https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer) + +## Submitting Incomplete Solutions + +It is possible to submit an incomplete solution so you can see how others have +completed the exercise. diff --git a/exercises/two-fer/TwoFer.elm b/exercises/two-fer/TwoFer.elm new file mode 100644 index 00000000..733b6f0f --- /dev/null +++ b/exercises/two-fer/TwoFer.elm @@ -0,0 +1,11 @@ +module TwoFer exposing (twoFer) + + +twoFer : Maybe String -> String +twoFer name = + case name of + Just name_ -> + "One for " ++ name_ ++ ", one for me." + + Nothing -> + "One for you, one for me." diff --git a/exercises/two-fer/TwoFer.example.elm b/exercises/two-fer/TwoFer.example.elm new file mode 100644 index 00000000..154bc85f --- /dev/null +++ b/exercises/two-fer/TwoFer.example.elm @@ -0,0 +1,5 @@ +module TwoFer exposing (twoFer) + + +twoFer name = + Debug.todo "Please implement this function" diff --git a/exercises/two-fer/elm.json b/exercises/two-fer/elm.json new file mode 100644 index 00000000..90f48609 --- /dev/null +++ b/exercises/two-fer/elm.json @@ -0,0 +1,19 @@ +{ + "type": "application", + "source-directories": [ + "." + ], + "elm-version": "0.19.0", + "dependencies": { + "direct": { + "elm/core": "1.0.0" + }, + "indirect": {} + }, + "test-dependencies": { + "direct": { + "elm-explorations/test": "1.0.0" + }, + "indirect": {} + } +} diff --git a/exercises/two-fer/tests/Tests.elm b/exercises/two-fer/tests/Tests.elm new file mode 100644 index 00000000..adf62462 --- /dev/null +++ b/exercises/two-fer/tests/Tests.elm @@ -0,0 +1,27 @@ +module Tests exposing (tests) + +import Expect +import String +import Test exposing (..) +import TwoFer exposing (twoFer) + + +tests : Test +tests = + describe "Two-fer" + [ test "No name given" <| + \() -> + Expect.equal "One for you, one for me." (twoFer Nothing) + + -- Once you get the first test passing, remove the + -- `skip <|` (just leave the comma) on the next two + -- lines to continue! + , skip <| + test "A name given" <| + \() -> + Expect.equal "One for Alice, one for me." (twoFer (Just "Alice")) + , skip <| + test "Another name given" <| + \() -> + Expect.equal "One for Bob, one for me." (twoFer (Just "Bob")) + ]