Skip to content

Commit

Permalink
Exercise/reverse string (#22)
Browse files Browse the repository at this point in the history
* feat: new exercise hamming added

* fix: CI/CD added to config and added some prerequisites

* New exercise - darts

* fix: CI/CD

* New exercise - Two-Fer

* new exercise - reverse-string

* CI/CD fix
  • Loading branch information
GroophyLifefor authored Apr 3, 2024
1 parent e4e3c8f commit 2100903
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 1 deletion.
12 changes: 12 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@
"practices": ["function-arguments"],
"prerequisites": ["basics", "strings"],
"difficulty": 1
},
{
"slug": "reverse-string",
"name": "Reverse String",
"uuid": "ba8c915a-85c0-4798-b21f-4adf4268b606",
"practices": [
"loops",
"strings"
],
"prerequisites": [],
"difficulty": 1,
"topics": []
}
]
},
Expand Down
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Instructions

Your task is to reverse a given string.

Some examples:

- Turn `"stressed"` into `"desserts"`.
- Turn `"strops"` into `"sports"`.
- Turn `"racecar"` into `"racecar"`.
20 changes: 20 additions & 0 deletions exercises/practice/reverse-string/.meta/Example.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off
setlocal enabledelayedexpansion

set "str=%~1"
set "rev="

if not defined str (
echo.
exit /b
)

:loop
if defined str (
set "char=!str:~0,1!"
set "rev=!char!!rev!"
set "str=!str:~1!"
goto loop
)
echo %rev%
exit /b
16 changes: 16 additions & 0 deletions exercises/practice/reverse-string/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"authors": ["GroophyLifefor"],
"files": {
"solution": [
"ReverseString.bat"
],
"test": [
"ReverseStringTest.bat"
],
"example": [
".meta/Example.bat"
]
},
"blurb": "Reverse a given string.",
"source": "Introductory challenge to reverse an input string"
}
13 changes: 13 additions & 0 deletions exercises/practice/reverse-string/.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!"
10 changes: 10 additions & 0 deletions exercises/practice/reverse-string/ReverseString.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off
setlocal enabledelayedexpansion

set "str=%~1"
set "rev="

REM Your code goes here


echo %rev%
111 changes: 111 additions & 0 deletions exercises/practice/reverse-string/ReverseStringTest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
@echo off
REM ---------------------------------------------------
REM Reverse String Unit Testing
REM
REM sUnit Testing Framework version: 0.2
REM ---------------------------------------------------

:Main
REM Initalize result variable
set "slug=ReverseString"

CALL :Initialize

REM --------------------
REM Test Case Start \/\/
REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/reverse-string/canonical-data.json
REM --------------------
set "expected="
set "if_success=Test passed"
set "if_failed=Test failed: an empty string."
CALL :Assert ""

set "expected=tobor"
set "if_success=Test passed"
set "if_failed=Test failed: a word."
CALL :Assert "robot"

set "expected=nemaR"
set "if_success=Test passed"
set "if_failed=Test failed: a capitalized word."
CALL :Assert "Ramen"

set "expected=racecar"
set "if_success=Test passed"
set "if_failed=Test failed: a palindrome."
CALL :Assert "racecar"

set "expected=reward"
set "if_success=Test passed"
set "if_failed=Test failed: an even-sized word."
CALL :Assert "drawer"

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
2 changes: 1 addition & 1 deletion exercises/practice/two-fer/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Here are some examples:
| Alice | One for Alice, one for me. |
| Bohdan | One for Bohdan, one for me. |
| | One for you, one for me. |
| Zaphod | One for Zaphod, one for me. |
| Zaphod | One for Zaphod, one for me. |

0 comments on commit 2100903

Please sign in to comment.