Created
October 22, 2016 19:16
-
-
Save andrewle/1a0568b9b108dcd3920a30d9ec65f63b to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
class Board { | |
constructor() { | |
this.width = 10; | |
this.height = 12; | |
this.grid = this._initializeToZeros(); | |
this.grid[2][1] = 1; | |
} | |
isAlive(coord) { | |
return this.grid[coord.y][coord.x] === 1; | |
} | |
_initializeToZeros() { | |
let r = []; | |
for(let y = 0; y < this.height; y++) { | |
r.push([]); | |
for(let x = 0; x < this.width; x++) { | |
r[y].push(0); | |
} | |
} | |
return r; | |
} | |
} | |
class Coord { | |
constructor(x, y) { | |
this.x = x; | |
this.y = y; | |
} | |
} | |
function blah() { | |
let board = new Board(3,3,[ | |
new Coord(1,1) | |
]); | |
let game = new Game(board); | |
game.tick(); | |
} | |
describe("Conway's game of life", function() { | |
describe("Board", function() { | |
beforeEach(function() { | |
this.board = new Board(); | |
}); | |
it("has a height", function() { | |
expect(this.board.height).toBe(12); | |
}); | |
it("has a width", function() { | |
expect(this.board.width).toBe(10); | |
}); | |
describe("the initialState", function() { | |
it("1,2 is alive", function() { | |
expect(this.board.isAlive(new Coord(1,2))).toBe(true); | |
}); | |
it("1,3 is not alive", function() { | |
expect(this.board.isAlive(new Coord(1,3))).toBe(false); | |
}); | |
}); | |
}); | |
describe("Game", function() { | |
beforeEach(function() { | |
this.board = new Board(); | |
this.game = new Game(board); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@SamNazar