about summary refs log blame commit diff stats
path: root/ts/bun/__tests__/gameOfLife.test.ts
blob: 21ad86df779e69a67965dc54e2370ae3a7e8e8f6 (plain) (tree)
1
                                               

























                                                                      
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);
    });
});