I’ve done exercises ‘Pangram’ and ‘Leap’, verified my solution with a COBOL Online Compiler but still the test functionality in exercism shows that some tests are not correct.
Does anyone know how this can be fixed or is this a common issue with the testing of COBOL exercises on the browser?
Unfortunately, that way you cannot post your solution and the exercise just stays open all the time although it is solved…
Can you include your code for those exercises, which tests were failing, and what error messages were you getting? That’ll be helpful for us to understand what’s going on. Also, when you verified your solution with the compiler, were you using the test cases provided by Exercism?
Of course, see my code and test case summary for COBOL Pangram and COBOL Leap below. Exactly, verfied my code with the testcases provided by Exercism in the COBOL Online Compiler of Online COBOL Compiler
Pangram: My Code
IDENTIFICATION DIVISION.
PROGRAM-ID. PANGRAM.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-SENTENCE PIC X(60) VALUE '’.
01 WS-SENTENCE-UC PIC X(60).
01 WS-SENT-PNTR PIC 9(2) VALUE 1.
01 WS-LETTER PIC X(1) VALUE 'A'.
01 WS-RESULT PIC 9 VALUE 0.
01 WS-COUNTER PIC 9(2) VALUE 0.
01 WS-ALPH-TABLE.
05 WS-ALPH-VALUES.
10 FILLER PIC X(13) VALUE 'ABCDEFGHIJKLM'.
10 FILLER PIC X(13) VALUE 'NOPQRSTUVWXYZ'.
05 WS-ALPH-ENTRIES REDEFINES WS-ALPH-VALUES.
10 WS-ALPH-ENTRY PIC X(01) OCCURS 26 TIMES.
05 WS-ALPH-DRIVER PIC 9(2) VALUE 1.
05 WS-CHECK-CHAR PIC X(1).
PROCEDURE DIVISION.
PANGRAM SECTION.
*>make sentence upper case
MOVE FUNCTION UPPER-CASE(WS-SENTENCE) TO WS-SENTENCE-UC
*>iterate through alphabet
PERFORM LENGTH OF WS-ALPH-VALUES TIMES
*>take each character one at a time
MOVE WS-ALPH-ENTRY(WS-ALPH-DRIVER) TO WS-CHECK-CHAR
*>go through sentence, if sentence contains character, increase counter
PERFORM LENGTH OF WS-SENTENCE TIMES
IF WS-SENTENCE-UC(WS-SENT-PNTR:1) = WS-CHECK-CHAR THEN
MOVE 1 TO WS-SENT-PNTR
ADD 1 TO WS-COUNTER
EXIT PERFORM
ELSE
ADD 1 TO WS-SENT-PNTR
END-IF
END-PERFORM
MOVE 1 TO WS-SENT-PNTR
ADD 1 TO WS-ALPH-DRIVER
END-PERFORM
*>if counter is 26 at the end return 1, else return 0
IF WS-COUNTER = 26 THEN
MOVE 1 TO WS-RESULT
END-IF
DISPLAY WS-RESULT
DISPLAY WS-COUNTER
EXIT.
Pangram: Exercism Test Cases
test.cob:157: warning: alphanumeric literal has zero length; a SPACE will be assumed [-Wothers]
155 | TO UT-TEST-CASE-NAME..
156 | PERFORM UT-INITIALIZE-MOCK-COUNT..
157 > MOVE '' TO WS-SENTENCE..
158 | PERFORM PANGRAM..
159 | ADD 1 TO UT-TEST-CASE-COUNT..
00
0
PASS: 1. empty sentence
04
0
**** FAIL: 2. perfect lower case
EXPECTED +00000000001.0000000, WAS +00000000000.0000000
30
0
**** FAIL: 3. only lower case
EXPECTED +00000000001.0000000, WAS +00000000000.0000000
55
0
PASS: 4. missing the letter 'x'
76
0
PASS: 5. missing the letter 'h'
84
0
**** FAIL: 6. with underscores
EXPECTED +00000000001.0000000, WAS +00000000000.0000000
10
0
**** FAIL: 7. with numbers
EXPECTED +00000000001.0000000, WAS +00000000000.0000000
34
0
PASS: 8. missing letters replaced by numbers
52
0
**** FAIL: 9. mixed case and punctuation
EXPECTED +00000000001.0000000, WAS +00000000000.0000000
64
0
PASS: 10. case insensitive
90
0
PASS: 11. a-m and A-M are 26 different characters but not a pangram
11 TEST CASES WERE EXECUTED
6 PASSED
5 FAILED
=================================================
Leap: My Code
IDENTIFICATION DIVISION.
PROGRAM-ID. LEAP.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-YEAR PIC 9(4) VALUE 1800.
01 WS-RESULT PIC 9(1) VALUE 0.
01 WS-TEMP PIC 9(5).
01 WS-REM4 PIC 9(5).
01 WS-REM100 PIC 9(5).
01 WS-REM400 PIC 9(5).
PROCEDURE DIVISION.
LEAP SECTION.
DIVIDE WS-YEAR BY 4 GIVING WS-TEMP REMAINDER WS-REM4
DIVIDE WS-YEAR BY 100 GIVING WS-TEMP REMAINDER WS-REM100
DIVIDE WS-YEAR BY 400 GIVING WS-TEMP REMAINDER WS-REM400
IF WS-REM4 = 0 AND (WS-REM100 NOT = 0 OR WS-REM400 = 0) THEN
MOVE 1 TO WS-RESULT
END-IF
DISPLAY WS-RESULT
EXIT.
Leap: Exercism Test Cases
PASS: 1. year not divisible by 4 in common year
PASS: 2. year divisible by 2, not divisible by 4 in common year
PASS: 3. year divisible by 4, not divisible by 100 in leap year
PASS: 4. year divisible by 4 and 5 is still a leap year
**** FAIL: 5. year divisible by 100, not divisible by 400 in common year
EXPECTED +00000000000.0000000, WAS +00000000001.0000000
**** FAIL: 6. year divisible by 100 but not by 3 is still not a leap year
EXPECTED +00000000000.0000000, WAS +00000000001.0000000
PASS: 7. year divisible by 400 is leap year
PASS: 8. year divisible by 400 but not by 125 is still a leap year
**** FAIL: 9. year divisible by 200, not divisible by 400 in common year
EXPECTED +00000000000.0000000, WAS +00000000001.0000000
9 TEST CASES WERE EXECUTED
6 PASSED
3 FAILED
=================================================
Look at what I did:
IDENTIFICATION DIVISION.
PROGRAM-ID. LEAP.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-YEAR PIC 9(4).
01 WS-RESULT PIC 9(1).
PROCEDURE DIVISION.
LEAP.
IF (FUNCTION MOD(WS-YEAR 4) = 0 AND FUNCTION MOD(WS-YEAR 100) NOT = 0)
MOVE 1 TO WS-RESULT
ELSE
IF (FUNCTION MOD(WS-YEAR 100) = 0 AND FUNCTION MOD(WS-YEAR 400) = 0)
MOVE 1 TO WS-RESULT
ELSE
MOVE 0 TO WS-RESULT
END-IF
END-IF
DISPLAY "WS-YEAR : " WS-YEAR " IS A LEAP YEAR: " WS-RESULT
CONTINUE.
LEAP-EXIT.
EXIT.
I think you need to first verify if the number is divisible by 4. Then you can check if the number is divisible by 100. If it’s divisible by 100 you should also check if it’s divisible by 400.
Hope this helps.
I do not know Cobol, but I do know how Leap works. I did a few things:
There are about 250 published solutions for leap on the Cobol track. They all pass the latest set of tests. I therefor don’t think there is an issue with the tests, and I don’t think we can assert it doesn’t work on Exercism.
I then checked the online compiler version. It reports (emphasis mine): This Online Compiler provides you the comfort to edit and compile your Cobol code using latest version GnuCOBOL v3.1.2. I then went to the test runner and saw that this uses version 3.2, so I don’t think that would be the reason.
I then tried to reproduce “a passing solution” on the online compiler you linked, but I cannot get that to work. Can you show me how you are running the tests and the solution there and getting a passing solution?
This is a good question.
I hope that @axtens is around. They know a lot about Cobol and the test runner and perhaps can help out here.