Skip to content

Commit cfb6628

Browse files
committed
Adding tests for "CGX formatter".
1 parent f51437b commit cfb6628

25 files changed

+613
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Tests for "Blunder - episode 2".
1010
- Tests for "Blunder - episode 3".
11+
- Tests for "CGX formatter".
1112

1213
## [1.3.0] - 2022-03-02
1314
### Added
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* The "CGX formatter" puzzle.
3+
*/
4+
function execute(readline) {
5+
const N = parseInt(readline());
6+
for (let i = 0; i < N; i++) {
7+
const cgxLine = readline();
8+
}
9+
10+
// Write an answer using console.log()
11+
// To debug: console.error('Debug messages...');
12+
13+
console.log('answer');
14+
}
15+
16+
export { execute };
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../File.js';
4+
import { assertOutputAnswer } from '../../../assertOutputAnswer.js';
5+
import { execute } from '../../../../lib/training/hard/CGXFormatter/CGXFormatter.js';
6+
7+
/**
8+
* Tests for the "CGX formatter" puzzle.
9+
*/
10+
suite('CGX formatter', function() {
11+
const sandbox = sinon.createSandbox();
12+
13+
setup(function () {
14+
sandbox.stub(console, "log");
15+
});
16+
17+
teardown(function () {
18+
sandbox.restore();
19+
});
20+
21+
22+
test('Boolean value with spaces and tabs', function() {
23+
let inputFile = new File('./test/training/hard/CGXFormatter/input/01 - boolean value with spaces and tabs.txt');
24+
25+
execute(inputFile.readline.bind(inputFile));
26+
27+
assert.strictEqual(
28+
console.log.getCall(0).args[0],
29+
"true"
30+
);
31+
});
32+
33+
test('Simple string of characters which must not be modified', function() {
34+
let inputFile = new File('./test/training/hard/CGXFormatter/input/02 - simple string of characters which must not be modified.txt');
35+
36+
execute(inputFile.readline.bind(inputFile));
37+
38+
assert.strictEqual(
39+
console.log.getCall(0).args[0],
40+
"' Content with spaces and tabs'"
41+
);
42+
});
43+
44+
test('Block containing a single value', function() {
45+
let inputFile = new File('./test/training/hard/CGXFormatter/input/03 - block containing a single value.txt');
46+
47+
execute(inputFile.readline.bind(inputFile));
48+
49+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/03 - block containing a single value.txt');
50+
});
51+
52+
test('Block containing multiple values', function() {
53+
let inputFile = new File('./test/training/hard/CGXFormatter/input/04 - block containing a multiple values.txt');
54+
55+
execute(inputFile.readline.bind(inputFile));
56+
57+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/04 - block containing a multiple values.txt');
58+
});
59+
60+
test('Nested blocks', function() {
61+
let inputFile = new File('./test/training/hard/CGXFormatter/input/05 - nested blocks.txt');
62+
63+
execute(inputFile.readline.bind(inputFile));
64+
65+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/05 - nested blocks.txt');
66+
});
67+
68+
test('Empty block', function() {
69+
let inputFile = new File('./test/training/hard/CGXFormatter/input/06 - empty block.txt');
70+
71+
execute(inputFile.readline.bind(inputFile));
72+
73+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/06 - empty block.txt');
74+
});
75+
76+
test('Block containing several blocks', function() {
77+
let inputFile = new File('./test/training/hard/CGXFormatter/input/07 - block containing several blocks.txt');
78+
79+
execute(inputFile.readline.bind(inputFile));
80+
81+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/07 - block containing several blocks.txt');
82+
});
83+
84+
test('Key/value without blanks', function() {
85+
let inputFile = new File('./test/training/hard/CGXFormatter/input/08 - key value without blanks.txt');
86+
87+
execute(inputFile.readline.bind(inputFile));
88+
89+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/08 - key value without blanks.txt');
90+
});
91+
92+
test('Block with several key/value', function() {
93+
let inputFile = new File('./test/training/hard/CGXFormatter/input/09 - block with several key value.txt');
94+
95+
execute(inputFile.readline.bind(inputFile));
96+
97+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/09 - block with several key value.txt');
98+
});
99+
100+
test('Example provided', function() {
101+
let inputFile = new File('./test/training/hard/CGXFormatter/input/10 - example provided.txt');
102+
103+
execute(inputFile.readline.bind(inputFile));
104+
105+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/10 - example provided.txt');
106+
});
107+
108+
test('Full example', function() {
109+
let inputFile = new File('./test/training/hard/CGXFormatter/input/11 - full example.txt');
110+
111+
execute(inputFile.readline.bind(inputFile));
112+
113+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/11 - full example.txt');
114+
});
115+
116+
test('Numerous overlaps', function() {
117+
let inputFile = new File('./test/training/hard/CGXFormatter/input/12 - numerous overlaps.txt');
118+
119+
execute(inputFile.readline.bind(inputFile));
120+
121+
assertOutputAnswer('./test/training/hard/CGXFormatter/output/12 - numerous overlaps.txt');
122+
});
123+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
3+
4+
true
5+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
' Content with spaces and tabs'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
(0)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
(0;1;2)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
((true))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
((true);(false);(0))

0 commit comments

Comments
 (0)