From b56a330d31f1940682bf1121770b1762f5588c86 Mon Sep 17 00:00:00 2001 From: Groophylifefor Date: Thu, 29 Feb 2024 23:10:15 +0300 Subject: [PATCH] feat: new exercise implementation. --- .../practice/raindrops/.docs/instructions.md | 24 +++ .../practice/raindrops/.meta/Example.bat | 25 +++ .../practice/raindrops/.meta/config.json | 17 ++ exercises/practice/raindrops/.meta/tests.toml | 13 ++ exercises/practice/raindrops/raindrops.bat | 9 + .../practice/raindrops/raindropsTest.bat | 174 ++++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 exercises/practice/raindrops/.docs/instructions.md create mode 100644 exercises/practice/raindrops/.meta/Example.bat create mode 100644 exercises/practice/raindrops/.meta/config.json create mode 100644 exercises/practice/raindrops/.meta/tests.toml create mode 100644 exercises/practice/raindrops/raindrops.bat create mode 100644 exercises/practice/raindrops/raindropsTest.bat diff --git a/exercises/practice/raindrops/.docs/instructions.md b/exercises/practice/raindrops/.docs/instructions.md new file mode 100644 index 0000000..16fb106 --- /dev/null +++ b/exercises/practice/raindrops/.docs/instructions.md @@ -0,0 +1,24 @@ +# Instructions + +Your task is to convert a number into its corresponding raindrop sounds. + +If a given number: + +- is divisible by 3, add "Pling" to the result. +- is divisible by 5, add "Plang" to the result. +- is divisible by 7, add "Plong" to the result. +- **is not** divisible by 3, 5, or 7, the result should be the number as a string. + +## Examples + +- 28 is divisible by 7, but not 3 or 5, so the result would be `"Plong"`. +- 30 is divisible by 3 and 5, but not 7, so the result would be `"PlingPlang"`. +- 34 is not divisible by 3, 5, or 7, so the result would be `"34"`. + +~~~~exercism/note +A common way to test if one number is evenly divisible by another is to compare the [remainder][remainder] or [modulus][modulo] to zero. +Most languages provide operators or functions for one (or both) of these. + +[remainder]: https://exercism.org/docs/programming/operators/remainder +[modulo]: https://en.wikipedia.org/wiki/Modulo_operation +~~~~ \ No newline at end of file diff --git a/exercises/practice/raindrops/.meta/Example.bat b/exercises/practice/raindrops/.meta/Example.bat new file mode 100644 index 0000000..b1e0172 --- /dev/null +++ b/exercises/practice/raindrops/.meta/Example.bat @@ -0,0 +1,25 @@ +@echo off +SETLOCAL EnableDelayedExpansion + +set "input=%~1" +set "result=" + +if "!input!"=="0" ( + set "result=0" +) else ( + if !input! gtr 0 ( + if !input! lss 3 ( + set "result=!input!" + ) else ( + set /a "mod3=!input! %% 3" + if !mod3!==0 set "result=Pling" + set /a "mod5=!input! %% 5" + if !mod5!==0 set "result=!result!Plang" + set /a "mod7=!input! %% 7" + if !mod7!==0 set "result=!result!Plong" + if not defined result set "result=%input%" + ) + ) +) + +echo !result! \ No newline at end of file diff --git a/exercises/practice/raindrops/.meta/config.json b/exercises/practice/raindrops/.meta/config.json new file mode 100644 index 0000000..e84ccae --- /dev/null +++ b/exercises/practice/raindrops/.meta/config.json @@ -0,0 +1,17 @@ +{ + "authors": ["GroophyLifefor"], + "files": { + "solution": [ + "raindrops.bat" + ], + "test": [ + "raindropsTest.bat" + ], + "example": [ + ".meta/Example.bat" + ] + }, + "blurb": "Convert a number into its corresponding raindrop sounds - Pling, Plang and Plong.", + "source": "A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division.", + "source_url": "https://en.wikipedia.org/wiki/Fizz_buzz" +} diff --git a/exercises/practice/raindrops/.meta/tests.toml b/exercises/practice/raindrops/.meta/tests.toml new file mode 100644 index 0000000..73466d6 --- /dev/null +++ b/exercises/practice/raindrops/.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/raindrops/raindrops.bat b/exercises/practice/raindrops/raindrops.bat new file mode 100644 index 0000000..33049d7 --- /dev/null +++ b/exercises/practice/raindrops/raindrops.bat @@ -0,0 +1,9 @@ +@echo off +SETLOCAL EnableDelayedExpansion + +set "input=%~1" +set "result=" + +REM Your code goes here + +echo !result! \ No newline at end of file diff --git a/exercises/practice/raindrops/raindropsTest.bat b/exercises/practice/raindrops/raindropsTest.bat new file mode 100644 index 0000000..78904bc --- /dev/null +++ b/exercises/practice/raindrops/raindropsTest.bat @@ -0,0 +1,174 @@ +@echo off +REM --------------------------------------------------- +REM Raindrops Unit Testing +REM --------------------------------------------------- + +:Main + REM Initalize result variable + set "slug=raindrops" + + CALL :Initialize + + REM -------------------- + REM Test Case Start \/\/ + REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/raindrops/canonical-data.json + REM -------------------- + set "expected=1" + set "if_success=Test passed" + set "if_failed=Test failed: the sound for 1 is 1." + CALL :Assert 1 + + set "expected=Pling" + set "if_success=Test passed" + set "if_failed=the sound for 3 is Pling." + CALL :Assert 3 + + set "expected=Plang" + set "if_success=Test passed" + set "if_failed=the sound for 5 is Plang." + CALL :Assert 5 + + set "expected=Plong" + set "if_success=Test passed" + set "if_failed=the sound for 7 is Plong." + CALL :Assert 7 + + set "expected=Pling" + set "if_success=Test passed" + set "if_failed=the sound for 6 is Pling as it has a factor 3." + CALL :Assert 6 + + set "expected=8" + set "if_success=Test passed" + set "if_failed=2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base." + CALL :Assert 8 + + set "expected=Pling" + set "if_success=Test passed" + set "if_failed=the sound for 9 is Pling as it has a factor 3." + CALL :Assert 9 + + set "expected=Plang" + set "if_success=Test passed" + set "if_failed=the sound for 10 is Plang as it has a factor 5." + CALL :Assert 10 + + set "expected=Plong" + set "if_success=Test passed" + set "if_failed=the sound for 14 is Plong as it has a factor of 7." + CALL :Assert 14 + + set "expected=PlingPlang" + set "if_success=Test passed" + set "if_failed=the sound for 15 is PlingPlang as it has factors 3 and 5." + CALL :Assert 15 + + set "expected=PlingPlong" + set "if_success=Test passed" + set "if_failed=the sound for 21 is PlingPlong as it has factors 3 and 7." + CALL :Assert 21 + + set "expected=Plang" + set "if_success=Test passed" + set "if_failed=the sound for 25 is Plang as it has a factor 5." + CALL :Assert 25 + + set "expected=Pling" + set "if_success=Test passed" + set "if_failed=the sound for 27 is Pling as it has a factor 3." + CALL :Assert 27 + + set "expected=PlangPlong" + set "if_success=Test passed" + set "if_failed=the sound for 35 is PlangPlong as it has factors 5 and 7." + CALL :Assert 35 + + set "expected=Plong" + set "if_success=Test passed" + set "if_failed=the sound for 49 is Plong as it has a factor 7." + CALL :Assert 49 + + set "expected=52" + set "if_success=Test passed" + set "if_failed=the sound for 52 is 52." + CALL :Assert 52 + + set "expected=PlingPlangPlong" + set "if_success=Test passed" + set "if_failed=the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7." + CALL :Assert 105 + + set "expected=Plang" + set "if_success=Test passed" + set "if_failed=the sound for 3125 is Plang as it has a factor 5." + CALL :Assert 3125 + + 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=