From 6303a486eb048b2bb51d75f7a16172383fd88624 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Tue, 5 Oct 2021 12:51:36 -0300 Subject: [PATCH] Exercism Two fer --- erlang/two-fer/.exercism/config.json | 24 +++++++++++++ erlang/two-fer/.exercism/metadata.json | 1 + erlang/two-fer/HELP.md | 36 +++++++++++++++++++ erlang/two-fer/README.md | 48 ++++++++++++++++++++++++++ erlang/two-fer/rebar.config | 30 ++++++++++++++++ erlang/two-fer/src/two_fer.app.src | 9 +++++ erlang/two-fer/src/two_fer.erl | 15 ++++++++ erlang/two-fer/test/two_fer_tests.erl | 44 +++++++++++++++++++++++ 8 files changed, 207 insertions(+) create mode 100644 erlang/two-fer/.exercism/config.json create mode 100644 erlang/two-fer/.exercism/metadata.json create mode 100644 erlang/two-fer/HELP.md create mode 100644 erlang/two-fer/README.md create mode 100644 erlang/two-fer/rebar.config create mode 100644 erlang/two-fer/src/two_fer.app.src create mode 100644 erlang/two-fer/src/two_fer.erl create mode 100644 erlang/two-fer/test/two_fer_tests.erl diff --git a/erlang/two-fer/.exercism/config.json b/erlang/two-fer/.exercism/config.json new file mode 100644 index 0000000..581bc3f --- /dev/null +++ b/erlang/two-fer/.exercism/config.json @@ -0,0 +1,24 @@ +{ + "blurb": "Create a sentence of the form \"One for X, one for me.\"", + "authors": [ + "sjwarner-bp" + ], + "contributors": [ + "ErikSchierboom", + "iHiD", + "juhlig", + "NobbZ" + ], + "files": { + "solution": [ + "src/two_fer.erl" + ], + "test": [ + "test/two_fer_tests.erl" + ], + "example": [ + ".meta/example.erl" + ] + }, + "source_url": "https://github.com/exercism/problem-specifications/issues/757" +} diff --git a/erlang/two-fer/.exercism/metadata.json b/erlang/two-fer/.exercism/metadata.json new file mode 100644 index 0000000..8e3debe --- /dev/null +++ b/erlang/two-fer/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"erlang","exercise":"two-fer","id":"e8deb62d43c54acabb5ef043ccb92ca5","url":"https://exercism.org/tracks/erlang/exercises/two-fer","handle":"JBiason","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/erlang/two-fer/HELP.md b/erlang/two-fer/HELP.md new file mode 100644 index 0000000..a819ca5 --- /dev/null +++ b/erlang/two-fer/HELP.md @@ -0,0 +1,36 @@ +# Help + +## Running the tests + +You can run the tests by running the following command from the exercise directory. + +```bash +$ rebar3 eunit +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit src/two_fer.erl` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Erlang track's documentation](https://exercism.org/docs/tracks/erlang) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Exercism related BEAM support channel on gitter](https://gitter.im/exercism/xerlang) +- [Erlang Documentation](http://www.erlang.org/doc.html) +- [Learn You Some Erlang for Great Good](http://learnyousomeerlang.com) +- [StackOverflow](http://stackoverflow.com/) \ No newline at end of file diff --git a/erlang/two-fer/README.md b/erlang/two-fer/README.md new file mode 100644 index 0000000..c7d1108 --- /dev/null +++ b/erlang/two-fer/README.md @@ -0,0 +1,48 @@ +# Two Fer + +Welcome to Two Fer on Exercism's Erlang Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +`Two-fer` or `2-fer` is short for two for one. One for you and one for me. + +Given a name, return a string with the message: + +```text +One for name, one for me. +``` + +Where "name" is the given name. + +However, if the name is missing, return the string: + +```text +One for you, one for me. +``` + +Here are some examples: + +|Name |String to return +|:-------|:------------------ +|Alice |One for Alice, one for me. +|Bob |One for Bob, one for me. +| |One for you, one for me. +|Zaphod |One for Zaphod, one for me. + +## Source + +### Created by + +- @sjwarner-bp + +### Contributed to by + +- @ErikSchierboom +- @iHiD +- @juhlig +- @NobbZ + +### Based on + +https://github.com/exercism/problem-specifications/issues/757 \ No newline at end of file diff --git a/erlang/two-fer/rebar.config b/erlang/two-fer/rebar.config new file mode 100644 index 0000000..db5d907 --- /dev/null +++ b/erlang/two-fer/rebar.config @@ -0,0 +1,30 @@ +%% Erlang compiler options +{erl_opts, [debug_info, warnings_as_errors]}. + +{deps, [{erl_exercism, "0.1.2"}]}. + +{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/erlang/two-fer/src/two_fer.app.src b/erlang/two-fer/src/two_fer.app.src new file mode 100644 index 0000000..4c4602f --- /dev/null +++ b/erlang/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/erlang/two-fer/src/two_fer.erl b/erlang/two-fer/src/two_fer.erl new file mode 100644 index 0000000..0c62bce --- /dev/null +++ b/erlang/two-fer/src/two_fer.erl @@ -0,0 +1,15 @@ +-module(two_fer). + +-import(string, [concat/2]). + +-export([two_fer/0, two_fer/1]). + + +two_fer() -> + "One for you, one for me.". + +two_fer(Name) -> + concat( + concat("One for ", Name), + ", one for me." + ). diff --git a/erlang/two-fer/test/two_fer_tests.erl b/erlang/two-fer/test/two_fer_tests.erl new file mode 100644 index 0000000..d6dd2d6 --- /dev/null +++ b/erlang/two-fer/test/two_fer_tests.erl @@ -0,0 +1,44 @@ +%% Generated with 'testgen v0.2.0' +%% Revision 1 of the exercises generator was used +%% https://github.com/exercism/problem-specifications/raw/42dd0cea20498fd544b152c4e2c0a419bb7e266a/exercises/two-fer/canonical-data.json +%% This file is automatically generated from the exercises canonical data. + +-module(two_fer_tests). + +-include_lib("erl_exercism/include/exercism.hrl"). +-include_lib("eunit/include/eunit.hrl"). + + +-define(assertStringEqual(Expect, Expr), + begin ((fun () -> + __X = (Expect), + __Y = (Expr), + case string:equal(__X, __Y) of + true -> ok; + false -> erlang:error({assertStringEqual, + [{module, ?MODULE}, + {line, ?LINE}, + {expression, (??Expr)}, + {expected, unicode:characters_to_list(__X)}, + {value, unicode:characters_to_list(__Y)}]}) + end + end)()) + end). + +-define(_assertStringEqual(Expect, Expr), ?_test(?assertStringEqual(Expect, Expr))). + + +'1_no_name_given_test_'() -> + {"no name given", + ?_assertStringEqual("One for you, one for me.", + two_fer:two_fer())}. + +'2_a_name_given_test_'() -> + {"a name given", + ?_assertStringEqual("One for Alice, one for me.", + two_fer:two_fer("Alice"))}. + +'3_another_name_given_test_'() -> + {"another name given", + ?_assertStringEqual("One for Bob, one for me.", + two_fer:two_fer("Bob"))}.