Skip to content

Commit 86c842c

Browse files
committed
Adding tests for "War".
1 parent f2aa53b commit 86c842c

File tree

12 files changed

+505
-1
lines changed

12 files changed

+505
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [1.3.0] - 2022-03-02
88
### Added
99
- Tests for "Network cabling".
1010
- Tests for "Scrabble".
1111
- Tests for "Stock exchange losses".
1212
- Tests for "Telephone numbers".
1313
- Tests for "The gift".
14+
- Tests for "War".
1415

1516
## [1.2.0] - 2022-03-02
1617
### Added

lib/training/medium/war/war.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* The "War" puzzle.
3+
*/
4+
function execute(readline) {
5+
const n = parseInt(readline()); // the number of cards for player 1
6+
for (let i = 0; i < n; i++) {
7+
const cardp1 = readline(); // the n cards of player 1
8+
}
9+
const m = parseInt(readline()); // the number of cards for player 2
10+
for (let i = 0; i < m; i++) {
11+
const cardp2 = readline(); // the m cards of player 2
12+
}
13+
14+
// Write an answer using console.log()
15+
// To debug: console.error('Debug messages...');
16+
17+
console.log('PAT');
18+
}
19+
20+
export { execute };

test/training/medium/war/CGTest.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { assert } from 'chai';
2+
import sinon from 'sinon';
3+
import File from '../../../File.js';
4+
import { execute } from '../../../../lib/training/medium/war/war.js';
5+
6+
/**
7+
* Tests for the "War" puzzle.
8+
*/
9+
suite('War', function() {
10+
const sandbox = sinon.createSandbox();
11+
12+
setup(function () {
13+
sandbox.stub(console, "log");
14+
});
15+
16+
teardown(function () {
17+
sandbox.restore();
18+
});
19+
20+
21+
test('3 cards', function() {
22+
let inputFile = new File('./test/training/medium/war/input/01 - 3 cards.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assert.strictEqual(
27+
console.log.getCall(0).args[0],
28+
'1 3'
29+
);
30+
});
31+
32+
test('26 cards', function() {
33+
let inputFile = new File('./test/training/medium/war/input/02 - 26 cards.txt');
34+
35+
execute(inputFile.readline.bind(inputFile));
36+
37+
assert.strictEqual(
38+
console.log.getCall(0).args[0],
39+
'2 26'
40+
);
41+
});
42+
43+
test('26 cards, medium length', function() {
44+
let inputFile = new File('./test/training/medium/war/input/03 - 26 cards medium length.txt');
45+
46+
execute(inputFile.readline.bind(inputFile));
47+
48+
assert.strictEqual(
49+
console.log.getCall(0).args[0],
50+
'2 56'
51+
);
52+
});
53+
54+
test('Battle', function() {
55+
let inputFile = new File('./test/training/medium/war/input/04 - battle.txt');
56+
57+
execute(inputFile.readline.bind(inputFile));
58+
59+
assert.strictEqual(
60+
console.log.getCall(0).args[0],
61+
'2 1'
62+
);
63+
});
64+
65+
test('One game, one battle', function() {
66+
let inputFile = new File('./test/training/medium/war/input/05 - one game one battle.txt');
67+
68+
execute(inputFile.readline.bind(inputFile));
69+
70+
assert.strictEqual(
71+
console.log.getCall(0).args[0],
72+
'1 52'
73+
);
74+
});
75+
76+
test('2 chained battles', function() {
77+
let inputFile = new File('./test/training/medium/war/input/06 - 2 chained battles.txt');
78+
79+
execute(inputFile.readline.bind(inputFile));
80+
81+
assert.strictEqual(
82+
console.log.getCall(0).args[0],
83+
'2 1'
84+
);
85+
});
86+
87+
test('Long game', function() {
88+
let inputFile = new File('./test/training/medium/war/input/07 - long game.txt');
89+
90+
execute(inputFile.readline.bind(inputFile));
91+
92+
assert.strictEqual(
93+
console.log.getCall(0).args[0],
94+
'2 1262'
95+
);
96+
});
97+
98+
test('PAT', function() {
99+
let inputFile = new File('./test/training/medium/war/input/08 - PAT.txt');
100+
101+
execute(inputFile.readline.bind(inputFile));
102+
103+
assert.strictEqual(
104+
console.log.getCall(0).args[0],
105+
'PAT'
106+
);
107+
});
108+
109+
test('Another PAT', function() {
110+
let inputFile = new File('./test/training/medium/war/input/09 - another PAT.txt');
111+
112+
execute(inputFile.readline.bind(inputFile));
113+
114+
assert.strictEqual(
115+
console.log.getCall(0).args[0],
116+
'PAT'
117+
);
118+
});
119+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
3
2+
AD
3+
KC
4+
QC
5+
3
6+
KH
7+
QS
8+
JC
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
26
2+
5C
3+
3D
4+
2C
5+
7D
6+
8C
7+
7S
8+
5D
9+
5H
10+
6D
11+
5S
12+
4D
13+
6H
14+
6S
15+
3C
16+
3S
17+
7C
18+
4S
19+
4H
20+
7H
21+
4C
22+
2H
23+
6C
24+
8D
25+
3H
26+
2D
27+
2S
28+
26
29+
AC
30+
9H
31+
KH
32+
KC
33+
KD
34+
KS
35+
10S
36+
10D
37+
9S
38+
QD
39+
JS
40+
10H
41+
8S
42+
QH
43+
JD
44+
AD
45+
JC
46+
AS
47+
QS
48+
AH
49+
JH
50+
10C
51+
9C
52+
8H
53+
QC
54+
9D
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
26
2+
6H
3+
7H
4+
6C
5+
QS
6+
7S
7+
8D
8+
6D
9+
5S
10+
6S
11+
QH
12+
4D
13+
3S
14+
7C
15+
3C
16+
4S
17+
5H
18+
QD
19+
5C
20+
3H
21+
3D
22+
8C
23+
4H
24+
4C
25+
QC
26+
5D
27+
7D
28+
26
29+
JH
30+
AH
31+
KD
32+
AD
33+
9C
34+
2D
35+
2H
36+
JC
37+
10C
38+
KC
39+
10D
40+
JS
41+
JD
42+
9D
43+
9S
44+
KS
45+
AS
46+
KH
47+
10S
48+
8S
49+
2S
50+
10H
51+
8H
52+
AC
53+
2C
54+
9H
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
5
2+
8C
3+
KD
4+
AH
5+
QH
6+
2S
7+
5
8+
8D
9+
2D
10+
3H
11+
4D
12+
3S
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
26
2+
10H
3+
KD
4+
6C
5+
10S
6+
8S
7+
AD
8+
QS
9+
3D
10+
7H
11+
KH
12+
9D
13+
2D
14+
JC
15+
KS
16+
3S
17+
2S
18+
QC
19+
AC
20+
JH
21+
7D
22+
KC
23+
10D
24+
4C
25+
AS
26+
5D
27+
5S
28+
26
29+
2H
30+
9C
31+
8C
32+
4S
33+
5C
34+
AH
35+
JD
36+
QH
37+
7C
38+
5H
39+
4H
40+
6H
41+
6S
42+
QD
43+
9H
44+
10C
45+
4D
46+
JS
47+
6D
48+
3H
49+
8H
50+
3C
51+
7S
52+
9S
53+
8D
54+
2C
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
9
2+
8C
3+
KD
4+
AH
5+
QH
6+
3D
7+
KD
8+
AH
9+
QH
10+
6D
11+
9
12+
8D
13+
2D
14+
3H
15+
4D
16+
3S
17+
2D
18+
3H
19+
4D
20+
7H

0 commit comments

Comments
 (0)