Skip to content

Commit e68f9d7

Browse files
committed
Adding tests for "Game of life".
1 parent ffe3861 commit e68f9d7

File tree

16 files changed

+391
-0
lines changed

16 files changed

+391
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- Tests for "Find the missing plus signs in addition".
3131
- Tests for "Rod cutting problem".
3232
- Tests for "Magic stones".
33+
- Tests for "Game of life".
3334

3435
## [1.13.0] - 2022-09-30
3536
### Added
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The "Game of life" puzzle.
3+
* @see {@link https://www.codingame.com/ide/puzzle/game-of-life}
4+
*/
5+
function execute(readline) {
6+
var inputs = readline().split(' ');
7+
const width = parseInt(inputs[0]);
8+
const height = parseInt(inputs[1]);
9+
for (let i = 0; i < height; i++) {
10+
const line = readline();
11+
}
12+
13+
// Write an answer using console.log()
14+
// To debug: console.error('Debug messages...');
15+
16+
console.log('answer');
17+
}
18+
19+
export { execute };
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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/community/training/medium/gameOfLife/gameOfLife.js';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
suite("Game of life", 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("3x3", function() {
22+
let inputFile = new File(__dirname + 'input/01 - 3x3.txt');
23+
24+
execute(inputFile.readline.bind(inputFile));
25+
26+
assertOutputAnswer(__dirname + 'output/01 - 3x3.txt');
27+
});
28+
29+
test("3x3 - 2", function() {
30+
let inputFile = new File(__dirname + 'input/02 - 3x3.txt');
31+
32+
execute(inputFile.readline.bind(inputFile));
33+
34+
assertOutputAnswer(__dirname + 'output/02 - 3x3.txt');
35+
});
36+
37+
test("26x5", function() {
38+
let inputFile = new File(__dirname + 'input/03 - 26x5.txt');
39+
40+
execute(inputFile.readline.bind(inputFile));
41+
42+
assertOutputAnswer(__dirname + 'output/03 - 26x5.txt');
43+
});
44+
45+
test("1x100", function() {
46+
let inputFile = new File(__dirname + 'input/04 - 1x100.txt');
47+
48+
execute(inputFile.readline.bind(inputFile));
49+
50+
assertOutputAnswer(__dirname + 'output/04 - 1x100.txt');
51+
});
52+
53+
test("100x1", function() {
54+
let inputFile = new File(__dirname + 'input/05 - 100x1.txt');
55+
56+
execute(inputFile.readline.bind(inputFile));
57+
58+
assertOutputAnswer(__dirname + 'output/05 - 100x1.txt');
59+
});
60+
61+
test("30x30", function() {
62+
let inputFile = new File(__dirname + 'input/06 - 30x30.txt');
63+
64+
execute(inputFile.readline.bind(inputFile));
65+
66+
assertOutputAnswer(__dirname + 'output/06 - 30x30.txt');
67+
});
68+
69+
test("1x1", function() {
70+
let inputFile = new File(__dirname + 'input/07 - 1x1.txt');
71+
72+
execute(inputFile.readline.bind(inputFile));
73+
74+
assert.strictEqual(
75+
console.log.getCall(0).args[0],
76+
0
77+
);
78+
});
79+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3 3
2+
000
3+
111
4+
000
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3 3
2+
010
3+
111
4+
010
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
26 5
2+
10110100001011110111100001
3+
10110101111011110111101101
4+
10000100001011110111101101
5+
10110101111011110111101101
6+
10110100001000010000100001
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
1 100
2+
0
3+
1
4+
0
5+
0
6+
0
7+
1
8+
0
9+
1
10+
0
11+
1
12+
0
13+
0
14+
1
15+
0
16+
1
17+
0
18+
0
19+
0
20+
0
21+
1
22+
0
23+
0
24+
0
25+
0
26+
0
27+
1
28+
0
29+
0
30+
0
31+
1
32+
1
33+
1
34+
1
35+
0
36+
0
37+
1
38+
1
39+
1
40+
0
41+
1
42+
1
43+
1
44+
0
45+
0
46+
1
47+
0
48+
1
49+
1
50+
0
51+
0
52+
0
53+
0
54+
1
55+
0
56+
0
57+
1
58+
1
59+
0
60+
0
61+
1
62+
0
63+
1
64+
0
65+
0
66+
0
67+
0
68+
0
69+
0
70+
0
71+
0
72+
0
73+
0
74+
0
75+
0
76+
1
77+
1
78+
0
79+
0
80+
0
81+
1
82+
0
83+
0
84+
0
85+
0
86+
1
87+
0
88+
0
89+
0
90+
1
91+
0
92+
0
93+
0
94+
0
95+
1
96+
0
97+
0
98+
1
99+
1
100+
1
101+
0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
100 1
2+
0010000101110011000010010000011000010100000001001001000010001010000010101000000110001000011011001000
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
30 30
2+
010100100001101010001000000000
3+
110000000111111100011100001110
4+
111010011101000000010010101100
5+
101001001000000010010100010100
6+
110000000000000110000010000001
7+
100100101010000010011001000000
8+
000110010001000010101001000011
9+
101001010010001000101101100100
10+
100010101011110110000100000100
11+
000001000001101101100111101100
12+
001001110100111111000000000011
13+
100000010010100000000010000000
14+
000001001000000110010011001010
15+
101100111011101000100000010010
16+
010000110110110101100010000010
17+
000000000000001100011110000000
18+
000110011110001100001110001000
19+
000000111000000100100000000001
20+
101010000100000000111001001100
21+
011100000000000011100100000001
22+
010110000001011000010000100001
23+
001001110100100000000100000100
24+
001001110000101100000000010100
25+
100000010100100100000000101000
26+
001010100100100001101100011000
27+
000000110101110001001000011011
28+
000001110000001000001000101000
29+
001000000010000000001001100101
30+
000101000101001000100000101001
31+
100100001000000110011001000000
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1 1
2+
0

0 commit comments

Comments
 (0)