{"size": 1919, "ext": "js", "max_stars_repo_path": "test/example/grid3x3AsMonoDimensionalArray.js", "max_stars_repo_name": "fibo/games-of-life", "max_stars_repo_stars_event_min_datetime": "2015-05-31T01:14:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T17:38:56.000Z", "max_issues_repo_path": "test/example/grid3x3AsMonoDimensionalArray.js", "max_issues_repo_name": "fibo/games-of-life", "max_issues_repo_issues_event_min_datetime": "2016-07-10T10:29:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-06T12:52:30.000Z", "max_forks_repo_path": "test/example/grid3x3AsMonoDimensionalArray.js", "max_forks_repo_name": "fibo/games-of-life", "max_forks_repo_forks_event_min_datetime": "2016-07-06T08:12:08.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-25T14:30:08.000Z"}
{"max_stars_count": 26, "max_issues_count": 3, "max_forks_count": 6, "avg_line_length": 24.9220779221, "max_line_length": 93, "alphanum_fraction": 0.6206357478}
var gamesOfLife = require('games-of-life')

var createWorld = gamesOfLife.createWorld
var transitionRule = gamesOfLife.classicTransitionRule.bind(null, 2, 3, 3)

/**
 * @params {Number} cell represented by an array index
 * @returns {Array} neighboursOf
 */

function getNeighboursOf (index) {
  var neighboursOf = {
    0: [1, 3, 4],
    1: [0, 2, 3, 4, 5],
    2: [1, 4, 5],
    3: [0, 1, 4, 6, 7],
    4: [0, 1, 2, 3, 5, 6, 7, 8],
    5: [1, 2, 4, 7, 8],
    6: [3, 4, 7],
    7: [3, 4, 5, 6, 8],
    8: [4, 5, 7]
  }

  return neighboursOf[index]
}

var world = createWorld(getNeighboursOf)

var evolve = world(transitionRule)

describe('grid3x3AsMonoDimensionalArray', function () {
  function pattern0 (cell) {
    return false
  }

  function pattern1 (cell) {
    return cell === 0
  }

  function horyzontalBlinker (cell) {
    return (cell === 3) || (cell === 4) || (cell === 5)
  }

  function verticalBlinker (cell) {
    return (cell === 1) || (cell === 4) || (cell === 7)
  }

  function patternsAreEqual (patternA, patternB) {
    var areEqual = true

    for (var i = 0; i < 9; i++) {
      if (patternA(i) !== patternB(i)) {
        areEqual = false
      }
    }

    return areEqual
  }

  describe('patternsAreEqual', function () {
    it('is a reflection', function () {
      patternsAreEqual(pattern0, pattern0).should.be.true()
      patternsAreEqual(pattern1, pattern1).should.be.true()
      patternsAreEqual(horyzontalBlinker, horyzontalBlinker).should.be.true()
    })
  })

  describe('evolve', function () {
    it('as expected', function () {
      patternsAreEqual(evolve(pattern1), pattern0).should.be.true()
      patternsAreEqual(evolve(verticalBlinker), horyzontalBlinker).should.be.true()
      patternsAreEqual(evolve(horyzontalBlinker), verticalBlinker).should.be.true()
      patternsAreEqual(evolve(evolve(horyzontalBlinker)), horyzontalBlinker).should.be.true()
    })
  })
})
