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

# angelikatyborska's solution

## to Bob in the Elixir Track

Published at Jul 13 2018 · 0 comments
Instructions
Test suite
Solution

#### Note:

This solution was written on an old version of Exercism. The tests below might not correspond to the solution code, and the exercise may have changed since this code was written.

Bob is a lackadaisical teenager. In conversation, his responses are very limited.

He answers 'Whoa, chill out!' if you yell at him.

He answers 'Calm down, I know what I'm doing!' if you yell a question at him.

He says 'Fine. Be that way!' if you address him without actually saying anything.

He answers 'Whatever.' to anything else.

## Running tests

Execute the tests with:

``````\$ elixir bob_test.exs
``````

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

For more detailed information about the Elixir track, please see the help page.

## Source

Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=06

## Submitting Incomplete Solutions

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

### bob_test.exs

``````if !System.get_env("EXERCISM_TEST_EXAMPLES") do
end

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

defmodule BobTest do
use ExUnit.Case

test "stating something" do
assert Bob.hey("Tom-ay-to, tom-aaaah-to.") == "Whatever."
end

@tag :pending
test "shouting" do
assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"
end

@tag :pending
assert Bob.hey("Does this cryogenic chamber make me look fat?") == "Sure."
end

@tag :pending
test "talking forcefully" do
assert Bob.hey("Let's go make out behind the gym!") == "Whatever."
end

@tag :pending
test "talking in capitals" do
assert Bob.hey("This Isn't Shouting!") == "Whatever."
end

@tag :pending
assert Bob.hey("THIS ISN'T SHOUTING?") == "Calm down, I know what I'm doing!"
end

@tag :pending
test "shouting numbers" do
assert Bob.hey("1, 2, 3 GO!") == "Whoa, chill out!"
end

@tag :pending
test "shouting with special characters" do
assert Bob.hey("ZOMG THE %^*@#\$(*^ ZOMBIES ARE COMING!!11!!1!") == "Whoa, chill out!"
end

@tag :pending
test "shouting with no exclamation mark" do
assert Bob.hey("I HATE YOU") == "Whoa, chill out!"
end

@tag :pending
test "statement containing question mark" do
assert Bob.hey("Ending with ? means a question.") == "Whatever."
end

@tag :pending
test "silence" do
assert Bob.hey("") == "Fine. Be that way!"
end

@tag :pending
test "prolonged silence" do
assert Bob.hey("  ") == "Fine. Be that way!"
end

@tag :pending
test "only numbers" do
assert Bob.hey("1, 2, 3") == "Whatever."
end

@tag :pending
test "question with numbers" do
assert Bob.hey("4?") == "Sure."
end

@tag :pending
test "shouting in Russian" do
assert Bob.hey("Ð£Ð¥ÐžÐ”Ð˜") == "Whoa, chill out!"
end
end``````
``````defmodule Bob do
def hey(input) do
cond do
shouting_question?(input) -> "Calm down, I know what I'm doing!"
question?(input) -> "Sure."
shouting?(input) -> "Whoa, chill out!"
silence?(input) -> "Fine. Be that way!"
true -> "Whatever."
end
end

defp shouting_question?(input) do
question?(input) && shouting?(input)
end

defp question?(input) do
String.ends_with?(input, "?")
end

defp shouting?(input) do
String.upcase(input) == input && String.downcase(input) != input
end

defp silence?(input) do
String.trim(input) == ""
end
end``````