From 22b46519fd30a1a38f25069a4021c112a99cc22c Mon Sep 17 00:00:00 2001 From: Danylo Negrienko Date: Mon, 11 Mar 2024 11:44:09 -0400 Subject: [PATCH] acronym --- elixir/acronym/.exercism/config.json | 35 ++++++++++++ elixir/acronym/.exercism/metadata.json | 1 + elixir/acronym/.formatter.exs | 4 ++ elixir/acronym/.gitignore | 24 +++++++++ elixir/acronym/HELP.md | 75 ++++++++++++++++++++++++++ elixir/acronym/README.md | 49 +++++++++++++++++ elixir/acronym/lib/acronym.ex | 14 +++++ elixir/acronym/mix.exs | 28 ++++++++++ elixir/acronym/test/acronym_test.exs | 49 +++++++++++++++++ elixir/acronym/test/test_helper.exs | 2 + 10 files changed, 281 insertions(+) create mode 100644 elixir/acronym/.exercism/config.json create mode 100644 elixir/acronym/.exercism/metadata.json create mode 100644 elixir/acronym/.formatter.exs create mode 100644 elixir/acronym/.gitignore create mode 100644 elixir/acronym/HELP.md create mode 100644 elixir/acronym/README.md create mode 100644 elixir/acronym/lib/acronym.ex create mode 100644 elixir/acronym/mix.exs create mode 100644 elixir/acronym/test/acronym_test.exs create mode 100644 elixir/acronym/test/test_helper.exs diff --git a/elixir/acronym/.exercism/config.json b/elixir/acronym/.exercism/config.json new file mode 100644 index 0000000..ebfbc22 --- /dev/null +++ b/elixir/acronym/.exercism/config.json @@ -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" +} diff --git a/elixir/acronym/.exercism/metadata.json b/elixir/acronym/.exercism/metadata.json new file mode 100644 index 0000000..43f95c6 --- /dev/null +++ b/elixir/acronym/.exercism/metadata.json @@ -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} \ No newline at end of file diff --git a/elixir/acronym/.formatter.exs b/elixir/acronym/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/elixir/acronym/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/elixir/acronym/.gitignore b/elixir/acronym/.gitignore new file mode 100644 index 0000000..82b94cb --- /dev/null +++ b/elixir/acronym/.gitignore @@ -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 + diff --git a/elixir/acronym/HELP.md b/elixir/acronym/HELP.md new file mode 100644 index 0000000..b6158db --- /dev/null +++ b/elixir/acronym/HELP.md @@ -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/.exs:LINENUM` - runs only a single test, the test from `.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. \ No newline at end of file diff --git a/elixir/acronym/README.md b/elixir/acronym/README.md new file mode 100644 index 0000000..f4d300b --- /dev/null +++ b/elixir/acronym/README.md @@ -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 \ No newline at end of file diff --git a/elixir/acronym/lib/acronym.ex b/elixir/acronym/lib/acronym.ex new file mode 100644 index 0000000..b7521e2 --- /dev/null +++ b/elixir/acronym/lib/acronym.ex @@ -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 diff --git a/elixir/acronym/mix.exs b/elixir/acronym/mix.exs new file mode 100644 index 0000000..8a7eee6 --- /dev/null +++ b/elixir/acronym/mix.exs @@ -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 diff --git a/elixir/acronym/test/acronym_test.exs b/elixir/acronym/test/acronym_test.exs new file mode 100644 index 0000000..48421cc --- /dev/null +++ b/elixir/acronym/test/acronym_test.exs @@ -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 diff --git a/elixir/acronym/test/test_helper.exs b/elixir/acronym/test/test_helper.exs new file mode 100644 index 0000000..35fc5bf --- /dev/null +++ b/elixir/acronym/test/test_helper.exs @@ -0,0 +1,2 @@ +ExUnit.start() +ExUnit.configure(exclude: :pending, trace: true)