1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { step, countNeighbors } from '../life';
describe('Game of Life', () => {
test('countNeighbors counts the number of live neighbors', () => {
const grid = [
[false, true, false],
[false, true, false],
[false, true, false]
];
expect(countNeighbors(grid, 1, 1)).toBe(2);
expect(countNeighbors(grid, 0, 0)).toBe(1);
});
test('step advances the game by one step', () => {
const initial = [
[false, true, false],
[false, true, false],
[false, true, false]
];
const expected = [
[false, true, false],
[false, true, false],
[false, true, false]
];
expect(step(initial)).toEqual(expected);
});
});
|