Skip to content

Commit

Permalink
Exercise/two fer (#21)
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
  • Loading branch information
GroophyLifefor authored Apr 2, 2024
1 parent 5279443 commit e4e3c8f
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
"practices": ["comparisons"],
"prerequisites": ["basics", "numbers", "comparisons", "conditionals"],
"difficulty": 1
},
{
"slug": "two-fer",
"name": "Two Fer",
"uuid": "fcde9a41-e1e7-4566-9c36-01158cb581c4",
"practices": ["function-arguments"],
"prerequisites": ["basics", "strings"],
"difficulty": 1
}
]
},
Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/two-fer/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Instructions

Your task is to determine what you will say as you give away the extra cookie.

If you know the person's name (e.g. if they're named Do-yun), then you will say:

```text
One for Do-yun, one for me.
```

If you don't know the person's name, you will say _you_ instead.

```text
One for you, one for me.
```

Here are some examples:

| Name | Dialogue |
| :----- | :-------------------------- |
| 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. |
12 changes: 12 additions & 0 deletions exercises/practice/two-fer/.meta/Example.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off

set "name=%~1"

if not defined name (
set "name=you"
)
if "%name%" EQU "" (
set "name=you"
)

echo One for %name%, one for me.
16 changes: 16 additions & 0 deletions exercises/practice/two-fer/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"authors": ["GroophyLifefor"],
"files": {
"solution": [
"TwoFer.bat"
],
"test": [
"TwoFerTest.bat"
],
"example": [
".meta/Example.bat"
]
},
"blurb": "Create a sentence of the form \"One for X, one for me.\".",
"source": "https://github.com/exercism/problem-specifications/issues/757"
}
13 changes: 13 additions & 0 deletions exercises/practice/two-fer/.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!"
6 changes: 6 additions & 0 deletions exercises/practice/two-fer/TwoFer.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off

set "name=%~1"

REM Your code goes here

106 changes: 106 additions & 0 deletions exercises/practice/two-fer/TwoFerTest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@echo off
REM ---------------------------------------------------
REM TwoFer Unit Testing
REM
REM sUnit Testing Framework version: 0.2
REM ---------------------------------------------------

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

CALL :Initialize

REM --------------------
REM Test Case Start \/\/
REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/darts/canonical-data.json
REM --------------------
set "expected=One for you, one for me."
set "if_success=Test passed"
set "if_failed=Test failed: no name given."
CALL :Assert ""

set "expected=One for you, one for me."
set "if_success=Test passed"
set "if_failed=Test failed: no name given."
CALL :Assert ""

set "expected=One for Alice, one for me."
set "if_success=Test passed"
set "if_failed=Test failed: a name given."
CALL :Assert "Alice"

set "expected=One for Bob, one for me."
set "if_success=Test passed"
set "if_failed=Test failed: another name given."
CALL :Assert "Bob"

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 e4e3c8f

Please sign in to comment.