Skip to content

Commit 41bebe6

Browse files
committed
Adding tests for "Cards castle".
1 parent 616d9a2 commit 41bebe6

24 files changed

+402
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
- Tests for "Binary search tree traversal".
3737
- Tests for "Gravity centrifuge".
3838
- Tests for "Identifying data structure".
39+
- Tests for "Cards castle".
3940

4041
## [1.13.0] - 2022-09-30
4142
### Added
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* The "Cards castle" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/cards-castle}
4+
*/
5+
function execute(readline) {
6+
const H = parseInt(readline());
7+
for (let i = 0; i < H; i++) {
8+
const S = readline();
9+
}
10+
11+
// Write an answer using console.log()
12+
// To debug: console.error('Debug messages...');
13+
14+
console.log('UNSTABLE');
15+
}
16+
17+
export { execute };
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../../File.js';
4+
import { execute } from '../../../../../lib/community/training/medium/cardsCastle/cardsCastle.js';
5+
6+
const __dirname = new URL('.', import.meta.url).pathname;
7+
8+
suite("Cards castle", function() {
9+
const sandbox = sinon.createSandbox();
10+
11+
setup(function () {
12+
sandbox.stub(console, "log");
13+
});
14+
15+
teardown(function () {
16+
sandbox.restore();
17+
});
18+
19+
20+
test("Example", function() {
21+
let inputFile = new File(__dirname + 'input/01 - example.txt');
22+
23+
execute(inputFile.readline.bind(inputFile));
24+
25+
assert.strictEqual(
26+
console.log.getCall(0).args[0],
27+
"STABLE"
28+
);
29+
});
30+
31+
test("Little castle", function() {
32+
let inputFile = new File(__dirname + 'input/02 - little castle.txt');
33+
34+
execute(inputFile.readline.bind(inputFile));
35+
36+
assert.strictEqual(
37+
console.log.getCall(0).args[0],
38+
"STABLE"
39+
);
40+
});
41+
42+
test("Little fallen castle", function() {
43+
let inputFile = new File(__dirname + 'input/03 - little fallen castle.txt');
44+
45+
execute(inputFile.readline.bind(inputFile));
46+
47+
assert.strictEqual(
48+
console.log.getCall(0).args[0],
49+
"UNSTABLE"
50+
);
51+
});
52+
53+
test("Fortress", function() {
54+
let inputFile = new File(__dirname + 'input/04 - fortress.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assert.strictEqual(
59+
console.log.getCall(0).args[0],
60+
"STABLE"
61+
);
62+
});
63+
64+
test("Fortress fortress", function() {
65+
let inputFile = new File(__dirname + 'input/05 - fallen fortress.txt');
66+
67+
execute(inputFile.readline.bind(inputFile));
68+
69+
assert.strictEqual(
70+
console.log.getCall(0).args[0],
71+
"UNSTABLE"
72+
);
73+
});
74+
75+
test("Cards are missing ?", function() {
76+
let inputFile = new File(__dirname + 'input/06 - cards are missing ?.txt');
77+
78+
execute(inputFile.readline.bind(inputFile));
79+
80+
assert.strictEqual(
81+
console.log.getCall(0).args[0],
82+
"STABLE"
83+
);
84+
});
85+
86+
test("A lot of cards are missing ?!", function() {
87+
let inputFile = new File(__dirname + 'input/07 - a lot of cards are missing ?!.txt');
88+
89+
execute(inputFile.readline.bind(inputFile));
90+
91+
assert.strictEqual(
92+
console.log.getCall(0).args[0],
93+
"STABLE"
94+
);
95+
});
96+
97+
test("Unstable single card", function() {
98+
let inputFile = new File(__dirname + 'input/08 - unstable single card.txt');
99+
100+
execute(inputFile.readline.bind(inputFile));
101+
102+
assert.strictEqual(
103+
console.log.getCall(0).args[0],
104+
"UNSTABLE"
105+
);
106+
});
107+
108+
test("Flying cards", function() {
109+
let inputFile = new File(__dirname + 'input/09 - flying cards.txt');
110+
111+
execute(inputFile.readline.bind(inputFile));
112+
113+
assert.strictEqual(
114+
console.log.getCall(0).args[0],
115+
"UNSTABLE"
116+
);
117+
});
118+
119+
test("Reversed cards", function() {
120+
let inputFile = new File(__dirname + 'input/10 - reversed cards.txt');
121+
122+
execute(inputFile.readline.bind(inputFile));
123+
124+
assert.strictEqual(
125+
console.log.getCall(0).args[0],
126+
"UNSTABLE"
127+
);
128+
});
129+
130+
test("Few floors", function() {
131+
let inputFile = new File(__dirname + 'input/11 - few floors.txt');
132+
133+
execute(inputFile.readline.bind(inputFile));
134+
135+
assert.strictEqual(
136+
console.log.getCall(0).args[0],
137+
"STABLE"
138+
);
139+
});
140+
141+
test("On the gap", function() {
142+
let inputFile = new File(__dirname + 'input/12 - on the gap.txt');
143+
144+
execute(inputFile.readline.bind(inputFile));
145+
146+
assert.strictEqual(
147+
console.log.getCall(0).args[0],
148+
"UNSTABLE"
149+
);
150+
});
151+
152+
test("Starting on", function() {
153+
let inputFile = new File(__dirname + 'input/13 - starting on.txt');
154+
155+
execute(inputFile.readline.bind(inputFile));
156+
157+
assert.strictEqual(
158+
console.log.getCall(0).args[0],
159+
"STABLE"
160+
);
161+
});
162+
163+
test("Shifted", function() {
164+
let inputFile = new File(__dirname + 'input/14 - shifted.txt');
165+
166+
execute(inputFile.readline.bind(inputFile));
167+
168+
assert.strictEqual(
169+
console.log.getCall(0).args[0],
170+
"STABLE"
171+
);
172+
});
173+
174+
test("Flying castle cards", function() {
175+
let inputFile = new File(__dirname + 'input/15 - flying castle cards.txt');
176+
177+
execute(inputFile.readline.bind(inputFile));
178+
179+
assert.strictEqual(
180+
console.log.getCall(0).args[0],
181+
"UNSTABLE"
182+
);
183+
});
184+
185+
test("Same card side by side", function() {
186+
let inputFile = new File(__dirname + 'input/16 - same card side by side.txt');
187+
188+
execute(inputFile.readline.bind(inputFile));
189+
190+
assert.strictEqual(
191+
console.log.getCall(0).args[0],
192+
"UNSTABLE"
193+
);
194+
});
195+
196+
test("Same flying card side by side", function() {
197+
let inputFile = new File(__dirname + 'input/17 - same flying card side by side.txt');
198+
199+
execute(inputFile.readline.bind(inputFile));
200+
201+
assert.strictEqual(
202+
console.log.getCall(0).args[0],
203+
"UNSTABLE"
204+
);
205+
});
206+
207+
test("Flying reversed card side by side", function() {
208+
let inputFile = new File(__dirname + 'input/18 - flying reversed card side by side.txt');
209+
210+
execute(inputFile.readline.bind(inputFile));
211+
212+
assert.strictEqual(
213+
console.log.getCall(0).args[0],
214+
"UNSTABLE"
215+
);
216+
});
217+
218+
test("The shifted unique one", function() {
219+
let inputFile = new File(__dirname + 'input/19 - the shifted unique one.txt');
220+
221+
execute(inputFile.readline.bind(inputFile));
222+
223+
assert.strictEqual(
224+
console.log.getCall(0).args[0],
225+
"STABLE"
226+
);
227+
});
228+
229+
test("Lost cards", function() {
230+
let inputFile = new File(__dirname + 'input/20 - lost cards.txt');
231+
232+
execute(inputFile.readline.bind(inputFile));
233+
234+
assert.strictEqual(
235+
console.log.getCall(0).args[0],
236+
"STABLE"
237+
);
238+
});
239+
240+
test("Complex", function() {
241+
let inputFile = new File(__dirname + 'input/21 - complex.txt');
242+
243+
execute(inputFile.readline.bind(inputFile));
244+
245+
assert.strictEqual(
246+
console.log.getCall(0).args[0],
247+
"STABLE"
248+
);
249+
});
250+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
.../\...
3+
../\/\..
4+
./\/\/\.
5+
/\/\/\/\
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
./\.
3+
/\/\
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
./\.
3+
/./\
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
6
2+
...../\.....
3+
..../\/\....
4+
.../\/\/\...
5+
../\/\/\/\..
6+
./\/\/\/\/\.
7+
/\/\/\/\/\/\
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
..../\....
3+
.../\/\...
4+
../\/./\..
5+
./\.\/\/\.
6+
/\/\/\/\/\
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
........
3+
../\/\..
4+
./\/\/\.
5+
/\/\/\/\
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
........
3+
../\....
4+
./\/\...
5+
/\/\/\/\

0 commit comments

Comments
 (0)