From 835af7f9e8e8fdcacdda321fd32a84a4fc615234 Mon Sep 17 00:00:00 2001 From: Teppo Saari Date: Sat, 20 Apr 2024 14:25:31 +0300 Subject: [PATCH] 1 new exercise: protein-translation (#125) * adding protein-translation * fixed config.json for protein-translation * fixing .cut file + proof * Update exercises/practice/protein-translation/bin/fetch-cobolcheck.ps1 Co-authored-by: Victor Goff * Update exercises/practice/protein-translation/src/protein-translation.cob Co-authored-by: Victor Goff * Sync the `scrabble-score` exercise's docs with the latest data. (#126) * Sync the `all-your-base` exercise's docs with the latest data. (#127) * Simplify test workflow (#129) * Format config.json file (#131) * file patterns (#132) * Add file patterns * Update files keys * Pre-fetch cobolcheck (#130) * Pre-fetch cobolcheck * Use home dir * Fetch cobolcheck on windows * Allow for pre-installed cobolcheck * from appveyor to sourceforge (#128) * from appveyor to sourceforge * different server * 7z * 7z * yaml issue fixed * slashes * 7z oddities * directories * $HOME ? * atbash tweak * cache management fix * commented out extraneous DISPLAY in proof.ci.cob files * eol issue * line ends fixed * strangenesses * SPACE instead of "" in CUT files * Trim additional line * Debug * Try simplify environment variables * More debugging * More tweaking * Fix path * Fix path * Fix path * Fix env * Streamline * eof is lf * acronym * acronym * sqrt * Fix paths * Fix cache path --------- Co-authored-by: Erik Schierboom * Try fix Windows caching (#133) * Try fix caching * Try fix cache path * Try include cobolcheck * Try include cobolcheck * Use home dir * Use home dir * Update proof.ci.cob (#135) function all intrinsic on its own line * Cache on linux (#134) * Try install * CONCAT -> CONCATENATE * CONCATENATE is two-fer --------- Co-authored-by: Bruce Axtens --------- Co-authored-by: Bruce Axtens Co-authored-by: Victor Goff Co-authored-by: Erik Schierboom --- config.json | 8 + .../protein-translation/.docs/instructions.md | 42 ++++ .../protein-translation/.docs/introduction.md | 42 ++++ .../protein-translation/.meta/config.json | 22 +++ .../protein-translation/.meta/proof.ci.cob | 96 +++++++++ .../protein-translation/bin/fetch-cobolcheck | 63 ++++++ .../bin/fetch-cobolcheck.ps1 | 28 +++ .../protein-translation/config.properties | 183 ++++++++++++++++++ .../src/protein-translation.cob | 15 ++ .../practice/protein-translation/test.ps1 | 16 ++ .../practice/protein-translation/test.sh | 20 ++ .../protein-translation.cut | 149 ++++++++++++++ 12 files changed, 684 insertions(+) create mode 100644 exercises/practice/protein-translation/.docs/instructions.md create mode 100644 exercises/practice/protein-translation/.docs/introduction.md create mode 100644 exercises/practice/protein-translation/.meta/config.json create mode 100644 exercises/practice/protein-translation/.meta/proof.ci.cob create mode 100755 exercises/practice/protein-translation/bin/fetch-cobolcheck create mode 100644 exercises/practice/protein-translation/bin/fetch-cobolcheck.ps1 create mode 100644 exercises/practice/protein-translation/config.properties create mode 100644 exercises/practice/protein-translation/src/protein-translation.cob create mode 100644 exercises/practice/protein-translation/test.ps1 create mode 100755 exercises/practice/protein-translation/test.sh create mode 100644 exercises/practice/protein-translation/tst/protein-translation/protein-translation.cut diff --git a/config.json b/config.json index 9ce42ac5..60b0187e 100644 --- a/config.json +++ b/config.json @@ -305,6 +305,14 @@ "prerequisites": [], "difficulty": 3 }, + { + "slug": "protein-translation", + "name": "Protein Translation", + "uuid": "95e2d8d7-31a6-4734-a353-c4688ef8494f", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "pascals-triangle", "name": "Pascal's Triangle", diff --git a/exercises/practice/protein-translation/.docs/instructions.md b/exercises/practice/protein-translation/.docs/instructions.md new file mode 100644 index 00000000..826a61cf --- /dev/null +++ b/exercises/practice/protein-translation/.docs/instructions.md @@ -0,0 +1,42 @@ +# Instructions + +Translate RNA sequences into proteins. + +RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so: + +RNA: `"AUGUUUUCU"` => translates to + +Codons: `"AUG", "UUU", "UCU"` +=> which become a polypeptide with the following sequence => + +Protein: `"Methionine", "Phenylalanine", "Serine"` + +There are 64 codons which in turn correspond to 20 amino acids; however, all of the codon sequences and resulting amino acids are not important in this exercise. If it works for one codon, the program should work for all of them. +However, feel free to expand the list in the test suite to include them all. + +There are also three terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated. + +All subsequent codons after are ignored, like this: + +RNA: `"AUGUUUUCUUAAAUG"` => + +Codons: `"AUG", "UUU", "UCU", "UAA", "AUG"` => + +Protein: `"Methionine", "Phenylalanine", "Serine"` + +Note the stop codon `"UAA"` terminates the translation and the final methionine is not translated into the protein sequence. + +Below are the codons and resulting Amino Acids needed for the exercise. + +Codon | Protein +:--- | :--- +AUG | Methionine +UUU, UUC | Phenylalanine +UUA, UUG | Leucine +UCU, UCC, UCA, UCG | Serine +UAU, UAC | Tyrosine +UGU, UGC | Cysteine +UGG | Tryptophan +UAA, UAG, UGA | STOP + +Learn more about [protein translation on Wikipedia](http://en.wikipedia.org/wiki/Translation_(biology)) diff --git a/exercises/practice/protein-translation/.docs/introduction.md b/exercises/practice/protein-translation/.docs/introduction.md new file mode 100644 index 00000000..90609058 --- /dev/null +++ b/exercises/practice/protein-translation/.docs/introduction.md @@ -0,0 +1,42 @@ +# Introduction + +Translate RNA sequences into proteins. + +RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so: + +RNA: `"AUGUUUUCU"` => translates to + +Codons: `"AUG", "UUU", "UCU"` +=> which become a polypeptide with the following sequence => + +Protein: `"Methionine", "Phenylalanine", "Serine"` + +There are 64 codons which in turn correspond to 20 amino acids; however, all of the codon sequences and resulting amino acids are not important in this exercise. If it works for one codon, the program should work for all of them. +However, feel free to expand the list in the test suite to include them all. + +There are also three terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated. + +All subsequent codons after are ignored, like this: + +RNA: `"AUGUUUUCUUAAAUG"` => + +Codons: `"AUG", "UUU", "UCU", "UAA", "AUG"` => + +Protein: `"Methionine", "Phenylalanine", "Serine"` + +Note the stop codon `"UAA"` terminates the translation and the final methionine is not translated into the protein sequence. + +Below are the codons and resulting Amino Acids needed for the exercise. + +Codon | Protein +:--- | :--- +AUG | Methionine +UUU, UUC | Phenylalanine +UUA, UUG | Leucine +UCU, UCC, UCA, UCG | Serine +UAU, UAC | Tyrosine +UGU, UGC | Cysteine +UGG | Tryptophan +UAA, UAG, UGA | STOP + +Learn more about [protein translation on Wikipedia](http://en.wikipedia.org/wiki/Translation_(biology)) diff --git a/exercises/practice/protein-translation/.meta/config.json b/exercises/practice/protein-translation/.meta/config.json new file mode 100644 index 00000000..d8507972 --- /dev/null +++ b/exercises/practice/protein-translation/.meta/config.json @@ -0,0 +1,22 @@ +{ + "authors": [ + "kapitaali" + ], + "files": { + "solution": [ + "src/protein-translation.cob" + ], + "test": [ + "tst/protein-translation/protein-translation.cut" + ], + "example": [ + ".meta/proof.ci.cob" + ], + "invalidator": [ + "test.sh", + "test.ps1" + ] + }, + "blurb": "Translate RNA sequences into proteins.", + "source": "Tyler Long" +} diff --git a/exercises/practice/protein-translation/.meta/proof.ci.cob b/exercises/practice/protein-translation/.meta/proof.ci.cob new file mode 100644 index 00000000..76733599 --- /dev/null +++ b/exercises/practice/protein-translation/.meta/proof.ci.cob @@ -0,0 +1,96 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. PROTEIN-TRANSLATION. + AUTHOR. kapitaali. + ENVIRONMENT DIVISION. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WS-INPUT PIC X(60). + 01 WS-PROTEIN PIC X(120) VALUE SPACES. + 01 TEMP PIC X(120) VALUE SPACES. + 01 WS-ERROR PIC X(60). + 01 PROT PIC X(3) VALUE SPACES. + 01 CHECKED PIC X(14) VALUE SPACES. + 01 INDX PIC 99 VALUE 1. + 01 LEN PIC 99. + 01 A PIC 99. + + PROCEDURE DIVISION. + + TRANSLATE-CODON. + MOVE SPACES TO WS-PROTEIN. + MOVE WS-INPUT TO PROT. + PERFORM CHECK-CODON. + EVALUATE CHECKED + WHEN "ERROR" MOVE "Invalid codon" TO WS-ERROR + WHEN "STOP" MOVE " " TO WS-PROTEIN + WHEN OTHER MOVE CHECKED TO WS-PROTEIN + END-EVALUATE. + + + CHECK-CODON. + MOVE SPACES TO WS-PROTEIN. + MOVE SPACES TO CHECKED. + EVALUATE PROT + WHEN " " MOVE " " TO CHECKED + WHEN "AUG" MOVE "Methionine" TO CHECKED + WHEN "UUU" MOVE "Phenylalanine" TO CHECKED + WHEN "UUC" MOVE "Phenylalanine" TO CHECKED + WHEN "UUA" MOVE "Leucine" TO CHECKED + WHEN "UUG" MOVE "Leucine" TO CHECKED + WHEN "UCU" MOVE "Serine" TO CHECKED + WHEN "UCC" MOVE "Serine" TO CHECKED + WHEN "UCA" MOVE "Serine" TO CHECKED + WHEN "UCG" MOVE "Serine" TO CHECKED + WHEN "UAU" MOVE "Tyrosine" TO CHECKED + WHEN "UAC" MOVE "Tyrosine" TO CHECKED + WHEN "UGU" MOVE "Cysteine" TO CHECKED + WHEN "UGC" MOVE "Cysteine" TO CHECKED + WHEN "UGG" MOVE "Tryptophan" TO CHECKED + WHEN "UAA" MOVE "STOP" TO CHECKED + WHEN "UAG" MOVE "STOP" TO CHECKED + WHEN "UGA" MOVE "STOP" TO CHECKED + WHEN OTHER MOVE "ERROR" TO CHECKED + END-EVALUATE. + + + STR-LENGTH. + MOVE 0 TO LEN. + PERFORM VARYING A FROM FUNCTION LENGTH(CHECKED) + BY -1 UNTIL CHECKED(A:1) <> " " + ADD 1 TO LEN + END-PERFORM. + COMPUTE LEN = FUNCTION LENGTH(CHECKED) - LEN. + + + TRANSLATE-RNA. + PERFORM UNTIL WS-INPUT = " " + MOVE WS-INPUT(1:3) TO PROT + PERFORM CHECK-CODON + PERFORM STR-LENGTH + EVALUATE CHECKED + WHEN "ERROR" + MOVE "Invalid codon" TO WS-ERROR + MOVE SPACES TO TEMP + MOVE SPACES TO WS-PROTEIN + GOBACK + WHEN " " + MOVE TEMP TO WS-PROTEIN + MOVE SPACES TO TEMP + GOBACK + WHEN "STOP" + MOVE TEMP TO WS-PROTEIN + MOVE SPACES TO TEMP + GOBACK + WHEN OTHER + IF INDX > 1 + MOVE "," TO TEMP(INDX:1) + ADD 1 TO INDX + END-IF + MOVE CHECKED TO TEMP(INDX:LEN) + ADD LEN TO INDX + END-EVALUATE + MOVE WS-INPUT(4:56) TO WS-INPUT(1:56) + END-PERFORM. + MOVE TEMP TO WS-PROTEIN. + MOVE SPACES TO TEMP. + MOVE 1 TO INDX. diff --git a/exercises/practice/protein-translation/bin/fetch-cobolcheck b/exercises/practice/protein-translation/bin/fetch-cobolcheck new file mode 100755 index 00000000..64230fe2 --- /dev/null +++ b/exercises/practice/protein-translation/bin/fetch-cobolcheck @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# This file is a copy of the +# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet file. +# Please submit bugfixes/improvements to the above file to ensure that all tracks benefit from the changes. + +# set -eo pipefail + +readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest' + +case "$(uname)" in + Darwin*) os='mac' ;; + Linux*) os='linux' ;; + Windows*) os='windows' ;; + MINGW*) os='windows' ;; + MSYS_NT-*) os='windows' ;; + *) os='linux' ;; +esac + +case "${os}" in + windows*) ext='.exe' ;; + *) ext='' ;; +esac + +arch="$(uname -m)" + +curlopts=( + --silent + --show-error + --fail + --location + --retry 3 +) + +if [[ -n "${GITHUB_TOKEN}" ]]; then + curlopts+=(--header "authorization: Bearer ${GITHUB_TOKEN}") +fi + +suffix="${os}-${arch}${ext}" + +get_download_url() { + curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${LATEST}" | + grep "\"browser_download_url\": \".*/download/.*/cobol-check.*${suffix}\"$" | + cut -d'"' -f4 +} + +main() { + if [[ -d ./bin ]]; then + output_dir="./bin" + elif [[ $PWD == */bin ]]; then + output_dir="$PWD" + else + echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2 + return 1 + fi + + output_path="${output_dir}/cobolcheck${ext}" + download_url="$(get_download_url)" + curl "${curlopts[@]}" --output "${output_path}" "${download_url}" + chmod +x "${output_path}" +} + +main diff --git a/exercises/practice/protein-translation/bin/fetch-cobolcheck.ps1 b/exercises/practice/protein-translation/bin/fetch-cobolcheck.ps1 new file mode 100644 index 00000000..1535c6e8 --- /dev/null +++ b/exercises/practice/protein-translation/bin/fetch-cobolcheck.ps1 @@ -0,0 +1,28 @@ +# This file is a copy of the +# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.ps1 file. +# Please submit bugfixes/improvements to the above file to ensure that all tracks +# benefit from the changes. + +$ErrorActionPreference = "Stop" +$ProgressPreference = "SilentlyContinue" + +$requestOpts = @{ + Headers = If ($env:GITHUB_TOKEN) { @{ Authorization = "Bearer ${env:GITHUB_TOKEN}" } } Else { @{ } } + MaximumRetryCount = 3 + RetryIntervalSec = 1 +} + +$arch = If ([Environment]::Is64BitOperatingSystem) { "amd64" } Else { "x86" } +$fileName = "cobol-check-windows-$arch.exe" + +Function Get-DownloadUrl { + $latestUrl = "https://api.github.com/repos/0xE282B0/cobol-check/releases/latest" + Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts + | Select-Object -ExpandProperty assets + | Where-Object { $_.browser_download_url -match $FileName } + | Select-Object -ExpandProperty browser_download_url +} + +$downloadUrl = Get-DownloadUrl +$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe" +Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts diff --git a/exercises/practice/protein-translation/config.properties b/exercises/practice/protein-translation/config.properties new file mode 100644 index 00000000..2c5a6c8e --- /dev/null +++ b/exercises/practice/protein-translation/config.properties @@ -0,0 +1,183 @@ +# Configuration settings for Cobol Check + +#--------------------------------------------------------------------------------------------------------------------- +# This configuration - echoed to console when Cobol Check is executed, for information only. +#--------------------------------------------------------------------------------------------------------------------- +config.loaded = production + +#--------------------------------------------------------------------------------------------------------------------- +# Prefix for field names and paragraph names in the test management code that cobol-check +# inserts into programs to be tested. The default is "UT-". If this conflicts with names +# in the programs to be tested, you can override it with a value you specify here. +# The value must be 3 characters or less. Cannot be empty. +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.prefix = UT- + +#--------------------------------------------------------------------------------------------------------------------- +# Tags written in the generated test code in the form of a comment, when a code injection starts and ends. +# Default is null, which will prevent the tags from appearing. Any other value will appear as comments +# surrounding the injected code. +# Examples: +# cobolcheck.injectedCodeTag.start = ###INJECT START### +# cobolcheck.injectedCodeTag.end = ###INJECT END### +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.injectedCodeTag.start = null +cobolcheck.injectedCodeTag.end = null + +#--------------------------------------------------------------------------------------------------------------------- +# A tag written at the start of entities stubbed by default. Recommended value-length <= 4. +# Note: The tag will appear only when cobolcheck stubs lines by default. +# This is the case for CALLs and batch file IO verbs. +# Default is null, which will prevent the tag from appearing. +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.stub.comment.tag = null + +#--------------------------------------------------------------------------------------------------------------------- +# Determines if cobolcheck should generate code, such that decimal point is comma. +# The default is "false". The value should be set to "true" if the compiler is set to +# read decimal points as commas. If the cobol source program sets DECIMAL-POINT IS COMMA, +# this configuration will be overwritten. +# Example: 1,385,481.00 (decimalPointIsComma = false) +# Example: 1.385.481,00 (decimalPointIsComma = true) +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.decimalPointIsComma = false + +#--------------------------------------------------------------------------------------------------------------------- +# If the source program contains rules as the first line follwed by CBL, the given value will be appended +# to this. +# If no CBL is found in source, it will be added along with the given value +# default is null, which will make no changes. +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.append.rules = null + +#--------------------------------------------------------------------------------------------------------------------- +# Path for the generated Cobol test code +# Default: ./ +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.test.program.path = ./ + +#--------------------------------------------------------------------------------------------------------------------- +# Suffix to append to the name of each program under test to produce the name of the corresponding +# test program that contains the merged test code. +# Example: For program ABCXYZ4, if suffix is T.CBL then the test program name will be ABCXYZ4T.CBL. +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.test.program.name = test.cob + +#--------------------------------------------------------------------------------------------------------------------- +# Path for the generated testsuite parse error log +# Default: ./ +#--------------------------------------------------------------------------------------------------------------------- +testsuite.parser.error.log.path = ./ + +#--------------------------------------------------------------------------------------------------------------------- +# Name of the generated testsuite parse error log file - with extension +# Default: ParserErrorLog.txt +#--------------------------------------------------------------------------------------------------------------------- +testsuite.parser.error.log.name = ParserErrorLog.txt + +#--------------------------------------------------------------------------------------------------------------------- +# The charset that cobolcheck will use when reading- and writing to files. +# See https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html, for a list of +# valid values. +# Default value for each OS is , which will use the default encoding for the OS. +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.file.encoding.linux = default +cobolcheck.file.encoding.macosx = default +cobolcheck.file.encoding.windows = default +cobolcheck.file.encoding.zos = default +cobolcheck.file.encoding.unix = default + +#--------------------------------------------------------------------------------------------------------------------- +# Sets permissions for all files generated by Cobol Check, for all users. +# If read, write and execute permissions are set, all users can perform said actions on all files +# that Cobol Check generates. +# Value can be any permutation of the letters: 'rwx' (read, write, execute) or none - meaning no permissions. +# Default value: rx +#--------------------------------------------------------------------------------------------------------------------- +generated.files.permission.all = rx + +#--------------------------------------------------------------------------------------------------------------------- +# Determines if Cobol Check should run the generated test program. +# Default is true. +# If set to false, Cobol Check will generate the code, but not run it. If more than one program +# is given as a command line option, the generated test file will be overwritten. Thus if set to false, +# only one program should be given at a time. +#--------------------------------------------------------------------------------------------------------------------- +cobolcheck.test.run = false + +#--------------------------------------------------------------------------------------------------------------------- +# These settings are to locate the application code under test in *your* Cobol project directory tree. +# Can be absolute path or relative to project root. +#--------------------------------------------------------------------------------------------------------------------- +application.source.directory = src +application.copybook.directory = cpy + +#--------------------------------------------------------------------------------------------------------------------- +# Location of test suite input file(s). This can also be passed on command-line option --test-suite-path. +#--------------------------------------------------------------------------------------------------------------------- +test.suite.directory = tst + +#--------------------------------------------------------------------------------------------------------------------- +# Location of test output. File extension is determined by a given format. +#--------------------------------------------------------------------------------------------------------------------- +test.results.file = output/testResults + +#--------------------------------------------------------------------------------------------------------------------- +# Determines the format of the test results written to the output file. +# Supported formats: txt, xml, html. +#--------------------------------------------------------------------------------------------------------------------- +test.results.format = txt + +#--------------------------------------------------------------------------------------------------------------------- +# Determines the format style of the test results written to the output file. +# The style controls the hierarchy and structure of data and naming of the 'object' that is written +# in a given format. Format: txt and style: directOutput are exclusive. txt cannot use any other style +# than directOutput, and directOutput cannot be used with any other format than txt. +# Other formats and styles can be used interchangeably. +# Supported styles: directOutput, JUnit, tableDocument, tableEmbed +#--------------------------------------------------------------------------------------------------------------------- +test.results.format.style = directOutput + +#--------------------------------------------------------------------------------------------------------------------- +# If application source filenames have a suffix, specify it here without the period or dot. +#--------------------------------------------------------------------------------------------------------------------- +application.source.filename.suffix = CBL,cbl,COB,cob + +#--------------------------------------------------------------------------------------------------------------------- +# If application copybook filenames have a suffix, specify it here without the period or dot +# e.g. application.copybook.filename.suffix = CBL +#--------------------------------------------------------------------------------------------------------------------- +application.copybook.filename.suffix = CBL,cbl,COB,cob + +#--------------------------------------------------------------------------------------------------------------------- +# Optional override of system default Locale for log messages and exception messages. +#--------------------------------------------------------------------------------------------------------------------- +#locale.language = ja +#locale.country = +#locale.variant = + +#--------------------------------------------------------------------------------------------------------------------- +# Cobol Check concatenates multiple test suite input files into a single file for the Generator. +# This is the relative or absolute path of the concatenated file. If not specified, the default +# is "./ALLTESTS" relative to the directory in which Cobol Check was started. +#--------------------------------------------------------------------------------------------------------------------- +concatenated.test.suites = ./ALLTESTS + +#--------------------------------------------------------------------------------------------------------------------- +# Shell scripts and JCL files for executing your test suites. +# Cobol Check will invoke one of these after creating the copy of the program under test that contains +# test code generated from your test suites. +# Unix and Mac OS X are both treated as unix. Most unices can run the linux script. +# Unix is the default. +# You can write custom scripts/JCL for your environment, for instance if you are using a different Cobol compiler. +# The first element in these names reflects the first few characters returned by Java's System.getProperty("os.name"). +# Cobol Check will select one of these entries based on which platform it thinks it's running on. +#--------------------------------------------------------------------------------------------------------------------- + +cobolcheck.script.directory = scripts +linux.process = linux_gnucobol_run_tests +osx.process = linux_gnucobol_run_tests +freebsd.process = linux_gnucobol_run_tests +windows.process = windows_gnucobol_run_tests.cmd +zos.process = +unix.process = linux_gnucobol_run_tests diff --git a/exercises/practice/protein-translation/src/protein-translation.cob b/exercises/practice/protein-translation/src/protein-translation.cob new file mode 100644 index 00000000..240879e5 --- /dev/null +++ b/exercises/practice/protein-translation/src/protein-translation.cob @@ -0,0 +1,15 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. PROTEIN-TRANSLATION. + ENVIRONMENT DIVISION. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WS-INPUT PIC X(60). + 01 WS-PROTEIN PIC X(120). + 01 WS-ERROR PIC X(60). + + PROCEDURE DIVISION. + + TRANSLATE-CODON. + + TRANSLATE-RNA. + \ No newline at end of file diff --git a/exercises/practice/protein-translation/test.ps1 b/exercises/practice/protein-translation/test.ps1 new file mode 100644 index 00000000..ccfa530a --- /dev/null +++ b/exercises/practice/protein-translation/test.ps1 @@ -0,0 +1,16 @@ +$slug=Split-Path $PSScriptRoot -Leaf + +if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){ + Write-Output "Cobolcheck not found. Trying to fetch it." + & "$PSScriptRoot\bin\fetch-cobolcheck.ps1" +} + +Write-Output "Run cobolcheck." +Set-Location $PSScriptRoot + +Invoke-Expression "bin\cobolcheck.exe -p $slug" +Invoke-Expression "cobc -xj test.cob" + +if ($Lastexitcode -ne 0) { + exit $Lastexitcode +} diff --git a/exercises/practice/protein-translation/test.sh b/exercises/practice/protein-translation/test.sh new file mode 100755 index 00000000..ed4a27a1 --- /dev/null +++ b/exercises/practice/protein-translation/test.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/ +SLUG=${1:-$(basename "${SCRIPT_DIR}")} +COBOLCHECK=./bin/cobolcheck + +WHICH_COBOLCHECK=$(which cobolcheck) +if [[ $? -eq 0 ]] ; then + echo "Found cobolcheck, using $COBOLCHECK" + COBOLCHECK=$WHICH_COBOLCHECK +elif [ ! -f $SCRIPT_DIR/bin/cobolcheck ]; then + echo "Cobolcheck not found, try to fetch it." + cd $SCRIPT_DIR/bin/ + bash fetch-cobolcheck +fi +cd $SCRIPT_DIR +$COBOLCHECK -p $SLUG + +# compile and run +echo "COMPILE AND RUN TEST" +cobc -xj test.cob diff --git a/exercises/practice/protein-translation/tst/protein-translation/protein-translation.cut b/exercises/practice/protein-translation/tst/protein-translation/protein-translation.cut new file mode 100644 index 00000000..2ecb299e --- /dev/null +++ b/exercises/practice/protein-translation/tst/protein-translation/protein-translation.cut @@ -0,0 +1,149 @@ +TestCase "Empty RNA sequence results in no proteins" + MOVE " " TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = SPACES + +TestCase "Methionine RNA sequence" + MOVE "AUG" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Methionine" + +TestCase "Phenylalanine RNA sequence 1" + MOVE "UUU" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Phenylalanine" + +TestCase "Phenylalanine RNA sequence 2" + MOVE "UUC" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Phenylalanine" + +TestCase "Leucine RNA sequence 1" + MOVE "UUA" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Leucine" + +TestCase "Leucine RNA sequence 2" + MOVE "UUG" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Leucine" + +TestCase "Serine RNA sequence 1" + MOVE "UCU" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Serine" + +TestCase "Serine RNA sequence 2" + MOVE "UCC" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Serine" + +TestCase "Serine RNA sequence 3" + MOVE "UCA" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Serine" + +TestCase "Serine RNA sequence 4" + MOVE "UCG" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Serine" + +TestCase "Tyrosine RNA sequence 1" + MOVE "UAU" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Tyrosine" + +TestCase "Tyrosine RNA sequence 2" + MOVE "UAC" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Tyrosine" + +TestCase "Cysteine RNA sequence 1" + MOVE "UGU" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Cysteine" + +TestCase "Cysteine RNA sequence 2" + MOVE "UGC" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Cysteine" + +TestCase "Tryptophan RNA sequence" + MOVE "UGG" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = "Tryptophan" + +TestCase "STOP codon RNA sequence 1" + MOVE "UAA" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = SPACES + +TestCase "STOP codon RNA sequence 2" + MOVE "UAG" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = SPACES + +TestCase "STOP codon RNA sequence 3" + MOVE "UGA" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-PROTEIN = SPACES + +TestCase "Sequence of two protein codons translates into proteins" + MOVE "UUUUUU" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = "Phenylalanine,Phenylalanine" + +TestCase "Sequence of two different protein codons translates into proteins" + MOVE "UUAUUG" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = "Leucine,Leucine" + +TestCase "Translate RNA strand into correct protein list" + MOVE "AUGUUUUGG" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = "Methionine,Phenylalanine,Tryptophan" + +TestCase "Translation stops if STOP codon at beginning of sequence" + MOVE "UAGUGG" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = SPACES + +TestCase "Translation stops if STOP codon at end of two-codon sequence" + MOVE "UGGUAG" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = "Tryptophan" + +TestCase "Translation stops if STOP codon at end of three-codon sequence" + MOVE "AUGUUUUAA" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = "Methionine,Phenylalanine" + +TestCase "Translation stops if STOP codon in middle of three-codon sequence" + MOVE "UGGUAGUGG" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = "Tryptophan" + +TestCase "Translation stops if STOP codon in middle of six-codon sequence" + MOVE "UGGUGUUAUUAAUGGUUU" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = "Tryptophan,Cysteine,Tyrosine" + +TestCase "Non-existing codon can't translate" + MOVE "AAA" TO WS-INPUT + PERFORM TRANSLATE-CODON + EXPECT WS-ERROR = "Invalid codon" + +TestCase "Unknown amino acids, not part of a codon, can't translate" + MOVE "XYZ" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-ERROR = "Invalid codon" + +TestCase "Incomplete RNA sequence can't translate" + MOVE "AUGU" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-ERROR = "Invalid codon" + +TestCase "Incomplete RNA sequence can translate if valid until a STOP codon" + MOVE "UUCUUCUAAUGGU" TO WS-INPUT + PERFORM TRANSLATE-RNA + EXPECT WS-PROTEIN = "Phenylalanine,Phenylalanine"