Skip to content

Commit

Permalink
Add new two-fer exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
benreyn committed Oct 21, 2018
1 parent a5e1b59 commit f700b16
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 48 additions & 0 deletions exercises/two-fer/README.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 11 additions & 0 deletions exercises/two-fer/TwoFer.elm
Original file line number Diff line number Diff line change
@@ -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."
5 changes: 5 additions & 0 deletions exercises/two-fer/TwoFer.example.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module TwoFer exposing (twoFer)


twoFer name =
Debug.todo "Please implement this function"
19 changes: 19 additions & 0 deletions exercises/two-fer/elm.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
}
27 changes: 27 additions & 0 deletions exercises/two-fer/tests/Tests.elm
Original file line number Diff line number Diff line change
@@ -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"))
]

0 comments on commit f700b16

Please sign in to comment.