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:
One for X, one for me.
Where X is the given name.
However, if the name is missing, return the string:
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. |
In order to run the tests, issue the following command from the exercise directory:
For running the tests provided, rebar3
is used as it is the official build and
dependency management tool for erlang now. Please refer to the tracks installation
instructions on how to do that.
In order to run the tests, you can issue the following command from the exercise directory.
$ rebar3 eunit
For detailed information about the Erlang track, please refer to the help page on the Exercism site. This covers the basic information on setting up the development environment expected by the exercises.
https://github.com/exercism/problem-specifications/issues/757
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
%% Based on canonical data version 1.2.0-1
%% https://github.com/exercism/problem-specifications/raw/master/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"))}.
-module(two_fer).
-export([two_fer/0, two_fer/1]).
two_fer() -> two_fer("you").
two_fer(Name) -> "One for " ++ Name ++ ", one for me.".
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.
Level up your programming skills with 3,450 exercises across 52 languages, and insightful discussion with our volunteer team of welcoming mentors. Exercism is 100% free forever.
Sign up Learn More
Community comments