From 855b95a718fb02c6ef1d13bbc79149b09567a6e5 Mon Sep 17 00:00:00 2001 From: SimaDovakin Date: Thu, 6 Jun 2024 13:49:15 +0300 Subject: [PATCH] anagram-exercise: Added anagram exercise. --- config.json | 8 + .../anagram/.docs/instructions.append.md | 3 + .../practice/anagram/.docs/instructions.md | 13 ++ .../practice/anagram/.docs/introduction.md | 12 ++ exercises/practice/anagram/.meta/config.json | 19 ++ exercises/practice/anagram/.meta/proof.ci.cob | 178 +++++++++++++++++ exercises/practice/anagram/.meta/tests.toml | 86 ++++++++ .../practice/anagram/bin/fetch-cobolcheck | 0 .../practice/anagram/bin/fetch-cobolcheck.ps1 | 0 exercises/practice/anagram/config.properties | 183 ++++++++++++++++++ exercises/practice/anagram/src/anagram.cob | 16 ++ exercises/practice/anagram/test.ps1 | 21 ++ exercises/practice/anagram/test.sh | 20 ++ .../practice/anagram/tst/anagram/anagram.cut | 137 +++++++++++++ 14 files changed, 696 insertions(+) create mode 100644 exercises/practice/anagram/.docs/instructions.append.md create mode 100644 exercises/practice/anagram/.docs/instructions.md create mode 100644 exercises/practice/anagram/.docs/introduction.md create mode 100644 exercises/practice/anagram/.meta/config.json create mode 100644 exercises/practice/anagram/.meta/proof.ci.cob create mode 100644 exercises/practice/anagram/.meta/tests.toml create mode 100755 exercises/practice/anagram/bin/fetch-cobolcheck create mode 100644 exercises/practice/anagram/bin/fetch-cobolcheck.ps1 create mode 100644 exercises/practice/anagram/config.properties create mode 100644 exercises/practice/anagram/src/anagram.cob create mode 100644 exercises/practice/anagram/test.ps1 create mode 100644 exercises/practice/anagram/test.sh create mode 100644 exercises/practice/anagram/tst/anagram/anagram.cut diff --git a/config.json b/config.json index 54fb9ff4..e1cf122d 100644 --- a/config.json +++ b/config.json @@ -384,6 +384,14 @@ "practices": [], "prerequisites": [], "difficulty": 5 + }, + { + "slug": "anagram", + "name": "Anagram", + "uuid": "031c8337-ee79-4487-bd23-5ee425515cbe", + "practices": [], + "prerequisites": [], + "difficulty": 5 } ] }, diff --git a/exercises/practice/anagram/.docs/instructions.append.md b/exercises/practice/anagram/.docs/instructions.append.md new file mode 100644 index 00000000..6ef822ab --- /dev/null +++ b/exercises/practice/anagram/.docs/instructions.append.md @@ -0,0 +1,3 @@ +# Hints + +The result should be a string with anagrams separated by a comma (e.g., `"hello,world"`). diff --git a/exercises/practice/anagram/.docs/instructions.md b/exercises/practice/anagram/.docs/instructions.md new file mode 100644 index 00000000..a7298485 --- /dev/null +++ b/exercises/practice/anagram/.docs/instructions.md @@ -0,0 +1,13 @@ +# Instructions + +Your task is to, given a target word and a set of candidate words, to find the subset of the candidates that are anagrams of the target. + +An anagram is a rearrangement of letters to form a new word: for example `"owns"` is an anagram of `"snow"`. +A word is _not_ its own anagram: for example, `"stop"` is not an anagram of `"stop"`. + +The target and candidates are words of one or more ASCII alphabetic characters (`A`-`Z` and `a`-`z`). +Lowercase and uppercase characters are equivalent: for example, `"PoTS"` is an anagram of `"sTOp"`, but `StoP` is not an anagram of `sTOp`. +The anagram set is the subset of the candidate set that are anagrams of the target (in any order). +Words in the anagram set should have the same letter case as in the candidate set. + +Given the target `"stone"` and candidates `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, `"Seton"`, the anagram set is `"tones"`, `"notes"`, `"Seton"`. diff --git a/exercises/practice/anagram/.docs/introduction.md b/exercises/practice/anagram/.docs/introduction.md new file mode 100644 index 00000000..1acbdf00 --- /dev/null +++ b/exercises/practice/anagram/.docs/introduction.md @@ -0,0 +1,12 @@ +# Introduction + +At a garage sale, you find a lovely vintage typewriter at a bargain price! +Excitedly, you rush home, insert a sheet of paper, and start typing away. +However, your excitement wanes when you examine the output: all words are garbled! +For example, it prints "stop" instead of "post" and "least" instead of "stale." +Carefully, you try again, but now it prints "spot" and "slate." +After some experimentation, you find there is a random delay before each letter is printed, which messes up the order. +You now understand why they sold it for so little money! + +You realize this quirk allows you to generate anagrams, which are words formed by rearranging the letters of another word. +Pleased with your finding, you spend the rest of the day generating hundreds of anagrams. diff --git a/exercises/practice/anagram/.meta/config.json b/exercises/practice/anagram/.meta/config.json new file mode 100644 index 00000000..04df2dc6 --- /dev/null +++ b/exercises/practice/anagram/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "SimaDovakin" + ], + "files": { + "solution": [ + "src/anagram.cob" + ], + "test": [ + "tst/anagram/anagram.cut" + ], + "example": [ + ".meta/proof.ci.cob" + ] + }, + "blurb": "Given a word and a list of possible anagrams, select the correct sublist.", + "source": "Inspired by the Extreme Startup game", + "source_url": "https://github.com/rchatley/extreme_startup" +} diff --git a/exercises/practice/anagram/.meta/proof.ci.cob b/exercises/practice/anagram/.meta/proof.ci.cob new file mode 100644 index 00000000..914401e1 --- /dev/null +++ b/exercises/practice/anagram/.meta/proof.ci.cob @@ -0,0 +1,178 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. ANAGRAM. + ENVIRONMENT DIVISION. + CONFIGURATION SECTION. + REPOSITORY. + FUNCTION ALL INTRINSIC. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WS-SUBJECT PIC X(20). + 01 WS-CANDIDATES-COUNT PIC 9. + 01 WS-CANDIDATES-TABLE. + 02 WS-CANDIDATES OCCURS 1 TO 20 + DEPENDING ON WS-CANDIDATES-COUNT. + 05 WS-CANDIDATE PIC X(20). + 01 WS-RESULT-LIST PIC X(48). + + 01 WS-INDEX PIC 9(3). + 01 WS-CANDIDATE-INDEX PIC 9. + 01 WS-MULT BINARY-LONG. + 01 WS-WORD-CODE BINARY-LONG. + 01 WS-STRING PIC X(20). + 01 WS-STRING-LENGTH PIC 9(2). + 01 WS-SEPARATOR PIC X. + 01 WS-IS-ANAGRAM PIC X. + 01 WS-SUBJECT-CODE BINARY-LONG. + 01 WS-LOWERED-SUBJECT PIC X(20). + 01 WS-LOWERED-CANDIDATE PIC X(20). + + PROCEDURE DIVISION. + + FIND-ANAGRAMS. + MOVE SPACE TO WS-RESULT-LIST + MOVE SPACE TO WS-SEPARATOR + MOVE LOWER-CASE(TRIM(WS-SUBJECT)) TO WS-LOWERED-SUBJECT + MOVE WS-LOWERED-SUBJECT TO WS-STRING + PERFORM WORD-PRIMERIZATION + MOVE WS-WORD-CODE TO WS-SUBJECT-CODE + + PERFORM VARYING WS-CANDIDATE-INDEX FROM 1 BY 1 + UNTIL WS-CANDIDATE-INDEX > WS-CANDIDATES-COUNT + MOVE LOWER-CASE(TRIM(WS-CANDIDATES(WS-CANDIDATE-INDEX))) + TO WS-STRING + + PERFORM IS-ANAGRAMS + + IF WS-IS-ANAGRAM = "T" + STRING + WS-RESULT-LIST DELIMITED BY SPACE + WS-SEPARATOR DELIMITED BY SPACE + WS-CANDIDATES(WS-CANDIDATE-INDEX) DELIMITED BY SPACE + INTO WS-RESULT-LIST + END-STRING + MOVE "," TO WS-SEPARATOR + END-IF + + END-PERFORM. + + IS-ANAGRAMS. + MOVE "F" TO WS-IS-ANAGRAM + PERFORM WORD-PRIMERIZATION + IF WS-LOWERED-SUBJECT <> WS-STRING + AND WS-SUBJECT-CODE = WS-WORD-CODE + MOVE "T" TO WS-IS-ANAGRAM + END-IF. + + WORD-PRIMERIZATION. + MOVE 1 TO WS-WORD-CODE + MOVE 1 TO WS-INDEX + MOVE LENGTH(WS-STRING) TO WS-STRING-LENGTH + + PERFORM VARYING WS-INDEX FROM 1 BY 1 + UNTIL WS-INDEX > WS-STRING-LENGTH + EVALUATE WS-STRING(WS-INDEX:1) + WHEN 'a' + MOVE 2 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'b' + MOVE 3 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'c' + MOVE 5 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'd' + MOVE 7 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'e' + MOVE 11 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'f' + MOVE 13 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'g' + MOVE 17 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'h' + MOVE 19 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'i' + MOVE 23 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'j' + MOVE 29 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'k' + MOVE 31 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'l' + MOVE 37 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'm' + MOVE 41 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'n' + MOVE 43 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'o' + MOVE 47 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'p' + MOVE 53 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'q' + MOVE 59 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'r' + MOVE 61 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 's' + MOVE 67 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 't' + MOVE 71 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'u' + MOVE 73 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'v' + MOVE 79 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'w' + MOVE 83 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'x' + MOVE 89 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'y' + MOVE 97 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + WHEN 'z' + MOVE 101 TO WS-MULT + MULTIPLY WS-WORD-CODE BY WS-MULT + GIVING WS-WORD-CODE + END-PERFORM. diff --git a/exercises/practice/anagram/.meta/tests.toml b/exercises/practice/anagram/.meta/tests.toml new file mode 100644 index 00000000..4d905627 --- /dev/null +++ b/exercises/practice/anagram/.meta/tests.toml @@ -0,0 +1,86 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[dd40c4d2-3c8b-44e5-992a-f42b393ec373] +description = "no matches" + +[b3cca662-f50a-489e-ae10-ab8290a09bdc] +description = "detects two anagrams" +include = false + +[03eb9bbe-8906-4ea0-84fa-ffe711b52c8b] +description = "detects two anagrams" +reimplements = "b3cca662-f50a-489e-ae10-ab8290a09bdc" + +[a27558ee-9ba0-4552-96b1-ecf665b06556] +description = "does not detect anagram subsets" + +[64cd4584-fc15-4781-b633-3d814c4941a4] +description = "detects anagram" + +[99c91beb-838f-4ccd-b123-935139917283] +description = "detects three anagrams" + +[78487770-e258-4e1f-a646-8ece10950d90] +description = "detects multiple anagrams with different case" + +[1d0ab8aa-362f-49b7-9902-3d0c668d557b] +description = "does not detect non-anagrams with identical checksum" + +[9e632c0b-c0b1-4804-8cc1-e295dea6d8a8] +description = "detects anagrams case-insensitively" + +[b248e49f-0905-48d2-9c8d-bd02d8c3e392] +description = "detects anagrams using case-insensitive subject" + +[f367325c-78ec-411c-be76-e79047f4bd54] +description = "detects anagrams using case-insensitive possible matches" + +[7cc195ad-e3c7-44ee-9fd2-d3c344806a2c] +description = "does not detect an anagram if the original word is repeated" +include = false + +[630abb71-a94e-4715-8395-179ec1df9f91] +description = "does not detect an anagram if the original word is repeated" +reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c" + +[9878a1c9-d6ea-4235-ae51-3ea2befd6842] +description = "anagrams must use all letters exactly once" + +[85757361-4535-45fd-ac0e-3810d40debc1] +description = "words are not anagrams of themselves (case-insensitive)" +include = false + +[68934ed0-010b-4ef9-857a-20c9012d1ebf] +description = "words are not anagrams of themselves" +reimplements = "85757361-4535-45fd-ac0e-3810d40debc1" + +[589384f3-4c8a-4e7d-9edc-51c3e5f0c90e] +description = "words are not anagrams of themselves even if letter case is partially different" +reimplements = "85757361-4535-45fd-ac0e-3810d40debc1" + +[ba53e423-7e02-41ee-9ae2-71f91e6d18e6] +description = "words are not anagrams of themselves even if letter case is completely different" +reimplements = "85757361-4535-45fd-ac0e-3810d40debc1" + +[a0705568-628c-4b55-9798-82e4acde51ca] +description = "words other than themselves can be anagrams" +include = false + +[33d3f67e-fbb9-49d3-a90e-0beb00861da7] +description = "words other than themselves can be anagrams" +reimplements = "a0705568-628c-4b55-9798-82e4acde51ca" + +[a6854f66-eec1-4afd-a137-62ef2870c051] +description = "handles case of greek letters" + +[fd3509e5-e3ba-409d-ac3d-a9ac84d13296] +description = "different characters may have the same bytes" diff --git a/exercises/practice/anagram/bin/fetch-cobolcheck b/exercises/practice/anagram/bin/fetch-cobolcheck new file mode 100755 index 00000000..e69de29b diff --git a/exercises/practice/anagram/bin/fetch-cobolcheck.ps1 b/exercises/practice/anagram/bin/fetch-cobolcheck.ps1 new file mode 100644 index 00000000..e69de29b diff --git a/exercises/practice/anagram/config.properties b/exercises/practice/anagram/config.properties new file mode 100644 index 00000000..2c5a6c8e --- /dev/null +++ b/exercises/practice/anagram/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/anagram/src/anagram.cob b/exercises/practice/anagram/src/anagram.cob new file mode 100644 index 00000000..45c5b8e5 --- /dev/null +++ b/exercises/practice/anagram/src/anagram.cob @@ -0,0 +1,16 @@ + IDENTIFICATION DIVISION. + PROGRAM-ID. ANAGRAM. + + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WS-SUBJECT PIC X(20). + 01 WS-CANDIDATES-COUNT PIC 9. + 01 WS-CANDIDATES-TABLE. + 02 WS-CANDIDATES OCCURS 1 TO 20 + DEPENDING ON WS-CANDIDATES-COUNT. + 05 WS-CANDIDATE PIC X(20). + 01 WS-RESULT-LIST PIC X(48). + + PROCEDURE DIVISION. + + FIND-ANAGRAMS. diff --git a/exercises/practice/anagram/test.ps1 b/exercises/practice/anagram/test.ps1 new file mode 100644 index 00000000..b54fdc61 --- /dev/null +++ b/exercises/practice/anagram/test.ps1 @@ -0,0 +1,21 @@ +$slug=Split-Path $PSScriptRoot -Leaf +$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe" +$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue + +if ($cobolcheckCmd) { + $cobolcheck = $cobolcheckCmd.Path + Write-Output "Found cobolcheck, using $cobolcheck" +} elseif (![System.IO.File]::Exists("$cobolcheck")){ + Write-Output "Cobolcheck not found. Trying to fetch it." + & "$PSScriptRoot\bin\fetch-cobolcheck.ps1" +} + +Write-Output "Run cobolcheck." +Set-Location $PSScriptRoot + +Invoke-Expression "$cobolcheck -p $slug" +Invoke-Expression "cobc -xj test.cob" + +if ($Lastexitcode -ne 0) { + exit $Lastexitcode +} diff --git a/exercises/practice/anagram/test.sh b/exercises/practice/anagram/test.sh new file mode 100644 index 00000000..ed4a27a1 --- /dev/null +++ b/exercises/practice/anagram/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/anagram/tst/anagram/anagram.cut b/exercises/practice/anagram/tst/anagram/anagram.cut new file mode 100644 index 00000000..c423ffbc --- /dev/null +++ b/exercises/practice/anagram/tst/anagram/anagram.cut @@ -0,0 +1,137 @@ +TESTSUITE 'Tests for Anagram' + +TestCase "test_no_matches", + MOVE "diaper" TO WS-SUBJECT + MOVE 4 TO WS-CANDIDATES-COUNT + MOVE "hello" TO WS-CANDIDATES(1) + MOVE "world" TO WS-CANDIDATES(2) + MOVE "zombies" TO WS-CANDIDATES(3) + MOVE "pants" TO WS-CANDIDATES(4) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "" + +TestCase "test_detect_two_anagrams", + MOVE "solemn" TO WS-SUBJECT + MOVE 3 TO WS-CANDIDATES-COUNT + MOVE "lemons" TO WS-CANDIDATES(1) + MOVE "cherry" TO WS-CANDIDATES(2) + MOVE "melons" TO WS-CANDIDATES(3) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "lemons,melons" + +TestCase "test_does_not_detect_anagram_subsets", + MOVE "good" TO WS-SUBJECT + MOVE 2 TO WS-CANDIDATES-COUNT + MOVE "dog" TO WS-CANDIDATES(1) + MOVE "goody" TO WS-CANDIDATES(2) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "" + +TestCase "test_detects_anagram", + MOVE "listen" TO WS-SUBJECT + MOVE 4 TO WS-CANDIDATES-COUNT + MOVE "enlists" TO WS-CANDIDATES(1) + MOVE "google" TO WS-CANDIDATES(2) + MOVE "inlets" TO WS-CANDIDATES(3) + MOVE "banana" TO WS-CANDIDATES(4) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "inlets" + +TestCase "test_three_anagrams", + MOVE "allergy" TO WS-SUBJECT + MOVE 6 TO WS-CANDIDATES-COUNT + MOVE "gallery" TO WS-CANDIDATES(1) + MOVE "ballerina" TO WS-CANDIDATES(2) + MOVE "regally" TO WS-CANDIDATES(3) + MOVE "clergy" TO WS-CANDIDATES(4) + MOVE "largely" TO WS-CANDIDATES(5) + MOVE "leading" TO WS-CANDIDATES(6) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "gallery,regally,largely" + +TestCase "test_detects_multiple_anagrams_with_different_case", + MOVE "nose" TO WS-SUBJECT + MOVE 2 TO WS-CANDIDATES-COUNT + MOVE "Eons" TO WS-CANDIDATES(1) + MOVE "ONES" TO WS-CANDIDATES(2) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "Eons,ONES" + +TestCase "test_does_not_detect_non_anagrams_with_identical_checksum", + MOVE "mass" TO WS-SUBJECT + MOVE 1 TO WS-CANDIDATES-COUNT + MOVE "last" TO WS-CANDIDATES(1) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "" + +TestCase "test_detects_anagrams_case_insensitively", + MOVE "Orchestra" TO WS-SUBJECT + MOVE 3 TO WS-CANDIDATES-COUNT + MOVE "cashregister" TO WS-CANDIDATES(1) + MOVE "Carthorse" TO WS-CANDIDATES(2) + MOVE "radishes" TO WS-CANDIDATES(3) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "Carthorse" + +TestCase "test_detects_anagram_using_case_insensitive_subject", + MOVE "Orchestra" TO WS-SUBJECT + MOVE 3 TO WS-CANDIDATES-COUNT + MOVE "cashregister" TO WS-CANDIDATES(1) + MOVE "carthorse" TO WS-CANDIDATES(2) + MOVE "radishes" TO WS-CANDIDATES(3) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "carthorse" + +TestCase "test_detects_anagrams_using_case_insensitive_possible_matches", + MOVE "orchestra" TO WS-SUBJECT + MOVE 3 TO WS-CANDIDATES-COUNT + MOVE "cashregister" TO WS-CANDIDATES(1) + MOVE "Carthorse" TO WS-CANDIDATES(2) + MOVE "radishes" TO WS-CANDIDATES(3) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "Carthorse" + +TestCase "test_does_not_detect_an_anagram_if_the_original_word_is_repeated", + MOVE "orchestra" TO WS-SUBJECT + MOVE 3 TO WS-CANDIDATES-COUNT + MOVE "go" TO WS-CANDIDATES(1) + MOVE "Go" TO WS-CANDIDATES(2) + MOVE "GO" TO WS-CANDIDATES(3) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "" + +TestCase "test_anagrams_must_use_all_letters_exactly_once", + MOVE "tapper" TO WS-SUBJECT + MOVE 1 TO WS-CANDIDATES-COUNT + MOVE "patter" TO WS-CANDIDATES(1) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "" + +TestCase "test_words_are_not_anagrams_of_themselves", + MOVE "BANANA" TO WS-SUBJECT + MOVE 1 TO WS-CANDIDATES-COUNT + MOVE "BANANA" TO WS-CANDIDATES(1) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "" + +TestCase "test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different", + MOVE "BANANA" TO WS-SUBJECT + MOVE 1 TO WS-CANDIDATES-COUNT + MOVE "Banana" TO WS-CANDIDATES(1) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "" + +TestCase "test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different", + MOVE "BANANA" TO WS-SUBJECT + MOVE 1 TO WS-CANDIDATES-COUNT + MOVE "banana" TO WS-CANDIDATES(1) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "" + +TestCase "test_words_other_than_themselves_can_be_anagrams", + MOVE "LISTEN" TO WS-SUBJECT + MOVE 2 TO WS-CANDIDATES-COUNT + MOVE "Listen" TO WS-CANDIDATES(1) + MOVE "Silent" TO WS-CANDIDATES(2) + PERFORM FIND-ANAGRAMS + EXPECT WS-RESULT-LIST = "Silent"