Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New exercise added with all tests passed #14

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@
],
"prerequisites": [],
"difficulty": 1
},
{
"uuid": "09af4822-c1da-4581-a88e-b44bbe275607",
"slug": "nucleotide-count",
"name": "Nucleotide Count",
"practices": [
"basics",
"loops",
"arrays",
"conditionals"
],
"prerequisites": [],
"difficulty": 1
}
]
},
Expand Down
23 changes: 23 additions & 0 deletions exercises/practice/nucleotide-count/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Description

Each of us inherits from our biological parents a set of chemical instructions known as DNA that influence how our bodies are constructed.
All known life depends on DNA!

> Note: You do not need to understand anything about nucleotides or DNA to complete this exercise.
DNA is a long chain of other chemicals and the most important are the four nucleotides, adenine, cytosine, guanine and thymine.
A single DNA chain can contain billions of these four nucleotides and the order in which they occur is important!
We call the order of these nucleotides in a bit of DNA a "DNA sequence".

We represent a DNA sequence as an ordered collection of these four nucleotides and a common way to do that is with a string of characters such as "ATTACG" for a DNA sequence of 6 nucleotides.
'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' for thymine.

Given a string representing a DNA sequence, count how many of each nucleotide is present.
If the string contains characters that aren't A, C, G, or T then it is invalid and you should signal an error.

For example:

```text
"GATTACA" -> 'A': 3, 'C': 1, 'G': 1, 'T': 2
"INVALID" -> error
```
24 changes: 24 additions & 0 deletions exercises/practice/nucleotide-count/.meta/Example.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@echo off
SETLOCAL EnableDelayedExpansion

set "nucleotide=%~1"
set "nucleotide[A]=0"
set "nucleotide[C]=0"
set "nucleotide[G]=0"
set "nucleotide[T]=0"

if "!nucleotide!"=="" goto :display_result
for /f "delims=ACGT" %%A in ("%nucleotide%") do (
echo Invalid nucleotide in strand
exit /b
)

set "index=0"
:strand_walker
if "!nucleotide:~%index%,1!"=="" goto :display_result
set /a "nucleotide[!nucleotide:~%index%,1!]+=1"
set /a index+=1
goto :strand_walker

:display_result
echo !nucleotide[A]!,!nucleotide[C]!,!nucleotide[G]!,!nucleotide[T]!
17 changes: 17 additions & 0 deletions exercises/practice/nucleotide-count/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"authors": ["sintrode", "GroophyLifefor"],
"files": {
"solution": [
"NucleotideCount.bat"
],
"test": [
"NucleotideCountTest.bat"
],
"example": [
".meta/Example.bat"
]
},
"blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.",
"source": "The Calculating DNA Nucleotides_problem at Rosalind",
"source_url": "https://rosalind.info/problems/dna/"
}
13 changes: 13 additions & 0 deletions exercises/practice/nucleotide-count/.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!"
13 changes: 13 additions & 0 deletions exercises/practice/nucleotide-count/NucleotideCount.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off
SETLOCAL EnableDelayedExpansion

set "nucleotide=%~1"
set "nucleotide[A]=0"
set "nucleotide[C]=0"
set "nucleotide[G]=0"
set "nucleotide[T]=0"

REM Your code goes here


echo !nucleotide[A]!,!nucleotide[C]!,!nucleotide[G]!,!nucleotide[T]!
109 changes: 109 additions & 0 deletions exercises/practice/nucleotide-count/NucleotideCountTest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
@echo off
REM ---------------------------------------------------
REM NucleotideCount Unit Testing
REM ---------------------------------------------------

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

CALL :Initialize

REM --------------------
REM Test Case Start \/\/
REM Resource: https://github.com/exercism/problem-specifications/blob/ce02684e726a1b78a1c1e591188e4e268fd27b15/exercises/nucleotide-count/canonical-data.json
REM --------------------
set "expected=0,0,0,0"
set "if_success=Test passed"
set "if_failed=Test failed: empty strand."
CALL :Assert ""

set "expected=0,0,1,0"
set "if_success=Test passed"
set "if_failed=Test failed: can count one nucleotide in single-character input."
CALL :Assert "G"

set "expected=0,0,7,0"
set "if_success=Test passed"
set "if_failed=Test failed: strand with repeated nucleotide."
CALL :Assert "GGGGGGG"

set "expected=20,12,17,21"
set "if_success=Test passed"
set "if_failed=Test failed: strand with multiple nucleotides."
CALL :Assert "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"

set "expected=Invalid nucleotide in strand"
set "if_success=Test passed"
set "if_failed=Test failed: strand with invalid nucleotides - Print just 'Invalid nucleotide in strand'."
CALL :Assert "AGXXACT"

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