Skip to content

Commit

Permalink
Updated hello_world problem to reflect exercism/problem-specification…
Browse files Browse the repository at this point in the history
…s#520 (#370)

* Updated hello_world problem to reflect exercism/problem-specifications#520

exercism/problem-specifications#520

* Adding example
  • Loading branch information
David McKay authored and devonestes committed Oct 9, 2017
1 parent f073ca5 commit 4f8228c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 72 deletions.
27 changes: 1 addition & 26 deletions exercises/hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,7 @@ If everything goes well, you will be ready to fetch your first real exercise.
Execute the tests with:

```bash
$ elixir bob_test.exs
```

(Replace `bob_test.exs` with the name of the test file.)

### Pending tests

In the test suites, all but the first test have been skipped.

Once you get a test passing, you can unskip the next one by
commenting out the relevant `@tag :pending` with a `#` symbol.

For example:

```elixir
# @tag :pending
test "shouting" do
assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"
end
```

Or, you can enable all the tests by commenting out the
`ExUnit.configure` line in the test suite.

```elixir
# ExUnit.configure exclude: :pending, trace: true
$ elixir hello_world_test.exs
```

For more detailed information about the Elixir track, please
Expand Down
10 changes: 3 additions & 7 deletions exercises/hello-world/example.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
defmodule HelloWorld do

@doc """
Greets the user by name, or by saying "Hello, World!"
if no name is given
"""

def hello(name \\ "World") do

"Hello, " <> name <> "!"

def hello do
"Hello, World!"
end
end
end
28 changes: 3 additions & 25 deletions exercises/hello-world/hello_world.exs
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
defmodule HelloWorld do
@moduledoc """
Elixir counts the number of arguments as part of the function name.
For instance;
def hello() do
end
would be a completely different function from
def hello(name) do
end
Can you find a way to make all the tests pass with just one
function?
Hint: look into argument defaults here:
http://elixir-lang.org/getting-started/modules-and-functions.html#default-arguments
"""

@doc """
Greets the user by name, or by saying "Hello, World!"
if no name is given.
Simply returns "Hello, world!"
"""
@spec hello(String.t) :: String.t
def hello(name) do

@spec hello :: String.t
def hello do
"Your implementation goes here"

end
end
15 changes: 2 additions & 13 deletions exercises/hello-world/hello_world_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true
ExUnit.configure trace: true

defmodule HelloWorldTest do
use ExUnit.Case

test "says hello with no name" do
test "says 'Hello, World!'" do
assert HelloWorld.hello() == "Hello, World!"
end

@tag :pending
test "says hello sample name" do
assert HelloWorld.hello("Alice") == "Hello, Alice!"
end

@tag :pending
test "says hello other sample name" do
assert HelloWorld.hello("Bob") == "Hello, Bob!"
end

end
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
%{"poison": {:hex, :poison, "1.4.0"}}
%{"poison": {:hex, :poison, "1.4.0", "cd5afb9db7f0d19487572fa28185b6d4de647f14235746824e77b3139b79b725", [], [], "hexpm"}}

0 comments on commit 4f8228c

Please sign in to comment.