bob
This commit is contained in:
parent
3c7f1d64f5
commit
c625ecedd6
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"authors": [
|
||||||
|
"rubysolo"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"andrewsardone",
|
||||||
|
"angelikatyborska",
|
||||||
|
"austinlyons",
|
||||||
|
"cbliard",
|
||||||
|
"Cohen-Carlisle",
|
||||||
|
"dalexj",
|
||||||
|
"devonestes",
|
||||||
|
"digitalronin",
|
||||||
|
"doncruse",
|
||||||
|
"etrepum",
|
||||||
|
"ghajba",
|
||||||
|
"kytrinyx",
|
||||||
|
"lpil",
|
||||||
|
"neenjaw",
|
||||||
|
"parkerl",
|
||||||
|
"pminten",
|
||||||
|
"rsslldnphy",
|
||||||
|
"seeflanigan",
|
||||||
|
"sotojuan",
|
||||||
|
"Teapane",
|
||||||
|
"tjcelaya",
|
||||||
|
"Tonkpils",
|
||||||
|
"victorpre",
|
||||||
|
"vladimir-tikhonov",
|
||||||
|
"waiting-for-dev"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"lib/bob.ex"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"test/bob_test.exs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.ex"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.",
|
||||||
|
"source": "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial.",
|
||||||
|
"source_url": "https://pine.fm/LearnToProgram/?Chapter=06"
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{"track":"elixir","exercise":"bob","id":"7c75c2cb7c6d4f808ec6412bbc842f86","url":"https://exercism.org/tracks/elixir/exercises/bob","handle":"negrienko","is_requester":true,"auto_approve":false}
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Used by "mix format"
|
||||||
|
[
|
||||||
|
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||||
|
]
|
|
@ -0,0 +1,24 @@
|
||||||
|
# The directory Mix will write compiled artifacts to.
|
||||||
|
/_build/
|
||||||
|
|
||||||
|
# If you run "mix test --cover", coverage assets end up here.
|
||||||
|
/cover/
|
||||||
|
|
||||||
|
# The directory Mix downloads your dependencies sources to.
|
||||||
|
/deps/
|
||||||
|
|
||||||
|
# Where third-party dependencies like ExDoc output generated docs.
|
||||||
|
/doc/
|
||||||
|
|
||||||
|
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||||
|
/.fetch
|
||||||
|
|
||||||
|
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||||
|
erl_crash.dump
|
||||||
|
|
||||||
|
# Also ignore archive artifacts (built via "mix archive.build").
|
||||||
|
*.ez
|
||||||
|
|
||||||
|
# Ignore package tarball (built via "mix hex.build").
|
||||||
|
bob-*.tar
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
From the terminal, change to the base directory of the exercise then execute the tests with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mix test
|
||||||
|
```
|
||||||
|
|
||||||
|
This will execute the test file found in the `test` subfolder -- a file ending in `_test.exs`
|
||||||
|
|
||||||
|
Documentation:
|
||||||
|
|
||||||
|
* [`mix test` - Elixir's test execution tool](https://hexdocs.pm/mix/Mix.Tasks.Test.html)
|
||||||
|
* [`ExUnit` - Elixir's unit test library](https://hexdocs.pm/ex_unit/ExUnit.html)
|
||||||
|
|
||||||
|
## Pending tests
|
||||||
|
|
||||||
|
In test suites of practice exercises, all but the first test have been tagged to be 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:
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
# @tag :pending
|
||||||
|
test "shouting" do
|
||||||
|
assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
If you wish to run all tests at once, you can include all skipped test by using the `--include` flag on the `mix test` command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mix test --include pending
|
||||||
|
```
|
||||||
|
|
||||||
|
Or, you can enable all the tests by commenting out the `ExUnit.configure` line in the file `test/test_helper.exs`.
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
# ExUnit.configure(exclude: :pending, trace: true)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Useful `mix test` options
|
||||||
|
|
||||||
|
* `test/<FILE>.exs:LINENUM` - runs only a single test, the test from `<FILE>.exs` whose definition is on line `LINENUM`
|
||||||
|
* `--failed` - runs only tests that failed the last time they ran
|
||||||
|
* `--max-failures` - the suite stops evaluating tests when this number of test failures
|
||||||
|
is reached
|
||||||
|
* `--seed 0` - disables randomization so the tests in a single file will always be ran
|
||||||
|
in the same order they were defined in
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit lib/bob.ex` 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 [Elixir track's documentation](https://exercism.org/docs/tracks/elixir)
|
||||||
|
- The [Elixir track's programming category on the forum](https://forum.exercism.org/c/programming/elixir)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
If you're stuck on something, it may help to look at some of the [available resources](https://exercism.org/docs/tracks/elixir/resources) out there where answers might be found.
|
|
@ -0,0 +1,73 @@
|
||||||
|
# Bob
|
||||||
|
|
||||||
|
Welcome to Bob on Exercism's Elixir Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
|
||||||
|
Bob is a [lackadaisical][] teenager.
|
||||||
|
He likes to think that he's very cool.
|
||||||
|
And he definitely doesn't get excited about things.
|
||||||
|
That wouldn't be cool.
|
||||||
|
|
||||||
|
When people talk to him, his responses are pretty limited.
|
||||||
|
|
||||||
|
[lackadaisical]: https://www.collinsdictionary.com/dictionary/english/lackadaisical
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Your task is to determine what Bob will reply to someone when they say something to him or ask him a question.
|
||||||
|
|
||||||
|
Bob only ever answers one of five things:
|
||||||
|
|
||||||
|
- **"Sure."**
|
||||||
|
This is his response if you ask him a question, such as "How are you?"
|
||||||
|
The convention used for questions is that it ends with a question mark.
|
||||||
|
- **"Whoa, chill out!"**
|
||||||
|
This is his answer if you YELL AT HIM.
|
||||||
|
The convention used for yelling is ALL CAPITAL LETTERS.
|
||||||
|
- **"Calm down, I know what I'm doing!"**
|
||||||
|
This is what he says if you yell a question at him.
|
||||||
|
- **"Fine. Be that way!"**
|
||||||
|
This is how he responds to silence.
|
||||||
|
The convention used for silence is nothing, or various combinations of whitespace characters.
|
||||||
|
- **"Whatever."**
|
||||||
|
This is what he answers to anything else.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @rubysolo
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @andrewsardone
|
||||||
|
- @angelikatyborska
|
||||||
|
- @austinlyons
|
||||||
|
- @cbliard
|
||||||
|
- @Cohen-Carlisle
|
||||||
|
- @dalexj
|
||||||
|
- @devonestes
|
||||||
|
- @digitalronin
|
||||||
|
- @doncruse
|
||||||
|
- @etrepum
|
||||||
|
- @ghajba
|
||||||
|
- @kytrinyx
|
||||||
|
- @lpil
|
||||||
|
- @neenjaw
|
||||||
|
- @parkerl
|
||||||
|
- @pminten
|
||||||
|
- @rsslldnphy
|
||||||
|
- @seeflanigan
|
||||||
|
- @sotojuan
|
||||||
|
- @Teapane
|
||||||
|
- @tjcelaya
|
||||||
|
- @Tonkpils
|
||||||
|
- @victorpre
|
||||||
|
- @vladimir-tikhonov
|
||||||
|
- @waiting-for-dev
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - https://pine.fm/LearnToProgram/?Chapter=06
|
|
@ -0,0 +1,23 @@
|
||||||
|
defmodule Bob do
|
||||||
|
@spec hey(String.t()) :: String.t()
|
||||||
|
def hey(input) do
|
||||||
|
trimmed = String.trim(input)
|
||||||
|
|
||||||
|
is_yell? = String.upcase(trimmed) == trimmed and String.downcase(trimmed) != trimmed
|
||||||
|
is_question? = String.ends_with?(trimmed, "?")
|
||||||
|
is_silence? = trimmed == ""
|
||||||
|
|
||||||
|
cond do
|
||||||
|
is_silence? ->
|
||||||
|
"Fine. Be that way!"
|
||||||
|
is_yell? and is_question? ->
|
||||||
|
"Calm down, I know what I'm doing!"
|
||||||
|
is_question? ->
|
||||||
|
"Sure."
|
||||||
|
is_yell? ->
|
||||||
|
"Whoa, chill out!"
|
||||||
|
true ->
|
||||||
|
"Whatever."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,28 @@
|
||||||
|
defmodule Bob.MixProject do
|
||||||
|
use Mix.Project
|
||||||
|
|
||||||
|
def project do
|
||||||
|
[
|
||||||
|
app: :bob,
|
||||||
|
version: "0.1.0",
|
||||||
|
# elixir: "~> 1.8",
|
||||||
|
start_permanent: Mix.env() == :prod,
|
||||||
|
deps: deps()
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Run "mix help compile.app" to learn about applications.
|
||||||
|
def application do
|
||||||
|
[
|
||||||
|
extra_applications: [:logger]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Run "mix help deps" to learn about dependencies.
|
||||||
|
defp deps do
|
||||||
|
[
|
||||||
|
# {:dep_from_hexpm, "~> 0.3.0"},
|
||||||
|
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,142 @@
|
||||||
|
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
|
||||||
|
test "shouting gibberish" do
|
||||||
|
assert Bob.hey("FCECDFCAAB") == "Whoa, chill out!"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "asking a question" do
|
||||||
|
assert Bob.hey("Does this cryogenic chamber make me look fat?") == "Sure."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "asking a numeric question" do
|
||||||
|
assert Bob.hey("You are, what, like 15?") == "Sure."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "asking gibberish" do
|
||||||
|
assert Bob.hey("fffbbcbeab?") == "Sure."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "talking forcefully" do
|
||||||
|
assert Bob.hey("Hi there!") == "Whatever."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "using acronyms in regular speech" do
|
||||||
|
assert Bob.hey("It's OK if you don't want to go to the DMV.") == "Whatever."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "talking in capitals" do
|
||||||
|
assert Bob.hey("This Isn't Shouting!") == "Whatever."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "forceful question" do
|
||||||
|
assert Bob.hey("WHAT'S GOING ON?") == "Calm down, I know what I'm doing!"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "asking in capitals" do
|
||||||
|
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 THE DENTIST") == "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 "alternate silence" do
|
||||||
|
assert Bob.hey("\t\t\t\t\t\t\t\t\t\t") == "Fine. Be that way!"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "only numbers" do
|
||||||
|
assert Bob.hey("1, 2, 3") == "Whatever."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "multiple line question" do
|
||||||
|
assert Bob.hey("\nDoes this cryogenic chamber make me look fat?\nNo.") == "Whatever."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "question with numbers" do
|
||||||
|
assert Bob.hey("4?") == "Sure."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "non-letters with question" do
|
||||||
|
assert Bob.hey(":) ?") == "Sure."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "prattling on" do
|
||||||
|
assert Bob.hey("Wait! Hang on. Are you going to be OK?") == "Sure."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "starting with whitespace" do
|
||||||
|
assert Bob.hey(" hmmmmmmm...") == "Whatever."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "ending with whitespace" do
|
||||||
|
assert Bob.hey("Okay if like my spacebar quite a bit? ") == "Sure."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "other whitespace" do
|
||||||
|
assert Bob.hey("\n\r \t") == "Fine. Be that way!"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "non-question ending with whitespace" do
|
||||||
|
assert Bob.hey("This is a statement ending with whitespace ") == "Whatever."
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "shouting in Russian" do
|
||||||
|
assert Bob.hey("УХОДИ") == "Whoa, chill out!"
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
ExUnit.start()
|
||||||
|
ExUnit.configure(exclude: :pending, trace: true)
|
Loading…
Reference in New Issue