This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (count < 2 || count > 3) { | |
| _grid[x][y] = 0; | |
| } | |
| if (count === 3) { | |
| _grid[x][y] = 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (count < 2 || count > 3) { | |
| _grid[x][y] = 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (count < 2) { | |
| _grid[x][y] = 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var nextFrame = function () { | |
| function countRow(row, prevColumn, nextColumn, isNotCurrent) { | |
| var result = 0; | |
| if (row) { | |
| if (prevColumn) { | |
| result += row[prevColumn]; | |
| } | |
| if (nextColumn) { | |
| result += row[nextColumn]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Game = (function () { | |
| var _grid; | |
| //...some existing code | |
| var setCell = function (x, y) { | |
| _grid[x][y] = 1; | |
| }; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('Game of Life', function () { | |
| var game; | |
| beforeEach(function () { | |
| game = Game(30); | |
| }); | |
| //...other tests |