Skip to content

Instantly share code, notes, and snippets.

View dtryon's full-sized avatar

Davin Tryon dtryon

View GitHub Profile
if (count < 2 || count > 3) {
_grid[x][y] = 0;
}
if (count === 3) {
_grid[x][y] = 1;
}
describe('Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.', function () {
it('should set cell with three live neighbours on different rows', function () {
game.setCell(2,2);
game.setCell(3,4);
game.setCell(4,4);
game.nextFrame();
expect(game.grid()[3][3]).toBe(1);
});
if (count < 2 || count > 3) {
_grid[x][y] = 0;
}
describe('Any live cell with more than three live neighbours dies, as if by overcrowding.', function () {
it('should kill cell with four live neighbours on different rows', function () {
game.setCell(2,2);
game.setCell(3,4);
game.setCell(4,4);
game.setCell(4,3);
game.setCell(3,3);
game.nextFrame();
describe('Any live cell with two or three live neighbours lives on to the next generation.', function () {
it('should save cell with two live neighbours', function () {
game.setCell(3,2);
game.setCell(3,4);
game.setCell(3,3);
game.nextFrame();
expect(game.grid()[3][3]).toBe(1);
});
if (count < 2) {
_grid[x][y] = 0;
}
var nextFrame = function () {
function countRow(row, prevColumn, nextColumn, isNotCurrent) {
var result = 0;
if (row) {
if (prevColumn) {
result += row[prevColumn];
}
if (nextColumn) {
result += row[nextColumn];
describe('Any live cell with fewer than two live neighbours dies, as if caused by under-population.', function () {
it('should kill cell with no live neighbours', function () {
game.setCell(3,3);
game.nextFrame();
expect(game.grid()[3][3]).toBe(0);
});
it('should kill cell with one live neighbour', function () {
game.setCell(3,2);
var Game = (function () {
var _grid;
//...some existing code
var setCell = function (x, y) {
_grid[x][y] = 1;
};
describe('Game of Life', function () {
var game;
beforeEach(function () {
game = Game(30);
});
//...other tests