ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# thekeele's solution

## to Two Fer in the Elixir Track

Published at Aug 29 2019 · 0 comments
Instructions
Test suite
Solution

`Two-fer` or `2-fer` is short for two for one. One for you and one for me.

``````"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."

## Running tests

Execute the tests with:

``````\$ mix test
``````

### 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:

``````# @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.

``````# ExUnit.configure exclude: :pending, trace: true
``````

If you're stuck on something, it may help to look at some of the available resources out there where answers might be found.

## Source

https://en.wikipedia.org/wiki/Two-fer

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

### test_helper.exs

``````ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)``````

### two_fer_test.exs

``````defmodule TwoFerTest do
use ExUnit.Case

test "no name given" do
assert TwoFer.two_fer() == "One for you, one for me"
end

@tag :pending
test "a name given" do
assert TwoFer.two_fer("Gilberto Barros") == "One for Gilberto Barros, one for me"
end

@tag :pending
test "when the parameter is a number" do
assert_raise FunctionClauseError, fn ->
TwoFer.two_fer(10)
end
end

@tag :pending
test "when the parameter is an atom" do
assert_raise FunctionClauseError, fn ->
TwoFer.two_fer(:bob)
end
end

@tag :pending
test "when the parameter is a charlist" do
assert_raise FunctionClauseError, fn ->
refute TwoFer.two_fer('Jon Snow')
end
end
end``````
``````defmodule TwoFer do
@spec two_fer(String.t()) :: String.t()
def two_fer(name \\ "you")
def two_fer(name) when is_binary(name), do: "One for #{name}, one for me"
def two_fer(_), do: raise FunctionClauseError
end``````