acronym
This commit is contained in:
parent
d46a9b8e9a
commit
22b46519fd
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"authors": [
|
||||||
|
"Teapane"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"angelikatyborska",
|
||||||
|
"Cohen-Carlisle",
|
||||||
|
"dalexj",
|
||||||
|
"devonestes",
|
||||||
|
"gmile",
|
||||||
|
"henrik",
|
||||||
|
"jwworth",
|
||||||
|
"lpil",
|
||||||
|
"martinsvalin",
|
||||||
|
"neenjaw",
|
||||||
|
"parkerl",
|
||||||
|
"rubysolo",
|
||||||
|
"sotojuan",
|
||||||
|
"waiting-for-dev"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"lib/acronym.ex"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"test/acronym_test.exs"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.ex"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"blurb": "Convert a long phrase to its acronym.",
|
||||||
|
"source": "Julien Vanier",
|
||||||
|
"source_url": "https://github.com/monkbroc"
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{"track":"elixir","exercise":"acronym","id":"6e61a6a0f47e4396aad6d4854fe80fb4","url":"https://exercism.org/tracks/elixir/exercises/acronym","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").
|
||||||
|
acronym-*.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/acronym.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,49 @@
|
||||||
|
# Acronym
|
||||||
|
|
||||||
|
Welcome to Acronym on Exercism's Elixir Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Convert a phrase to its acronym.
|
||||||
|
|
||||||
|
Techies love their TLA (Three Letter Acronyms)!
|
||||||
|
|
||||||
|
Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).
|
||||||
|
|
||||||
|
Punctuation is handled as follows: hyphens are word separators (like whitespace); all other punctuation can be removed from the input.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
| Input | Output |
|
||||||
|
| ------------------------- | ------ |
|
||||||
|
| As Soon As Possible | ASAP |
|
||||||
|
| Liquid-crystal display | LCD |
|
||||||
|
| Thank George It's Friday! | TGIF |
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @Teapane
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @angelikatyborska
|
||||||
|
- @Cohen-Carlisle
|
||||||
|
- @dalexj
|
||||||
|
- @devonestes
|
||||||
|
- @gmile
|
||||||
|
- @henrik
|
||||||
|
- @jwworth
|
||||||
|
- @lpil
|
||||||
|
- @martinsvalin
|
||||||
|
- @neenjaw
|
||||||
|
- @parkerl
|
||||||
|
- @rubysolo
|
||||||
|
- @sotojuan
|
||||||
|
- @waiting-for-dev
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Julien Vanier - https://github.com/monkbroc
|
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule Acronym do
|
||||||
|
@doc """
|
||||||
|
Generate an acronym from a string.
|
||||||
|
"This is a string" => "TIAS"
|
||||||
|
"""
|
||||||
|
@spec abbreviate(String.t()) :: String.t()
|
||||||
|
def abbreviate(string) do
|
||||||
|
string
|
||||||
|
|> String.split([" ", "-", "_"], trim: true)
|
||||||
|
|> Enum.map(&String.first/1)
|
||||||
|
|> Enum.join()
|
||||||
|
|> String.upcase()
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,28 @@
|
||||||
|
defmodule Acronym.MixProject do
|
||||||
|
use Mix.Project
|
||||||
|
|
||||||
|
def project do
|
||||||
|
[
|
||||||
|
app: :acronym,
|
||||||
|
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,49 @@
|
||||||
|
defmodule AcronymTest do
|
||||||
|
use ExUnit.Case
|
||||||
|
|
||||||
|
test "it produces acronyms from title case" do
|
||||||
|
assert Acronym.abbreviate("Portable Networks Graphic") === "PNG"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "it produces acronyms from lower case" do
|
||||||
|
assert Acronym.abbreviate("Ruby on Rails") === "ROR"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "it ignores punctuation" do
|
||||||
|
assert Acronym.abbreviate("First in, First out") === "FIFO"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "it produces acronyms from phrases with acronyms" do
|
||||||
|
assert Acronym.abbreviate("GNU Image Manipulation Program") === "GIMP"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "it produces acronyms ignoring punctuation and casing" do
|
||||||
|
assert Acronym.abbreviate("Complementary Metal-Oxide semiconductor") === "CMOS"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "it produces a very long abbreviation" do
|
||||||
|
assert Acronym.abbreviate(
|
||||||
|
"Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
|
||||||
|
) === "ROTFLSHTMDCOALM"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "it produces acronyms from phrases with consecutive delimiters" do
|
||||||
|
assert Acronym.abbreviate("Something - I made up from thin air") === "SIMUFTA"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "it produces acronyms from phrases with apostrophes" do
|
||||||
|
assert Acronym.abbreviate("Halley's Comet") === "HC"
|
||||||
|
end
|
||||||
|
|
||||||
|
# @tag :pending
|
||||||
|
test "it produces acronyms from phrases with underscore emphasis" do
|
||||||
|
assert Acronym.abbreviate("The Road _Not_ Taken") === "TRNT"
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
ExUnit.start()
|
||||||
|
ExUnit.configure(exclude: :pending, trace: true)
|
Loading…
Reference in New Issue