From 8a480c0520a141571f5eef4c0c348d6c586f6832 Mon Sep 17 00:00:00 2001 From: Teppo Saari Date: Wed, 24 Apr 2024 15:08:39 +0300 Subject: [PATCH] 1 new exercise: robot-simulator (#139) * adding robot-simulator, removing redundant introduction.md files * update config.json --- config.json | 8 + .../binary-search/.docs/introduction.md | 35 --- .../protein-translation/.docs/introduction.md | 42 ---- .../robot-simulator/.docs/instructions.md | 25 +++ .../robot-simulator/.meta/config.json | 22 ++ .../robot-simulator/.meta/proof.ci.cob | 68 ++++++ .../robot-simulator/bin/fetch-cobolcheck | 63 ++++++ .../robot-simulator/bin/fetch-cobolcheck.ps1 | 28 +++ .../robot-simulator/config.properties | 183 ++++++++++++++++ .../robot-simulator/src/robot-simulator.cob | 16 ++ exercises/practice/robot-simulator/test.ps1 | 16 ++ exercises/practice/robot-simulator/test.sh | 20 ++ .../tst/robot-simulator/robot-simulator.cut | 204 ++++++++++++++++++ .../secret-handshake/.docs/introduction.md | 27 --- .../practice/space-age/.docs/introduction.md | 18 -- 15 files changed, 653 insertions(+), 122 deletions(-) delete mode 100644 exercises/practice/binary-search/.docs/introduction.md delete mode 100644 exercises/practice/protein-translation/.docs/introduction.md create mode 100644 exercises/practice/robot-simulator/.docs/instructions.md create mode 100644 exercises/practice/robot-simulator/.meta/config.json create mode 100644 exercises/practice/robot-simulator/.meta/proof.ci.cob create mode 100755 exercises/practice/robot-simulator/bin/fetch-cobolcheck create mode 100644 exercises/practice/robot-simulator/bin/fetch-cobolcheck.ps1 create mode 100644 exercises/practice/robot-simulator/config.properties create mode 100644 exercises/practice/robot-simulator/src/robot-simulator.cob create mode 100644 exercises/practice/robot-simulator/test.ps1 create mode 100755 exercises/practice/robot-simulator/test.sh create mode 100644 exercises/practice/robot-simulator/tst/robot-simulator/robot-simulator.cut delete mode 100644 exercises/practice/secret-handshake/.docs/introduction.md delete mode 100644 exercises/practice/space-age/.docs/introduction.md diff --git a/config.json b/config.json index 16ba6c27..955c2553 100644 --- a/config.json +++ b/config.json @@ -337,6 +337,14 @@ "prerequisites": [], "difficulty": 1 }, + { + "slug": "robot-simulator", + "name": "Robot Simulator", + "uuid": "aa8d3ec5-da37-45e2-87c2-ec94eacf6cb4", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "pascals-triangle", "name": "Pascal's Triangle", diff --git a/exercises/practice/binary-search/.docs/introduction.md b/exercises/practice/binary-search/.docs/introduction.md deleted file mode 100644 index d998c9e8..00000000 --- a/exercises/practice/binary-search/.docs/introduction.md +++ /dev/null @@ -1,35 +0,0 @@ -# Introduction - -Implement a binary search algorithm. - -Searching a sorted collection is a common task. A dictionary is a sorted -list of word definitions. Given a word, one can find its definition. A -telephone book is a sorted list of people's names, addresses, and -telephone numbers. Knowing someone's name allows one to quickly find -their telephone number and address. - -If the list to be searched contains more than a few items (a dozen, say) -a binary search will require far fewer comparisons than a linear search, -but it imposes the requirement that the list be sorted. - -In computer science, a binary search or half-interval search algorithm -finds the position of a specified input value (the search "key") within -an array sorted by key value. - -In each step, the algorithm compares the search key value with the key -value of the middle element of the array. - -If the keys match, then a matching element has been found and its index, -or position, is returned. - -Otherwise, if the search key is less than the middle element's key, then -the algorithm repeats its action on the sub-array to the left of the -middle element or, if the search key is greater, on the sub-array to the -right. - -If the remaining array to be searched is empty, then the key cannot be -found in the array and a special "not found" indication is returned. - -A binary search halves the number of items to check with each iteration, -so locating an item (or determining its absence) takes logarithmic time. -A binary search is a dichotomic divide and conquer search algorithm. diff --git a/exercises/practice/protein-translation/.docs/introduction.md b/exercises/practice/protein-translation/.docs/introduction.md deleted file mode 100644 index 90609058..00000000 --- a/exercises/practice/protein-translation/.docs/introduction.md +++ /dev/null @@ -1,42 +0,0 @@ -# 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/robot-simulator/.docs/instructions.md b/exercises/practice/robot-simulator/.docs/instructions.md new file mode 100644 index 00000000..0ac96ce0 --- /dev/null +++ b/exercises/practice/robot-simulator/.docs/instructions.md @@ -0,0 +1,25 @@ +# Instructions + +Write a robot simulator. + +A robot factory's test facility needs a program to verify robot movements. + +The robots have three possible movements: + +- turn right +- turn left +- advance + +Robots are placed on a hypothetical infinite grid, facing a particular direction (north, east, south, or west) at a set of {x,y} coordinates, +e.g., {3,8}, with coordinates increasing to the north and east. + +The robot then receives a number of instructions, at which point the testing facility verifies the robot's new position, and in which direction it is pointing. + +- The letter-string "RAALAL" means: + - Turn right + - Advance twice + - Turn left + - Advance once + - Turn left yet again +- Say a robot starts at {7, 3} facing north. + Then running this stream of instructions should leave it at {9, 4} facing west. diff --git a/exercises/practice/robot-simulator/.meta/config.json b/exercises/practice/robot-simulator/.meta/config.json new file mode 100644 index 00000000..efe9273c --- /dev/null +++ b/exercises/practice/robot-simulator/.meta/config.json @@ -0,0 +1,22 @@ +{ + "authors": [ + "kapitaali" + ], + "files": { + "solution": [ + "src/robot-simulator.cob" + ], + "test": [ + "tst/robot-simulator/robot-simulator.cut" + ], + "example": [ + ".meta/proof.ci.cob" + ], + "invalidator": [ + "test.sh", + "test.ps1" + ] + }, + "blurb": "Write a robot simulator.", + "source": "Inspired by an interview question at a famous company." +} diff --git a/exercises/practice/robot-simulator/.meta/proof.ci.cob b/exercises/practice/robot-simulator/.meta/proof.ci.cob new file mode 100644 index 00000000..a2766919 --- /dev/null +++ b/exercises/practice/robot-simulator/.meta/proof.ci.cob @@ -0,0 +1,68 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. ROBOT-SIMULATOR. + AUTHOR. kapitaali. + ENVIRONMENT DIVISION. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WS-X-COORD PIC S999. + 01 WS-Y-COORD PIC S999. + 01 WS-DIRECTION PIC X(20). + 01 WS-INSTRUCTIONS PIC X(60). + 01 INSTRU PIC X. + 01 LEN PIC 99. + 01 CC PIC 99. + + + PROCEDURE DIVISION. + + CREATE-ROBOT. + CONTINUE. + + + MOVE-ROBOT. + PERFORM VARYING LEN FROM 60 BY -1 + UNTIL WS-INSTRUCTIONS(LEN:1) IS NOT EQUAL TO " " + CONTINUE + END-PERFORM. + PERFORM VARYING CC FROM 1 BY 1 UNTIL CC > LEN + MOVE WS-INSTRUCTIONS(CC:1) TO INSTRU + PERFORM PROCESS-INSTRUCTION + END-PERFORM. + + + PROCESS-INSTRUCTION. + EVALUATE INSTRU + WHEN 'L' + EVALUATE WS-DIRECTION + WHEN 'north' + MOVE 'west' TO WS-DIRECTION + WHEN 'west' + MOVE 'south' TO WS-DIRECTION + WHEN 'south' + MOVE 'east' TO WS-DIRECTION + WHEN 'east' + MOVE 'north' TO WS-DIRECTION + END-EVALUATE + WHEN 'R' + EVALUATE WS-DIRECTION + WHEN 'north' + MOVE 'east' TO WS-DIRECTION + WHEN 'west' + MOVE 'north' TO WS-DIRECTION + WHEN 'south' + MOVE 'west' TO WS-DIRECTION + WHEN 'east' + MOVE 'south' TO WS-DIRECTION + END-EVALUATE + WHEN 'A' + EVALUATE WS-DIRECTION + WHEN 'north' + ADD 1 TO WS-Y-COORD + WHEN 'east' + ADD 1 TO WS-X-COORD + WHEN 'south' + SUBTRACT 1 FROM WS-Y-COORD + WHEN 'west' + SUBTRACT 1 FROM WS-X-COORD + END-EVALUATE + END-EVALUATE. diff --git a/exercises/practice/robot-simulator/bin/fetch-cobolcheck b/exercises/practice/robot-simulator/bin/fetch-cobolcheck new file mode 100755 index 00000000..64230fe2 --- /dev/null +++ b/exercises/practice/robot-simulator/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/robot-simulator/bin/fetch-cobolcheck.ps1 b/exercises/practice/robot-simulator/bin/fetch-cobolcheck.ps1 new file mode 100644 index 00000000..261f5f45 --- /dev/null +++ b/exercises/practice/robot-simulator/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 \ No newline at end of file diff --git a/exercises/practice/robot-simulator/config.properties b/exercises/practice/robot-simulator/config.properties new file mode 100644 index 00000000..2c5a6c8e --- /dev/null +++ b/exercises/practice/robot-simulator/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/robot-simulator/src/robot-simulator.cob b/exercises/practice/robot-simulator/src/robot-simulator.cob new file mode 100644 index 00000000..9dbcce91 --- /dev/null +++ b/exercises/practice/robot-simulator/src/robot-simulator.cob @@ -0,0 +1,16 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. ROBOT-SIMULATOR. + ENVIRONMENT DIVISION. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WS-X-COORD PIC S999. + 01 WS-Y-COORD PIC S999. + 01 WS-DIRECTION PIC X(20). + 01 WS-INSTRUCTIONS PIC X(60). + + PROCEDURE DIVISION. + + CREATE-ROBOT. + + + MOVE-ROBOT. \ No newline at end of file diff --git a/exercises/practice/robot-simulator/test.ps1 b/exercises/practice/robot-simulator/test.ps1 new file mode 100644 index 00000000..ccfa530a --- /dev/null +++ b/exercises/practice/robot-simulator/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/robot-simulator/test.sh b/exercises/practice/robot-simulator/test.sh new file mode 100755 index 00000000..ed4a27a1 --- /dev/null +++ b/exercises/practice/robot-simulator/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/robot-simulator/tst/robot-simulator/robot-simulator.cut b/exercises/practice/robot-simulator/tst/robot-simulator/robot-simulator.cut new file mode 100644 index 00000000..71007563 --- /dev/null +++ b/exercises/practice/robot-simulator/tst/robot-simulator/robot-simulator.cut @@ -0,0 +1,204 @@ +TESTSUITE "Create robot" + +TestCase "at origin facing north" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "north" TO WS-DIRECTION + PERFORM CREATE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "north" + +TestCase "at negative position facing south" + MOVE -1 TO WS-X-COORD + MOVE -1 TO WS-Y-COORD + MOVE "south" TO WS-DIRECTION + PERFORM CREATE-ROBOT + EXPECT WS-X-COORD = -1 + EXPECT WS-Y-COORD = -1 + EXPECT WS-DIRECTION = "south" + + +TESTSUITE "Rotating clockwise" + +TestCase "changes north to east" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "north" TO WS-DIRECTION + MOVE "R" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "east" + + +TestCase "changes east to south" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "east" TO WS-DIRECTION + MOVE "R" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "south" + + +TestCase "changes south to west" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "south" TO WS-DIRECTION + MOVE "R" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "west" + + +TestCase "changes west to north" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "west" TO WS-DIRECTION + MOVE "R" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "north" + + +TESTSUITE "Rotating counter-clockwise" + +TestCase "changes north to west" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "north" TO WS-DIRECTION + MOVE "L" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "west" + + +TestCase "changes west to south" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "west" TO WS-DIRECTION + MOVE "L" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "south" + + +TestCase "changes south to east" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "south" TO WS-DIRECTION + MOVE "L" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "east" + + +TestCase "changes east to north" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "east" TO WS-DIRECTION + MOVE "L" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "north" + + +TESTSUITE "Moving forward one" + +TestCase "facing north increments Y" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "north" TO WS-DIRECTION + MOVE "A" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = 1 + EXPECT WS-DIRECTION = "north" + + +TestCase "facing south decrements Y" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "south" TO WS-DIRECTION + MOVE "A" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 0 + EXPECT WS-Y-COORD = -1 + EXPECT WS-DIRECTION = "south" + + +TestCase "facing east increments X" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "east" TO WS-DIRECTION + MOVE "A" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 1 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "east" + + +TestCase "facing west decrements X" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "west" TO WS-DIRECTION + MOVE "A" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = -1 + EXPECT WS-Y-COORD = 0 + EXPECT WS-DIRECTION = "west" + + +TESTSUITE "Follow series of instructions" + +TestCase "moving east and north" + MOVE 7 TO WS-X-COORD + MOVE 3 TO WS-Y-COORD + MOVE "north" TO WS-DIRECTION + MOVE "RAALAL" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 9 + EXPECT WS-Y-COORD = 4 + EXPECT WS-DIRECTION = "west" + + +TestCase "moving west and north" + MOVE 0 TO WS-X-COORD + MOVE 0 TO WS-Y-COORD + MOVE "north" TO WS-DIRECTION + MOVE "LAAARALA" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = -4 + EXPECT WS-Y-COORD = 1 + EXPECT WS-DIRECTION = "west" + + +TestCase "moving west and south" + MOVE 2 TO WS-X-COORD + MOVE -7 TO WS-Y-COORD + MOVE "east" TO WS-DIRECTION + MOVE "RRAAAAALA" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = -3 + EXPECT WS-Y-COORD = -8 + EXPECT WS-DIRECTION = "south" + + +TestCase "moving east and north" + MOVE 8 TO WS-X-COORD + MOVE 4 TO WS-Y-COORD + MOVE "south" TO WS-DIRECTION + MOVE "LAAARRRALLLL" TO WS-INSTRUCTIONS + PERFORM MOVE-ROBOT + EXPECT WS-X-COORD = 11 + EXPECT WS-Y-COORD = 5 + EXPECT WS-DIRECTION = "north" + diff --git a/exercises/practice/secret-handshake/.docs/introduction.md b/exercises/practice/secret-handshake/.docs/introduction.md deleted file mode 100644 index 450e6092..00000000 --- a/exercises/practice/secret-handshake/.docs/introduction.md +++ /dev/null @@ -1,27 +0,0 @@ -# Introduction - -> There are 10 types of people in the world: Those who understand -> binary, and those who don't. - -You and your fellow cohort of those in the "know" when it comes to -binary decide to come up with a secret "handshake". - -```text -00001 = wink -00010 = double blink -00100 = close your eyes -01000 = jump - - -10000 = Reverse the order of the operations in the secret handshake. -``` - -Given a decimal number, convert it to the appropriate sequence of events for a secret handshake. - -Here's a couple of examples: - -Given the decimal input 3, the function would return the array -["wink", "double blink"] because the decimal number 3 is 2+1 in powers of two and thus `11` in binary. - -Let's now examine the input 19 which is 16+2+1 in powers of two and thus `10011` in binary. -Recalling that the addition of 16 (`10000` in binary) reverses an array and that we already know what array is returned given input 3, the array returned for input 19 is ["double blink", "wink"]. diff --git a/exercises/practice/space-age/.docs/introduction.md b/exercises/practice/space-age/.docs/introduction.md deleted file mode 100644 index 8689cafd..00000000 --- a/exercises/practice/space-age/.docs/introduction.md +++ /dev/null @@ -1,18 +0,0 @@ -# Introduction - -Given an age in seconds, calculate how old someone would be on: - -- Mercury: orbital period 0.2408467 Earth years -- Venus: orbital period 0.61519726 Earth years -- Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds -- Mars: orbital period 1.8808158 Earth years -- Jupiter: orbital period 11.862615 Earth years -- Saturn: orbital period 29.447498 Earth years -- Uranus: orbital period 84.016846 Earth years -- Neptune: orbital period 164.79132 Earth years - -So if you were told someone were 1,000,000,000 seconds old, you should -be able to say that they're 31.69 Earth-years old. - -If you're wondering why Pluto didn't make the cut, go watch [this -YouTube video](http://www.youtube.com/watch?v=Z_2gbGXzFbs).