Skip to content

Commit

Permalink
Add acronym (#597)
Browse files Browse the repository at this point in the history
* Add acronym

* Fix example module name
  • Loading branch information
BNAndras authored Aug 15, 2024
1 parent a19032c commit 091266d
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@
"strings"
]
},
{
"slug": "acronym",
"name": "Acronym",
"uuid": "16e89060-3e51-46d2-8dc2-88082b83254f",
"practices": [],
"prerequisites": [],
"difficulty": 2,
"topics": [
"pattern_matching",
"strings"
]
},
{
"slug": "bob",
"name": "Bob",
Expand Down
17 changes: 17 additions & 0 deletions exercises/practice/acronym/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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 |
19 changes: 19 additions & 0 deletions exercises/practice/acronym/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"BNAndras"
],
"files": {
"solution": [
"src/acronym.erl"
],
"test": [
"test/acronym_tests.erl"
],
"example": [
".meta/example.erl"
]
},
"blurb": "Convert a long phrase to its acronym.",
"source": "Julien Vanier",
"source_url": "https://github.com/monkbroc"
}
19 changes: 19 additions & 0 deletions exercises/practice/acronym/.meta/example.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(example).

-export([abbreviate/1]).

abbreviate(Phrase) ->
abbreviate(Phrase, []).

abbreviate([First, Second | Rest], Acc) when First >= $A, First =< $Z, Second >= $A, Second =< $Z ->
abbreviate([First | Rest], Acc);
abbreviate([First | Rest], Acc) when First >= $A, First =< $Z ->
abbreviate(Rest, [First | Acc]);
abbreviate([First, Second | Rest], Acc) when First == $\s orelse First == $- orelse First == $_,
Second /= $\s, Second /= $-, Second /= $_->
abbreviate(Rest, [Second | Acc]);
abbreviate([_ | Rest], Acc) ->
abbreviate(Rest, Acc);
abbreviate([], Acc) ->
string:uppercase(lists:reverse(Acc)).

37 changes: 37 additions & 0 deletions exercises/practice/acronym/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[1e22cceb-c5e4-4562-9afe-aef07ad1eaf4]
description = "basic"

[79ae3889-a5c0-4b01-baf0-232d31180c08]
description = "lowercase words"

[ec7000a7-3931-4a17-890e-33ca2073a548]
description = "punctuation"

[32dd261c-0c92-469a-9c5c-b192e94a63b0]
description = "all caps word"

[ae2ac9fa-a606-4d05-8244-3bcc4659c1d4]
description = "punctuation without whitespace"

[0e4b1e7c-1a6d-48fb-81a7-bf65eb9e69f9]
description = "very long abbreviation"

[6a078f49-c68d-4b7b-89af-33a1a98c28cc]
description = "consecutive delimiters"

[5118b4b1-4572-434c-8d57-5b762e57973e]
description = "apostrophes"

[adc12eab-ec2d-414f-b48c-66a4fc06cdef]
description = "underscore emphasis"
30 changes: 30 additions & 0 deletions exercises/practice/acronym/rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%% Erlang compiler options
{erl_opts, [debug_info, warnings_as_errors]}.

{deps, [{erl_exercism, "0.1.2"}]}.

{dialyzer, [
{warnings, [underspecs, no_return]},
{get_warnings, true},
{plt_apps, top_level_deps}, % top_level_deps | all_deps
{plt_extra_apps, []},
{plt_location, local}, % local | "/my/file/name"
{plt_prefix, "rebar3"},
{base_plt_apps, [stdlib, kernel, crypto]},
{base_plt_location, global}, % global | "/my/file/name"
{base_plt_prefix, "rebar3"}
]}.

%% eunit:test(Tests)
{eunit_tests, []}.
%% Options for eunit:test(Tests, Opts)
{eunit_opts, [verbose]}.

%% == xref ==

{xref_warnings, true}.

%% xref checks to run
{xref_checks, [undefined_function_calls, undefined_functions,
locals_not_used, exports_not_used,
deprecated_function_calls, deprecated_functions]}.
9 changes: 9 additions & 0 deletions exercises/practice/acronym/src/acronym.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{application, acronym,
[{description, "exercism.org - acronym"},
{vsn, "0.0.0"},
{modules, []},
{registered, []},
{applications, [kernel,
stdlib]},
{env, []}
]}.
6 changes: 6 additions & 0 deletions exercises/practice/acronym/src/acronym.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-module(acronym).

-export([abbreviate/1]).


abbreviate(_Phrase) -> undefined.
70 changes: 70 additions & 0 deletions exercises/practice/acronym/test/acronym_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-module(acronym_tests).

-include_lib("erl_exercism/include/exercism.hrl").
-include_lib("eunit/include/eunit.hrl").




'1_basic_test_'() ->
Input = "Portable Network Graphics",
Expected = "PNG",
{"basic",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

'2_lowercase_words_test_'() ->
Input = "Ruby on Rails",
Expected = "ROR",
{"lowercase words",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

'3_punctuation_test_'() ->
Input = "First In, First Out",
Expected = "FIFO",
{"punctuation",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

'4_all_caps_words_test_'() ->
Input = "GNU Image Manipulation Program",
Expected = "GIMP",
{"all caps word",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

'5_punctuation_without_whitespace_test_'() ->
Input = "Complementary metal-oxide semiconductor",
Expected = "CMOS",
{"punctuation without whitespace",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

'6_very_long_abbreviation_test_'() ->
Input = "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me",
Expected = "ROTFLSHTMDCOALM",
{"very long abbreviation",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

'7_consecutive_delimiters_test_'() ->
Input = "Something - I made up from thin air",
Expected = "SIMUFTA",
{"consecutive delimiters",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

'8_apostrophes_test_'() ->
Input = "Halley's Comet",
Expected = "HC",
{"apostrophes",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

'9_underscore_emphasis_test_'() ->
Input = "The Road _Not_ Taken",
Expected = "TRNT",
{"underscore emphasis",
?_assertEqual(Expected,
acronym:abbreviate(Input))}.

0 comments on commit 091266d

Please sign in to comment.