Skip to content

Commit

Permalink
feat: new exercise implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
GroophyLifefor committed Feb 29, 2024
1 parent a42c299 commit b56a330
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 0 deletions.
24 changes: 24 additions & 0 deletions exercises/practice/raindrops/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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
~~~~
25 changes: 25 additions & 0 deletions exercises/practice/raindrops/.meta/Example.bat
Original file line number Diff line number Diff line change
@@ -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!
17 changes: 17 additions & 0 deletions exercises/practice/raindrops/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
13 changes: 13 additions & 0 deletions exercises/practice/raindrops/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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!"
9 changes: 9 additions & 0 deletions exercises/practice/raindrops/raindrops.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off
SETLOCAL EnableDelayedExpansion

set "input=%~1"
set "result="

REM Your code goes here

echo !result!
174 changes: 174 additions & 0 deletions exercises/practice/raindrops/raindropsTest.bat
Original file line number Diff line number Diff line change
@@ -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=<stdout.bin
del stdout.bin

REM Check if the result is correct
if "%stdout%" == "%expected%" (
if defined if_success (
echo %if_success%

REM Reset the variable to avoid duplicating the message.
set "if_success="
set "if_failed="
)

REM If the result is correct, exit with code 0
set /a successCount+=1
exit /b 0
) else (
if defined if_failed (
echo %if_failed%

REM Reset the variable to avoid duplicating the message.
set "if_success="
set "if_failed="
)

REM If the result is incorrect, exit with code 1
set /a failCount+=1
exit /b 1
)
GOTO :EOF REM Go back to the line after the call to :Assert

:Initialize
REM It's for initialize, not about checking empty file
set "successCount=0"
set "failCount=0"
GOTO :EOF REM Go back to the line after the call to :CheckEmptyFile

:ResolveStatus
set "status="
if %failCount% gtr 0 (
REM status: Fail
REM message: The test failed.
exit /b 1

) else (
REM status: Pass
exit /b 0

)
GOTO :EOF REM Go back to the line after the call to :ExportResultAsJson

:End

0 comments on commit b56a330

Please sign in to comment.