diff --git a/config.json b/config.json index 9993380c..7a93ac37 100644 --- a/config.json +++ b/config.json @@ -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", diff --git a/exercises/two-fer/README.md b/exercises/two-fer/README.md new file mode 100644 index 00000000..71484dcb --- /dev/null +++ b/exercises/two-fer/README.md @@ -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. + diff --git a/exercises/two-fer/include/exercism.hrl b/exercises/two-fer/include/exercism.hrl new file mode 100644 index 00000000..cc152d9f --- /dev/null +++ b/exercises/two-fer/include/exercism.hrl @@ -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()). diff --git a/exercises/two-fer/rebar.config b/exercises/two-fer/rebar.config new file mode 100644 index 00000000..360f3d18 --- /dev/null +++ b/exercises/two-fer/rebar.config @@ -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]}. diff --git a/exercises/two-fer/src/example.erl b/exercises/two-fer/src/example.erl new file mode 100644 index 00000000..3a7bd3b3 --- /dev/null +++ b/exercises/two-fer/src/example.erl @@ -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. diff --git a/exercises/two-fer/src/two_fer.app.src b/exercises/two-fer/src/two_fer.app.src new file mode 100644 index 00000000..4c4602fa --- /dev/null +++ b/exercises/two-fer/src/two_fer.app.src @@ -0,0 +1,9 @@ +{application, two_fer, + [{description, "exercism.io - two-fer"}, + {vsn, "0.0.1"}, + {modules, []}, + {registered, []}, + {applications, [kernel, + stdlib]}, + {env, []} + ]}. diff --git a/exercises/two-fer/src/two_fer.erl b/exercises/two-fer/src/two_fer.erl new file mode 100644 index 00000000..e9ea0e70 --- /dev/null +++ b/exercises/two-fer/src/two_fer.erl @@ -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. diff --git a/exercises/two-fer/test/two_fer_tests.erl b/exercises/two-fer/test/two_fer_tests.erl new file mode 100644 index 00000000..4dcba211 --- /dev/null +++ b/exercises/two-fer/test/two_fer_tests.erl @@ -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")). \ No newline at end of file