Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

1 new exercise: protein-translation #125

Merged
merged 15 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 11 additions & 14 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ jobs:
- name: Checkout repository
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5


- name: Cache GnuCOBOL
id: cache-gnu-cobol
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
with:
path: ~\gnucobol-3.2-dev.zip
key: ${{ runner.os }}-gnu-cobol-3.2
path: |
~/gnucobol
~/cobolcheck
key: gnucobol-3.2.7-cobolcheck-v1

- name: Download GnuCOBOL
if: steps.cache-gnu-cobol.outputs.cache-hit != 'true'
Expand All @@ -46,20 +47,16 @@ jobs:
MaximumRetryCount = 3
RetryIntervalSec = 1
}
Invoke-WebRequest -Uri 'https://ci.appveyor.com/api/projects/GitMensch/gnucobol-3-x-win32-posix/artifacts/gnucobol-3.2-dev-MinGW-binaries%20(debug).zip?job=Environment:%20BUILD_TYPE=MSYS,%20BUILD_BIN=C:\MinGW\msys\1.0\bin' -OutFile ~\gnucobol-3.2-dev.zip @requestOpts
Invoke-WebRequest -Uri 'https://www.arnoldtrembley.com/GC32-BDB-SP1-rename-7z-to-exe.7z' -OutFile $HOME\gnucobol-3.2.7z @requestOpts
7z x $HOME\gnucobol-3.2.7z -o"${HOME}\gnucobol" -y

- name: Extract GnuCOBOL
- name: Download CobolCheck
if: steps.cache-gnu-cobol.outputs.cache-hit != 'true'
shell: pwsh
run: Expand-Archive ~\gnucobol-3.2-dev.zip -DestinationPath gnucobol -Force
run: bin/fetch-cobolcheck.ps1

- name: Run tests for all exercises
shell: pwsh
run: |
$env:Path = "D:\a\cobol\cobol\gnucobol\bin;" + $env:Path
[System.Environment]::SetEnvironmentVariable('COB_CONFIG_DIR', 'D:\a\cobol\cobol\gnucobol\config')
[System.Environment]::SetEnvironmentVariable('COB_COPY_DIR', 'D:\a\cobol\cobol\gnucobol\copy')
[System.Environment]::SetEnvironmentVariable('COB_CFLAGS', '-I D:\a\cobol\cobol\gnucobol\include')
[System.Environment]::SetEnvironmentVariable('COB_LDFLAGS', '-L D:\a\cobol\cobol\gnucobol\lib')
[System.Environment]::SetEnvironmentVariable('COB_LIBRARY_PATH', 'D:\a\cobol\cobol\gnucobol\lib')
[System.Environment]::SetEnvironmentVariable('COB_LIBS', 'D:\a\cobol\cobol\gnucobol\bin\libcob-4.dll')
bin/setup-environment.ps1
bin/test.ps1
12 changes: 3 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ jobs:
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5

- name: Setup COBOL
run: |
sudo apt-get update
sudo apt-get -y install curl tar libncurses5-dev libgmp-dev libdb-dev
sudo apt-get -y autoremove
sudo apt-get -y install iproute2
run: sudo apt update && sudo apt install -y gnucobol

sudo apt-get -y install ranger autoconf build-essential
curl -sLk https://sourceforge.net/projects/open-cobol/files/gnu-cobol/3.1/gnucobol-3.1.2.tar.gz | tar xz
cd gnucobol-3.1.2 && ./configure --prefix=/usr && sudo make && sudo make install && sudo ldconfig
sudo apt-get -y --purge autoremove
- name: Fetch CobolCheck
run: bin/fetch-cobolcheck

- name: Run tests for all exercises
run: bin/test
54 changes: 54 additions & 0 deletions bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

# This file is inspired by https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

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() {
output_path="/usr/local/bin/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
}

main
29 changes: 29 additions & 0 deletions bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is inspired by https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.ps1.
# It is only used in the cobol track, and a copy of it is placed in every exercise folder.
# If you change something, make sure to upgrade all scripts in all exercises!

