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

Two-fer: Implemented two-fer as in #197. #200

Merged
merged 3 commits into from
Oct 6, 2017
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 @@ -192,6 +192,16 @@

]
},
{
"uuid": "1a8abaa2-04f5-0e80-7986-5fb33995971caeb1496",
"slug": "two-fer",
"core": false,
"unlocked_by": null,
"difficulty": 3,
"topics": [

]
},
{
"uuid": "a2d4ca29-54e2-4969-bfc9-ee483acf9caf",
"slug": "robot-simulator",
Expand Down
19 changes: 19 additions & 0 deletions exercises/two-fer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
`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."

## Instructions

Submissions are encouraged to be general, within reason. Having said that, it's
also important not to over-engineer a solution.

It's important to remember that the goal is to make code as expressive and
readable as we can.

11 changes: 11 additions & 0 deletions exercises/two-fer/include/exercism.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-include_lib("eunit/include/eunit.hrl").

sut(Module) ->
{ok, Files} = file:list_dir("./src"),
case lists:member("example.erl", Files) of
true -> example;
false -> Module
end.

version_test() ->
?assertMatch(?TEST_VERSION, ?TESTED_MODULE:test_version()).
30 changes: 30 additions & 0 deletions exercises/two-fer/rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%% Erlang compiler options
{erl_opts, [debug_info]}.

{deps, []}.

{dialyzer, [
{warnings, [underspecs, no_return]},
{get_warnings, true},
{plt_apps, top_level_deps}, % top_level_deps | all_deps
{plt_extra_apps, []},
{plt_location, local}, % local | "/my/file/name"
{plt_prefix, "rebar3"},
{base_plt_apps, [stdlib, kernel, crypto]},
{base_plt_location, global}, % global | "/my/file/name"
{base_plt_prefix, "rebar3"}
]}.

%% eunit:test(Tests)
{eunit_tests, []}.
%% Options for eunit:test(Tests, Opts)
{eunit_opts, [verbose]}.

%% == xref ==

{xref_warnings, true}.

%% xref checks to run
{xref_checks, [undefined_function_calls, undefined_functions,
locals_not_used, exports_not_used,
deprecated_function_calls, deprecated_functions]}.
11 changes: 11 additions & 0 deletions exercises/two-fer/src/example.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-module(example).
-export([two_fer/1, two_fer/0, test_version/0]).

two_fer() ->
"One for you, one for me.".

two_fer(Name) ->
lists:flatten(io_lib:format("One for ~s, one for me.", [Name])).

test_version() ->
1.
9 changes: 9 additions & 0 deletions exercises/two-fer/src/two_fer.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{application, two_fer,
[{description, "exercism.io - two-fer"},
{vsn, "0.0.1"},
{modules, []},
{registered, []},
{applications, [kernel,
stdlib]},
{env, []}
]}.
11 changes: 11 additions & 0 deletions exercises/two-fer/src/two_fer.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-module(two_fer).

-export([two_fer/1, two_fer/0, test_version/0]).

two_fer() ->
undefined.

two_fer(Name) ->
undefined.

test_version() -> 1.
15 changes: 15 additions & 0 deletions exercises/two-fer/test/two_fer_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-module(two_fer_tests).

-define(TESTED_MODULE, (sut(two_fer))).
-define(TEST_VERSION, 1).
-include("exercism.hrl").


say_you_test() ->
?assertEqual("One for you, one for me.", ?TESTED_MODULE:two_fer()).

say_alice_test() ->
?assertEqual("One for Alice, one for me.", ?TESTED_MODULE:two_fer("Alice")).

say_bob_test() ->
?assertEqual("One for Bob, one for me.", ?TESTED_MODULE:two_fer("Bob")).