diff --git a/elixir/acronym/.exercism/metadata.json b/elixir/acronym/.exercism/metadata.json new file mode 100644 index 0000000..336eabf --- /dev/null +++ b/elixir/acronym/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"elixir","exercise":"acronym","id":"f0e509924ee3483c83a8e3f370eade53","url":"https://exercism.io/my/solutions/f0e509924ee3483c83a8e3f370eade53","handle":"Xevion","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/README.md b/elixir/acronym/README.md new file mode 100644 index 0000000..d090170 --- /dev/null +++ b/elixir/acronym/README.md @@ -0,0 +1,50 @@ +# Acronym + +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). + +## Running tests + +Execute the tests with: + +```bash +$ 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: + +```elixir +# @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. + +```elixir +# ExUnit.configure exclude: :pending, trace: true +``` + +If you're stuck on something, it may help to look at some of +the [available resources](https://exercism.io/tracks/elixir/resources) +out there where answers might be found. + +## Source + +Julien Vanier [https://github.com/monkbroc](https://github.com/monkbroc) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/elixir/acronym/lib/acronym.ex b/elixir/acronym/lib/acronym.ex new file mode 100644 index 0000000..9f7e661 --- /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(~r/\s|[-]|(?<=[a-z])-(?=[A-Z])|(?<=[a-z])(?=[A-Z])/) + |> Enum.filter(&String.match?(&1, ~r/^\w/)) + |> Enum.map(&String.upcase(String.at(String.trim(&1, "_"), 0))) + |> Enum.join("") + 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..bcea3fa --- /dev/null +++ b/elixir/acronym/test/acronym_test.exs @@ -0,0 +1,55 @@ +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 + + # Track specific test case: additional case + @tag :pending + test "it produces acronyms from inconsistent case" do + assert Acronym.abbreviate("HyperText Markup Language") === "HTML" + end +end diff --git a/elixir/acronym/test/test_helper.exs b/elixir/acronym/test/test_helper.exs new file mode 100644 index 0000000..0ee8618 --- /dev/null +++ b/elixir/acronym/test/test_helper.exs @@ -0,0 +1,2 @@ +ExUnit.start() +# ExUnit.configure(exclude: :pending, trace: true)