$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
$outputDir = Join-Path -Path $HOME -ChildPath "cobolcheck"
$outputFile = Join-Path -Path $outputDir -ChildPath "cobolcheck.exe"
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
9 changes: 9 additions & 0 deletions bin/setup-environment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$gnucobolDir = "${HOME}\gnucobol"
$cobolcheckDir = "${HOME}\cobolcheck"
$env:Path = "${gnucobolDir}\bin;${cobolcheckDir};${env:Path}"
[System.Environment]::SetEnvironmentVariable('COB_CONFIG_DIR', "${gnucobolDir}\config")
[System.Environment]::SetEnvironmentVariable('COB_COPY_DIR', "${gnucobolDir}\copy")
[System.Environment]::SetEnvironmentVariable('COB_CFLAGS', "-I ${gnucobolDir}\include")
[System.Environment]::SetEnvironmentVariable('COB_LDFLAGS', "-L ${gnucobolDir}\lib")
[System.Environment]::SetEnvironmentVariable('COB_LIBRARY_PATH', "${gnucobolDir}\lib")
[System.Environment]::SetEnvironmentVariable('COB_LIBS', "${gnucobolDir}\bin\libcob-4.dll")
44 changes: 32 additions & 12 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,31 @@
"indent_size": 3,
"highlightjs_language": "cobol"
},
"test_runner": {
"test_runner": {
"average_run_time": 2
},
"files": {
"solution": [],
"test": [],
"example": [],
"exemplar": []
"solution": [
"src/%{kebab_slug}.cob"
],
"test": [
"tst/%{kebab_slug}/%{kebab_slug}.cut"
],
"example": [
".meta/proof.ci.cob"
],
"exemplar": [
".meta/exemplar.ci.cob"
],
"invalidator": [
"test.ps1",
"test.sh",
"bin/fetch-cobolcheck",
"bin/fetch-cobolcheck.ps1",
"config.properties"
]
},
"exercises": {
"concept": [],
"practice": [
{
"slug": "hello-world",
Expand All @@ -39,8 +53,7 @@
"slug": "leap",
"name": "Leap",
"uuid": "eab41ebb-64a9-4015-92b8-3899d58b8e5f",
"practices": [
],
"practices": [],
"prerequisites": [],
"difficulty": 2
},
Expand Down Expand Up @@ -243,7 +256,7 @@
"practices": [],
"prerequisites": [],
"difficulty": 3
},
},
{
"slug": "all-your-base",
"name": "All Your Base",
Expand Down Expand Up @@ -292,6 +305,14 @@
"prerequisites": [],
"difficulty": 3
},
{
"slug": "protein-translation",
"name": "Protein Translation",
"uuid": "95e2d8d7-31a6-4734-a353-c4688ef8494f",
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "pascals-triangle",
"name": "Pascal's Triangle",
Expand All @@ -302,7 +323,6 @@
}
]
},
"concepts": [],
"key_features": [
{
"title": "Statically Typed",
Expand Down Expand Up @@ -336,12 +356,12 @@
}
],
"tags": [
"paradigm/procedural",
"execution_mode/compiled",
"paradigm/imperative",
"paradigm/object_oriented",
"paradigm/procedural",
"typing/static",
"typing/strong",
"execution_mode/compiled",
"used_for/backends",
"used_for/financial_systems"
]
Expand Down
45 changes: 24 additions & 21 deletions exercises/practice/acronym/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"authors": [
"kapitaali"
"authors": [
"kapitaali"
],
"files": {
"solution": [
"src/acronym.cob"
],
"files": {
"solution": [
"src/acronym.cob"
],
"test": [
"tst/acronym/acronym.cut"
],
"example": [
".meta/proof.ci.cob"
],
"invalidator": [
"test.sh",
"test.ps1"
]
},
"blurb": "Convert a phrase to its acronym.",
"source": "Julien Vanier",
"source_url": "https://github.com/monkbroc"
}
"test": [
"tst/acronym/acronym.cut"
],
"example": [
".meta/proof.ci.cob"
],
"invalidator": [
"test.ps1",
"test.sh",
"bin/fetch-cobolcheck",
"bin/fetch-cobolcheck.ps1",
"config.properties"
]
},
"blurb": "Convert a phrase to its acronym.",
"source": "Julien Vanier",
"source_url": "https://github.com/monkbroc"
}
4 changes: 1 addition & 3 deletions exercises/practice/acronym/.meta/proof.ci.cob
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
EVALUATE CHAR
WHEN "_"
CONTINUE
WHEN " "
WHEN SPACE
MOVE 1 TO PICKNEXT
CONTINUE
WHEN "-"
Expand All @@ -48,5 +48,3 @@
ADD 1 TO LEN
END-PERFORM.
COMPUTE LEN = 80 - LEN.


44 changes: 42 additions & 2 deletions exercises/practice/acronym/src/acronym.cob
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. ACRONYM.
PROGRAM-ID. acronym.
AUTHOR. kapitaali.
ENVIRONMENT DIVISION.
DATA DIVISION.
FILE SECTION.

WORKING-STORAGE SECTION.
01 WS-ACRONYM PIC X(80).
01 WS-RESULT PIC X(20).

01 LEN PIC 99.
01 PICKNEXT PIC 9.
01 COUNTER PIC 99.
01 IDX PIC 99.
01 CHAR PIC X.

PROCEDURE DIVISION.
ABBREVIATE.
PERFORM STR-LENGTH.
MOVE 1 TO IDX.
MOVE SPACES TO WS-RESULT.
MOVE 1 TO PICKNEXT.
PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER = LEN
MOVE WS-ACRONYM(COUNTER:1) TO CHAR
EVALUATE CHAR
WHEN "_"
CONTINUE
WHEN SPACE
MOVE 1 TO PICKNEXT
CONTINUE
WHEN "-"
MOVE 1 TO PICKNEXT
CONTINUE
WHEN OTHER
IF PICKNEXT = 1
MOVE FUNCTION UPPER-CASE(CHAR)
TO WS-RESULT(IDX:1)
ADD 1 TO IDX
END-IF
MOVE 0 TO PICKNEXT
END-PERFORM.

STR-LENGTH.
MOVE 0 TO LEN.
MOVE FUNCTION LENGTH(WS-ACRONYM) TO IDX.
PERFORM VARYING IDX FROM FUNCTION LENGTH(WS-ACRONYM)
BY -1 UNTIL WS-ACRONYM(IDX:1) <> " "
ADD 1 TO LEN
END-PERFORM.
COMPUTE LEN = 80 - LEN.
9 changes: 7 additions & 2 deletions exercises/practice/acronym/test.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
$slug=Split-Path $PSScriptRoot -Leaf
$cobolcheck = "$PSScriptRoot\bin\cobolcheck.exe"
$cobolcheckCmd = Get-Command "cobolcheck.exe" -ErrorAction SilentlyContinue

if (![System.IO.File]::Exists("$PSScriptRoot\bin\cobolcheck.exe")){
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 "bin\cobolcheck.exe -p $slug"
Invoke-Expression "$cobolcheck -p $slug"
Invoke-Expression "cobc -xj test.cob"

if ($Lastexitcode -ne 0) {
Expand Down