Skip to content

Instantly share code, notes, and snippets.

@davidmatas
Created November 16, 2019 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmatas/3661e29fdf5761a25b8d9b369643a006 to your computer and use it in GitHub Desktop.
Save davidmatas/3661e29fdf5761a25b8d9b369643a006 to your computer and use it in GitHub Desktop.
import should from 'should';
import GameOfLife, { Cell } from '../../src/GameOfLife';
// 1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
// 2. Any live cell with more than three live neighbours dies, as if by overcrowding.
// 3. Any live cell with two or three live neighbours lives on to the next generation.
// 4. Any dead cell with exactly three live neighbours becomes a live cell.
describe('GameOfLife', () => {
it('needs to be defined', () => {
const gameOfLife = new GameOfLife();
should(gameOfLife).not.be.undefined()
})
it('Any live cell with fewer than two live neighbours dies, as if caused by underpopulation', () => {
const cell = new Cell(1)
const cellStatus = cell.getNextStatus(1)
should(cellStatus).be.equal(0)
})
it('Any live cell with more than three live neighbours dies, as if by overcrowding.', () => {
const cell = new Cell(1)
const cellStatus = cell.getNextStatus(4)
should(cellStatus).be.equal(0)
})
it('Any live cell with two lives neighbours on to the next generation.', () => {
const cell = new Cell(1)
const cellStatus = cell.getNextStatus(2)
should(cellStatus).be.equal(1)
})
it('Any live cell with three lives neighbours on to the next generation.', () => {
const cell = new Cell(1)
const cellStatus = cell.getNextStatus(3)
should(cellStatus).be.equal(1)
})
it('Any dead cell with exactly three live neighbours becomes a live cell.', () => {
const cell = new Cell(0)
const cellStatus = cell.getNextStatus(3)
should(cellStatus).be.equal(1)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment