Hello,
I can´t pass Tests in Exercise 1 of COBOL Track.
Tests Failed messages refer to line numbers, code and variables that are not present or used in my code.
Tests Failed messages:
test.cob:155: error: ‘WS-YEAR’ is not defined
153 | TO UT-TEST-CASE-NAME…
154 | PERFORM UT-INITIALIZE-MOCK-COUNT…
155 > MOVE 2015 TO WS-YEAR…
156 | PERFORM LEAP…
157 | ADD 1 TO UT-TEST-CASE-COUNT…
test.cob:160: error: ‘WS-RESULT’ is not defined
158 | SET UT-NORMAL-COMPARE TO TRUE…
159 | SET UT-ALPHANUMERIC-COMPARE TO TRUE…
160 > MOVE WS-RESULT TO UT-ACTUAL…
161 | MOVE 0…
162 | TO UT-EXPECTED…
test.cob:156: error: ‘LEAP’ is not defined
154 | PERFORM UT-INITIALIZE-MOCK-COUNT…
155 | MOVE 2015 TO WS-YEAR…
156 > PERFORM LEAP…
157 | ADD 1 TO UT-TEST-CASE-COUNT…
158 | SET UT-NORMAL-COMPARE TO TRUE…
My code:
*>>source format is free
*> *************************************************************
*> Author: Geiza
*> Date: Oct-2025
*> Purpose: Determine if an year is leap
*> *************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. Verify-Leap-Year.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 YEAR-IN PIC 9(004) VALUE ZERO.
01 LEAP-RESULT PIC 9(001) VALUE ZERO.
01 YEAR-IS-LEAP.
03 FILLER PIC X(20) VALUE "YEAR IS LEAP".
01 YEAR-IS-NOT-LEAP.
03 FILLER PIC X(20) VALUE "YEAR IS NOT LEAP".
PROCEDURE DIVISION.
MAIN-ROUTINE.
ACCEPT YEAR-IN.
PERFORM CHECK-LEAP.
IF LEAP-RESULT EQUALS 0
DISPLAY YEAR-IS-LEAP
ELSE
DISPLAY YEAR-IS-NOT-LEAP
END-IF.
STOP RUN.
CHECK-LEAP.
*>Solution
IF FUNCTION MOD(YEAR-IN;4) = 0
IF FUNCTION MOD(YEAR-IN;100) = 0
IF FUNCTION MOD(YEAR-IN;400) = 0
*>Year is leap (divisible by 400)
MOVE 1 TO LEAP-RESULT
ELSE
*>Year is not leap (divisible by 100,
*>but not divisible by 400)
MOVE 0 TO LEAP-RESULT
ELSE
*>Year is leap (divisible by 4, but not divisible by 100)
MOVE 1 TO LEAP-RESULT
ELSE
*>Year is not leap (not divisible by 4)
MOVE 0 TO LEAP-RESULT
END-IF.
Welcome to the Cobol track. Your solution has a couple of problems.
Exercism uses a program called cobol-check for testing your solution. It essentially embeds your solution into a program that runs particular paragraphs in your solution (which is the leap paragraph in the leap exercise). In order for cobol-check to do the job correctly, your solution is written in the fixed-format. Please fix the format.
Your solution has no paragraph named leap. When you got the original source file, it must have looked like:
IDENTIFICATION DIVISION.
PROGRAM-ID. LEAP.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
LEAP.
* Enter solution here
CONTINUE.
LEAP-EXIT.
EXIT.
You need to follow the instruction given there.
The file tst/leap/leap.cut describes what tests are going to be performed. It is written in a domain-specific languange that looks like a cobol code. You see in the file that the test substitute various values to WS-YEAR and expects certain values in WS-RESULT. This means that your solution must declare the two variables and use them suitably.
I made the minimal change to your solution to do the things described above.
*> *************************************************************
*> Author: Geiza
*> Date: Oct-2025
*> Purpose: Determine if an year is leap
*> *************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. Verify-Leap-Year.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-YEAR PIC 9(4).
01 WS-RESULT PIC 9.
01 YEAR-IN PIC 9(004) VALUE ZERO.
01 LEAP-RESULT PIC 9(001) VALUE ZERO.
01 YEAR-IS-LEAP.
03 FILLER PIC X(20) VALUE "YEAR IS LEAP".
01 YEAR-IS-NOT-LEAP.
03 FILLER PIC X(20) VALUE "YEAR IS NOT LEAP".
PROCEDURE DIVISION.
MAIN-ROUTINE.
ACCEPT YEAR-IN.
PERFORM CHECK-LEAP.
IF LEAP-RESULT EQUALS 0
DISPLAY YEAR-IS-LEAP
ELSE
DISPLAY YEAR-IS-NOT-LEAP
END-IF.
STOP RUN.
LEAP.
move WS-YEAR TO YEAR-IN
PERFORM CHECK-LEAP.
MOVE LEAP-RESULT TO WS-RESULT.
CHECK-LEAP.
*>Solution
MOVE 0 TO LEAP-RESULT
IF FUNCTION MOD(YEAR-IN;4) = 0
IF FUNCTION MOD(YEAR-IN;100) = 0
IF FUNCTION MOD(YEAR-IN;400) = 0
*>Year is leap (divisible by 400)
MOVE 1 TO LEAP-RESULT
ELSE
*>Year is not leap (divisible by 100,
*>but not divisible by 400)
MOVE 0 TO LEAP-RESULT
ELSE
*>Year is leap (divisible by 4, but not divisible by 100)
MOVE 1 TO LEAP-RESULT
ELSE
*>Year is not leap (not divisible by 4)
MOVE 0 TO LEAP-RESULT
END-IF.
This code goes through all tests without syntax errors and passes all tests. But I hope that you will rewrite it in a better way. Please remember that you can always request a tutoring session to get help.
Thanks a lot for such a helpfull and well explained answer. I’m really grateful because I’ve learned a lot of about working in Exercism that I didn’t know before.