From 60b712810b78b578f3ebdfbadb46eb194880735c Mon Sep 17 00:00:00 2001 From: glaxxie <86179463+glaxxie@users.noreply.github.com> Date: Tue, 5 Mar 2024 19:45:53 -0600 Subject: [PATCH] [New Exercise]: Acronym --- config.json | 8 +++ .../practice/acronym/.docs/instructions.md | 17 ++++++ exercises/practice/acronym/.meta/config.json | 19 +++++++ exercises/practice/acronym/.meta/example.gd | 7 +++ exercises/practice/acronym/.meta/tests.toml | 37 +++++++++++++ exercises/practice/acronym/acronym.gd | 2 + exercises/practice/acronym/acronym_test.gd | 54 +++++++++++++++++++ 7 files changed, 144 insertions(+) create mode 100644 exercises/practice/acronym/.docs/instructions.md create mode 100644 exercises/practice/acronym/.meta/config.json create mode 100644 exercises/practice/acronym/.meta/example.gd create mode 100644 exercises/practice/acronym/.meta/tests.toml create mode 100644 exercises/practice/acronym/acronym.gd create mode 100644 exercises/practice/acronym/acronym_test.gd diff --git a/config.json b/config.json index 87a05ba..1b5ce19 100644 --- a/config.json +++ b/config.json @@ -139,6 +139,14 @@ "prerequisites": [], "difficulty": 2 }, + { + "slug": "acronym", + "name": "Acronym", + "uuid": "b83cec41-58c0-46ff-9fc9-10947d606f0f", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "flatten-array", "name": "Flatten Array", diff --git a/exercises/practice/acronym/.docs/instructions.md b/exercises/practice/acronym/.docs/instructions.md new file mode 100644 index 0000000..133bd2c --- /dev/null +++ b/exercises/practice/acronym/.docs/instructions.md @@ -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 | diff --git a/exercises/practice/acronym/.meta/config.json b/exercises/practice/acronym/.meta/config.json new file mode 100644 index 0000000..fedc30e --- /dev/null +++ b/exercises/practice/acronym/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "glaxxie" + ], + "files": { + "solution": [ + "acronym.gd" + ], + "test": [ + "acronym_test.gd" + ], + "example": [ + ".meta/example.gd" + ] + }, + "blurb": "Convert a long phrase to its acronym.", + "source": "Julien Vanier", + "source_url": "https://github.com/monkbroc" +} diff --git a/exercises/practice/acronym/.meta/example.gd b/exercises/practice/acronym/.meta/example.gd new file mode 100644 index 0000000..0da3532 --- /dev/null +++ b/exercises/practice/acronym/.meta/example.gd @@ -0,0 +1,7 @@ +func acronym(phrase): + var regex = RegEx.new() + regex.compile("\\p{L}+'?\\p{L}*") + var result = [] + for word in regex.search_all(phrase): + result.append(word.get_string()[0].to_upper()) + return "".join(result) diff --git a/exercises/practice/acronym/.meta/tests.toml b/exercises/practice/acronym/.meta/tests.toml new file mode 100644 index 0000000..6e3277c --- /dev/null +++ b/exercises/practice/acronym/.meta/tests.toml @@ -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" diff --git a/exercises/practice/acronym/acronym.gd b/exercises/practice/acronym/acronym.gd new file mode 100644 index 0000000..5f20697 --- /dev/null +++ b/exercises/practice/acronym/acronym.gd @@ -0,0 +1,2 @@ +func acronym(phrase): + pass diff --git a/exercises/practice/acronym/acronym_test.gd b/exercises/practice/acronym/acronym_test.gd new file mode 100644 index 0000000..b8ecfb4 --- /dev/null +++ b/exercises/practice/acronym/acronym_test.gd @@ -0,0 +1,54 @@ +func test_basic(solution_script): + var value = "Portable Networks Graphic" + var expected = "PNG" + return [solution_script.acronym(value), expected] + + +func test_lowercase_words(solution_script): + var value = "Ruby on Rails" + var expected = "ROR" + return [solution_script.acronym(value), expected] + + +func test_punctuation(solution_script): + var value = "First in, First out" + var expected = "FIFO" + return [solution_script.acronym(value), expected] + + +func test_all_caps_word(solution_script): + var value = "GNU Image Manipulation Program" + var expected = "GIMP" + return [solution_script.acronym(value), expected] + + +func test_punctuation_without_whitespace(solution_script): + var value = "Complementary Metal-Oxide semiconductor" + var expected = "CMOS" + return [solution_script.acronym(value), expected] + + +func test_very_long_abbreviation(solution_script): + var value = "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me" + var expected = "ROTFLSHTMDCOALM" + return [solution_script.acronym(value), expected] + + +func test_consecutive_delimiters(solution_script): + var value = "Something - I made up from thin air" + var expected = "SIMUFTA" + return [solution_script.acronym(value), expected] + + +func test_apostrophes(solution_script): + var value = "Halley's Comet" + var expected = "HC" + return [solution_script.acronym(value), expected] + + +func test_underscore_emphasis(solution_script): + var value = "The Road _Not_ Taken" + var expected = "TRNT" + return [solution_script.acronym(value), expected] + +