diff --git a/config.json b/config.json index ea9d421a..bdc5e587 100644 --- a/config.json +++ b/config.json @@ -353,6 +353,14 @@ "prerequisites": [], "difficulty": 4 }, + { + "slug": "pig-latin", + "name": "Pig Latin", + "uuid": "3ed36cd0-8087-41b1-bf31-1625238344ce", + "practices": [], + "prerequisites": [], + "difficulty": 5 + }, { "slug": "pascals-triangle", "name": "Pascal's Triangle", diff --git a/exercises/practice/pig-latin/.docs/instructions.md b/exercises/practice/pig-latin/.docs/instructions.md new file mode 100644 index 00000000..bcb12511 --- /dev/null +++ b/exercises/practice/pig-latin/.docs/instructions.md @@ -0,0 +1,18 @@ +# Instructions + +Implement a program that translates from English to Pig Latin. + +Pig Latin is a made-up children's language that's intended to be +confusing. It obeys a few simple rules (below), but when it's spoken +quickly it's really difficult for non-children (and non-native speakers) +to understand. + +- **Rule 1**: If a word begins with a vowel sound, add an "ay" sound to the end of the word. Please note that "xr" and "yt" at the beginning of a word make vowel sounds (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay"). +- **Rule 2**: If a word begins with a consonant sound, move it to the end of the word and then add an "ay" sound to the end of the word. Consonant sounds can be made up of multiple consonants, a.k.a. a consonant cluster (e.g. "chair" -> "airchay"). +- **Rule 3**: If a word starts with a consonant sound followed by "qu", move it to the end of the word, and then add an "ay" sound to the end of the word (e.g. "square" -> "aresquay"). +- **Rule 4**: If a word contains a "y" after a consonant cluster or as the second letter in a two letter word it makes a vowel sound (e.g. "rhythm" -> "ythmrhay", "my" -> "ymay"). + +There are a few more rules for edge cases, and there are regional +variants too. + +See for more details. diff --git a/exercises/practice/pig-latin/.meta/config.json b/exercises/practice/pig-latin/.meta/config.json new file mode 100644 index 00000000..bd15b9ce --- /dev/null +++ b/exercises/practice/pig-latin/.meta/config.json @@ -0,0 +1,23 @@ +{ + "authors": [ + "kapitaali" + ], + "files": { + "solution": [ + "src/pig-latin.cob" + ], + "test": [ + "tst/pig-latin/pig-latin.cut" + ], + "example": [ + ".meta/proof.ci.cob" + ], + "invalidator": [ + "test.sh", + "test.ps1" + ] + }, + "blurb": "Implement a program that translates from English to Pig Latin.", + "source": "The Pig Latin exercise at Test First Teaching by Ultrasaurus", + "source_url": "https://github.com/ultrasaurus/test-first-teaching/blob/master/learn_ruby/pig_latin/" +} diff --git a/exercises/practice/pig-latin/.meta/proof.ci.cob b/exercises/practice/pig-latin/.meta/proof.ci.cob new file mode 100644 index 00000000..81a031da --- /dev/null +++ b/exercises/practice/pig-latin/.meta/proof.ci.cob @@ -0,0 +1,257 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. PIG-LATIN. + AUTHOR. kapitaali. + ENVIRONMENT DIVISION. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VOWELS PIC X(6) VALUE 'aeiouy'. + 01 WS-INPUT PIC X(60). + 01 WS-RESULT PIC X(60). + 01 STR PIC X(60). + 01 TEMP PIC X(60). + 01 TEMP2 PIC X(60). + 01 BOOL PIC 9. + 01 A PIC 99. + 01 B PIC 99 VALUE 1. + 01 C PIC 99. + 01 X PIC X. + 01 I PIC 99. + 01 LEN PIC 99. + 01 LEN2 PIC 99. + 01 INPUTLEN PIC 99. + + 01 STARTING-POINT USAGE BINARY-LONG. + 01 ITEM-COUNT USAGE BINARY-LONG. + + 01 Wordstable. + 02 WORDSLIST PIC X(60) OCCURS 10 TIMES. + + + PROCEDURE DIVISION. + + STR-LENGTH. + MOVE 0 TO LEN. + PERFORM VARYING A FROM FUNCTION LENGTH(STR) + BY -1 UNTIL STR(A:1) IS NOT EQUAL TO " " + ADD 1 TO LEN + END-PERFORM. + COMPUTE LEN = FUNCTION LENGTH(STR) - LEN. + + + BEGINS-WITH-VOWEL. + MOVE FUNCTION LOWER-CASE(STR(1:1)) TO X. + PERFORM IS-X-VOWEL. + IF BOOL = 1 + PERFORM RULE-1 + ELSE IF STR(1:1) = 'x' + MOVE STR(2:1) TO X + PERFORM IS-X-VOWEL + IF BOOL = 0 + PERFORM RULE-1 + ELSE + PERFORM RULE-2 + END-IF + ELSE IF STR(2:2) = 'qu' + PERFORM RULE-3 + ELSE + PERFORM FIND-FIRST-VOWEL + IF X = 'y' + PERFORM RULE-4 + ELSE + PERFORM RULE-2 + END-IF + END-IF. + + + IS-X-VOWEL. + MOVE 0 TO BOOL. + MOVE FUNCTION LOWER-CASE(X) TO X. + PERFORM VARYING I FROM 1 BY 1 UNTIL I > 6 + IF VOWELS(I:1) = X + MOVE 1 TO BOOL + END-IF + END-PERFORM. + + + FIND-FIRST-VOWEL. + MOVE 1 TO I. + MOVE 1 TO A. + MOVE 0 TO BOOL + PERFORM STR-LENGTH. + PERFORM VARYING A FROM 1 BY 1 UNTIL A = LEN + MOVE STR(A:1) TO X + PERFORM IS-X-VOWEL + IF BOOL = 1 + EXIT PARAGRAPH + END-IF + END-PERFORM. + + + CHECK-IF-MULTIPLE-WORDS. + MOVE WS-INPUT TO STR. + PERFORM STR-LENGTH. + MOVE 1 TO A. + PERFORM VARYING I FROM 1 BY 1 UNTIL I = LEN + IF STR(I:1) IS NOT EQUAL TO " " + ADD 1 TO A + ELSE + ADD 1 TO A + EXIT PERFORM + END-IF + END-PERFORM. + * spaces before end of string -> multiple words + IF A < LEN + MOVE 1 TO BOOL + ELSE + MOVE 0 TO BOOL + END-IF. + + + PROCESS-MULTIPLE-WORDS. + INITIALIZE Wordstable. + MOVE SPACES TO TEMP2. + MOVE 1 TO INPUTLEN. + INITIALIZE ITEM-COUNT. + MOVE 1 TO STARTING-POINT. + MOVE 1 TO ITEM-COUNT. + * unstring perform by bruce axtens, begin + PERFORM UNTIL EXIT + UNSTRING WS-INPUT DELIMITED BY SPACE + INTO WORDSLIST(ITEM-COUNT) + WITH POINTER STARTING-POINT + END-UNSTRING + IF WORDSLIST(ITEM-COUNT) = SPACE + EXIT PERFORM + END-IF + ADD 1 TO ITEM-COUNT + END-PERFORM. + * end + PERFORM VARYING C FROM 1 BY 1 UNTIL C > 10 + MOVE WORDSLIST(C) TO STR + PERFORM BEGINS-WITH-VOWEL + MOVE WS-RESULT TO STR + PERFORM STR-LENGTH + IF C > 1 + ADD 1 TO INPUTLEN + MOVE STR TO TEMP2(INPUTLEN:LEN) + ADD LEN TO INPUTLEN + ELSE + MOVE STR TO TEMP2 + ADD LEN TO INPUTLEN + END-IF + MOVE WS-RESULT TO WORDSLIST(C) + END-PERFORM. + MOVE TEMP2 TO WS-RESULT. + + + TRANSLATE. + MOVE 1 TO LEN2. + MOVE WS-INPUT TO STR. + PERFORM STR-LENGTH. + IF WS-INPUT = " " + MOVE TEMP TO WS-RESULT + EXIT PARAGRAPH + END-IF. + PERFORM CHECK-IF-MULTIPLE-WORDS. + IF BOOL = 1 + PERFORM PROCESS-MULTIPLE-WORDS + ELSE + MOVE WS-INPUT TO STR + PERFORM BEGINS-WITH-VOWEL + END-IF. + + + * Rule 1: If a word begins with a vowel sound, add an "ay" + * sound to the end of the word. Please note that "xr" + * and "yt" at the beginning of a word make vowel sounds + * (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay"). + RULE-1. + PERFORM STR-LENGTH. + IF STR(1:1) = "y" + IF STR(2:1) = "t" + ADD 1 TO LEN + MOVE STR TO WS-RESULT + MOVE "ay" TO WS-RESULT(LEN:2) + ELSE + MOVE STR(2:55) TO STR(1:55) + MOVE "yay" TO STR(LEN:3) + MOVE STR TO WS-RESULT + END-IF + ELSE + ADD 1 TO LEN + MOVE STR TO WS-RESULT + MOVE "ay" TO WS-RESULT(LEN:2) + END-IF. + + * Rule 2: If a word begins with a consonant sound, move it + * to the end of the word and then add an "ay" sound to + * the end of the word. Consonant sounds can be made up + * of multiple consonants, such as the "ch" in "chair" or + * "st" in "stand" (e.g. "chair" -> "airchay"). + RULE-2. + MOVE 0 TO BOOL. + PERFORM STR-LENGTH. + IF LEN = 0 + MOVE " " TO WS-RESULT + ELSE IF STR(1:2) = "qu" + MOVE STR(3:55) TO STR(1:55) + PERFORM STR-LENGTH + ADD 1 TO LEN GIVING A + MOVE "quay" TO STR(A:4) + MOVE STR TO WS-RESULT + ELSE + MOVE 1 TO A + PERFORM VARYING I FROM 1 BY 1 UNTIL BOOL = 1 + MOVE STR(A:1) TO X + PERFORM IS-X-VOWEL + ADD 1 TO A + END-PERFORM + SUBTRACT 2 FROM A GIVING I + MOVE STR(1:I) TO TEMP + SUBTRACT 1 FROM A + MOVE STR(A:55) TO STR(1:55) + PERFORM STR-LENGTH + ADD 1 TO LEN GIVING A + MOVE TEMP TO STR(A:I) + MOVE STR TO WS-RESULT + PERFORM STR-LENGTH + ADD 1 TO LEN + MOVE "ay" TO WS-RESULT(LEN:2) + END-IF. + + * Rule 3: If a word starts with a consonant sound followed by + * "qu", move it to the end of the word, and then add an "ay" + * sound to the end of the word (e.g. "square" -> "aresquay"). + RULE-3. + MOVE STR(1:3) TO TEMP. + MOVE STR(4:55) TO STR(1:55). + PERFORM STR-LENGTH. + ADD 1 TO LEN GIVING A. + MOVE TEMP TO STR(A:3). + ADD 3 TO A. + MOVE "ay" TO STR(A:2). + MOVE STR TO WS-RESULT. + + * Rule 4: If a word contains a "y" after a consonant cluster or + * as the second letter in a two letter word it makes a vowel + * sound (e.g. "rhythm" -> "ythmrhay", "my" -> "ymay"). + RULE-4. + PERFORM VARYING I FROM 1 BY 1 UNTIL I = 60 + IF STR(I:1) = 'y' + EXIT PERFORM + END-IF + END-PERFORM. + * y is at index I, so everything before y is B characters + SUBTRACT 1 FROM I GIVING B. + MOVE STR(1:B) TO TEMP. + * move everything starting from y to the beginning + MOVE STR(I:55) TO STR(1:55). + PERFORM STR-LENGTH. + * move stuff before y to the end + COMPUTE A = LEN + 1. + MOVE TEMP TO STR(A:B). + * add ay to the end + ADD B TO A. + MOVE "ay" TO STR(A:2). + MOVE STR TO WS-RESULT. + diff --git a/exercises/practice/pig-latin/bin/fetch-cobolcheck b/exercises/practice/pig-latin/bin/fetch-cobolcheck new file mode 100755 index 00000000..64230fe2 --- /dev/null +++ b/exercises/practice/pig-latin/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/pig-latin/bin/fetch-cobolcheck.ps1 b/exercises/practice/pig-latin/bin/fetch-cobolcheck.ps1 new file mode 100644 index 00000000..261f5f45 --- /dev/null +++ b/exercises/practice/pig-latin/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/pig-latin/config.properties b/exercises/practice/pig-latin/config.properties new file mode 100644 index 00000000..2c5a6c8e --- /dev/null +++ b/exercises/practice/pig-latin/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/pig-latin/src/pig-latin.cob b/exercises/practice/pig-latin/src/pig-latin.cob new file mode 100644 index 00000000..663efcdb --- /dev/null +++ b/exercises/practice/pig-latin/src/pig-latin.cob @@ -0,0 +1,11 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. PIG-LATIN. + ENVIRONMENT DIVISION. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WS-INPUT PIC X(60). + 01 WS-RESULT PIC X(60). + + PROCEDURE DIVISION. + + TRANSLATE. \ No newline at end of file diff --git a/exercises/practice/pig-latin/test.ps1 b/exercises/practice/pig-latin/test.ps1 new file mode 100644 index 00000000..ccfa530a --- /dev/null +++ b/exercises/practice/pig-latin/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/pig-latin/test.sh b/exercises/practice/pig-latin/test.sh new file mode 100755 index 00000000..ed4a27a1 --- /dev/null +++ b/exercises/practice/pig-latin/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/pig-latin/tst/pig-latin/pig-latin.cut b/exercises/practice/pig-latin/tst/pig-latin/pig-latin.cut new file mode 100644 index 00000000..69ed33be --- /dev/null +++ b/exercises/practice/pig-latin/tst/pig-latin/pig-latin.cut @@ -0,0 +1,127 @@ +TESTSUITE "ay is added to words that start with vowels" + +TestCase "word beginning with a" + MOVE "apple" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "appleay" + +TestCase "word beginning with e" + MOVE "ear" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "earay" + +TestCase "word beginning with i" + MOVE "igloo" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "iglooay" + +TestCase "word beginning with o" + MOVE "object" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "objectay" + +TestCase "word beginning with u" + MOVE "under" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "underay" + +TestCase "word beginning with a vowel and followed by a qu" + MOVE "equal" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "equalay" + + +TESTSUITE "first letter and ay are moved to the end of words that start with consonants" + +TestCase "word beginning with p" + MOVE "pig" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "igpay" + +TestCase "word beginning with k" + MOVE "koala" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "oalakay" + +TestCase "word beginning with x" + MOVE "xenon" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "enonxay" + +TestCase "word beginning with q without a following u" + MOVE "qat" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "atqay" + + +TESTSUITE "some letter clusters are treated like a single consonant" + +TestCase "word beginning with ch" + MOVE "chair" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "airchay" + +TestCase "word beginning with qu" + MOVE "queen" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "eenquay" + +TestCase "word beginning with qu and a preceding consonant" + MOVE "square" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "aresquay" + +TestCase "word beginning with th" + MOVE "therapy" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "erapythay" + +TestCase "word beginning with sch" + MOVE "school" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "oolschay" + +TestCase "word beginning with thr" + MOVE "thrush" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "ushthray" + + +TESTSUITE "some letter clusters are treated like a single vowel" + +TestCase "word beginning with yt" + MOVE "yttria" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "yttriaay" + +TestCase "word beginning with xr" + MOVE "xray" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "xrayay" + + +TESTSUITE "position of y in a word determines if it is a consonant or a vowel" + +TestCase "y is treated like a consonant at the beginning of a word" + MOVE "yellow" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "ellowyay" + +TestCase "y is treated like a vowel at the end of a consonant cluster" + MOVE "rhythm" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "ythmrhay" + +TestCase "y as second letter in two letter word" + MOVE "my" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "ymay" + + +TESTSUITE "phrases are translated" + +TestCase "a whole phrase" + MOVE "quick fast run" TO WS-INPUT + PERFORM TRANSLATE + EXPECT WS-RESULT = "ickquay astfay unray" + \ No newline at end of file