From 2ddfa24e4565c1546c4bc61b242c261601ccfa1b Mon Sep 17 00:00:00 2001 From: Groophylifefor Date: Tue, 5 Mar 2024 15:39:49 +0300 Subject: [PATCH] feat: new exercise - acronym --- .../practice/acronym/.docs/instructions.md | 17 +++ exercises/practice/acronym/.meta/Example.bat | 20 +++ exercises/practice/acronym/.meta/config.json | 17 +++ exercises/practice/acronym/.meta/tests.toml | 13 ++ exercises/practice/acronym/Acronym.bat | 10 ++ exercises/practice/acronym/AcronymTest.bat | 131 ++++++++++++++++++ 6 files changed, 208 insertions(+) create mode 100644 exercises/practice/acronym/.docs/instructions.md create mode 100644 exercises/practice/acronym/.meta/Example.bat create mode 100644 exercises/practice/acronym/.meta/config.json create mode 100644 exercises/practice/acronym/.meta/tests.toml create mode 100644 exercises/practice/acronym/Acronym.bat create mode 100644 exercises/practice/acronym/AcronymTest.bat diff --git a/exercises/practice/acronym/.docs/instructions.md b/exercises/practice/acronym/.docs/instructions.md new file mode 100644 index 0000000..657ed84 --- /dev/null +++ b/exercises/practice/acronym/.docs/instructions.md @@ -0,0 +1,17 @@ +# Description + +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/Example.bat b/exercises/practice/acronym/.meta/Example.bat new file mode 100644 index 0000000..9ef8abb --- /dev/null +++ b/exercises/practice/acronym/.meta/Example.bat @@ -0,0 +1,20 @@ +@echo off +setlocal enabledelayedexpansion + +set "phrase=%~1 %~2 %~3 %~4 %~5 %~6 %~7 %~8 %~9" +set "acronym=" + +REM replace some of special characters which cmd interpeter care. +set "phrase=%phrase:-= %" +set "phrase=%phrase:_= %" + +for %%a in (%phrase%) do ( + set "word=%%~a" + set "word=!word:~0,1!" + set "acronym=!acronym!!word!" +) + +REM Uppercase output +for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do set "acronym=!acronym:%%A=%%A!" + +echo !acronym! diff --git a/exercises/practice/acronym/.meta/config.json b/exercises/practice/acronym/.meta/config.json new file mode 100644 index 0000000..07d6923 --- /dev/null +++ b/exercises/practice/acronym/.meta/config.json @@ -0,0 +1,17 @@ +{ + "authors": ["GroophyLifefor"], + "files": { + "solution": [ + "Acronym.bat" + ], + "test": [ + "AcronymTest.bat" + ], + "example": [ + ".meta/Example.bat" + ] + }, + "blurb": "Convert a long phrase to its acronym.", + "source": "Julien Vanier", + "source_url": "https://github.com/monkbroc/" +} diff --git a/exercises/practice/acronym/.meta/tests.toml b/exercises/practice/acronym/.meta/tests.toml new file mode 100644 index 0000000..73466d6 --- /dev/null +++ b/exercises/practice/acronym/.meta/tests.toml @@ -0,0 +1,13 @@ +# 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. + +[af9ffe10-dc13-42d8-a742-e7bdafac449d] +description = "Say Hi!" diff --git a/exercises/practice/acronym/Acronym.bat b/exercises/practice/acronym/Acronym.bat new file mode 100644 index 0000000..740bb05 --- /dev/null +++ b/exercises/practice/acronym/Acronym.bat @@ -0,0 +1,10 @@ +@echo off +setlocal enabledelayedexpansion + +set "phrase=%~1 %~2 %~3 %~4 %~5 %~6 %~7 %~8 %~9" +set "acronym=" + +REM Your code goes here + + +echo !acronym! diff --git a/exercises/practice/acronym/AcronymTest.bat b/exercises/practice/acronym/AcronymTest.bat new file mode 100644 index 0000000..0576a2f --- /dev/null +++ b/exercises/practice/acronym/AcronymTest.bat @@ -0,0 +1,131 @@ +@echo off +REM --------------------------------------------------- +REM Acronym Unit Testing +REM +REM sUnit Testing Framework version: 0.2 +REM --------------------------------------------------- + +:Main + REM Initalize result variable + set "slug=acronym" + + CALL :Initialize + + REM -------------------- + REM Test Case Start \/\/ + REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/acronym/canonical-data.json + REM -------------------- + set "expected=PNG" + set "if_success=Test passed" + set "if_failed=Test failed: basic." + CALL :Assert "Portable Network Graphics" + + set "expected=ROR" + set "if_success=Test passed" + set "if_failed=Test failed: lowercase words." + CALL :Assert "Ruby on Rails" + + set "expected=FIFO" + set "if_success=Test passed" + set "if_failed=Test failed: punctuation." + CALL :Assert "First In, First Out" + + set "expected=GIMP" + set "if_success=Test passed" + set "if_failed=Test failed: all caps word." + CALL :Assert "GNU Image Manipulation Program" + + set "expected=CMOS" + set "if_success=Test passed" + set "if_failed=Test failed: punctuation without whitespace." + CALL :Assert "Complementary metal-oxide semiconductor" + + set "expected=ROTFLSHTMDCOALM" + set "if_success=Test passed" + set "if_failed=Test failed: very long abbreviation." + CALL :Assert "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me" + + set "expected=SIMUFTA" + set "if_success=Test passed" + set "if_failed=Test failed: consecutive delimiters." + CALL :Assert "Something - I made up from thin air" + + set "expected=HC" + set "if_success=Test passed" + set "if_failed=Test failed: apostrophes." + CALL :Assert "Halley's Comet" + + set "expected=TRNT" + set "if_success=Test passed" + set "if_failed=Test failed: underscore emphasis." + CALL :Assert "The Road _Not_ Taken" + + REM -------------------- + REM Test Case End /\/\/\ + REM -------------------- + + CALL :ResolveStatus + exit /b %errorlevel% +REM End of Main + +REM --------------------------------------------------- +REM Assert [..Parameters(up to 9)] +REM --------------------------------------------------- +GOTO :End REM Prevents the code below from being executed +:Assert +set "stdout=" + +REM Run the program and capture the output then delete the file +CALL %slug%.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 > stdout.bin 2>&1 +set /p stdout=