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

Update hello-world exercise and add two-fer exercise #236

Merged
merged 5 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 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
4 changes: 2 additions & 2 deletions exercises/hello-world/HelloWorld.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module HelloWorld exposing (helloWorld)
-- It's good style to include any types at the top level of your modules.


helloWorld : Maybe String -> String
helloWorld name =
helloWorld : String
helloWorld =
Debug.todo "Please implement this function"


Expand Down
11 changes: 3 additions & 8 deletions exercises/hello-world/HelloWorld.example.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module HelloWorld exposing (helloWorld)


helloWorld : Maybe String -> String
helloWorld name =
case name of
Just name_ ->
"Hello, " ++ name_ ++ "!"

Nothing ->
"Hello, World!"
helloWorld : String
helloWorld =
"Hello, World!"
20 changes: 3 additions & 17 deletions exercises/hello-world/tests/Tests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ import Test exposing (..)

tests : Test
tests =
describe "Hello, World!"
[ test "Hello with no name" <|
\() ->
Expect.equal "Hello, World!" (helloWorld Nothing)

-- Once you get the first test passing, remove the
-- `skip <|` (just leave the comma) on the next two
-- lines to continue!
, skip <|
test "Hello to a sample name" <|
\() ->
Expect.equal "Hello, Alice!" (helloWorld (Just "Alice"))
, skip <|
test "Hello to another sample name" <|
\() ->
Expect.equal "Hello, Bob!" (helloWorld (Just "Bob"))
]
test "Hello, World!" <|
\() ->
Expect.equal "Hello, World!" helloWorld
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.
6 changes: 6 additions & 0 deletions exercises/two-fer/TwoFer.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module TwoFer exposing (twoFer)


twoFer : Maybe String -> String
twoFer name =
tuxagon marked this conversation as resolved.
Show resolved Hide resolved
Debug.todo "Please implement this function"
8 changes: 8 additions & 0 deletions exercises/two-fer/TwoFer.example.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module TwoFer exposing (twoFer)


twoFer : Maybe String -> String
twoFer name =
"One for "
++ Maybe.withDefault "you" name
++ ", one for me."
29 changes: 29 additions & 0 deletions exercises/two-fer/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "application",
"source-directories": [
"."
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.0",
"elm/core": "1.0.0",
"elm/html": "1.0.0",
"elm/regex": "1.0.0"
},
"indirect": {
"elm/json": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.0"
}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "1.0.0"
},
"indirect": {
"elm/random": "1.0.0"
}
}
}
23 changes: 23 additions & 0 deletions exercises/two-fer/tests/Tests.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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)
, 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"))
]