diff --git a/src/components/GameField.js b/src/components/GameField.js index e69de29..2978b36 100644 --- a/src/components/GameField.js +++ b/src/components/GameField.js @@ -0,0 +1,18 @@ +import Cell from "./Cell"; + +export default class GameField { + constructor(seed) { + // seed = [ [] ] + this.map = {}; + seed.forEach((subArray, majorIndex) => + subArray.forEach((value, minorIndex) => { + if (value > 0) { + this.map[`${majorIndex}-${minorIndex}`] = new Cell(true); + } + }) + ); + // instead of implementing multiple GameFields, clear irrelevant keys and expand Game Field as needed + } +} + +// as a stream -> fieldStream => Stream(GameField, () => Stream(GameField.computeNeighbors(), () => Stream(GameField.setLiving())) diff --git a/src/test/Cell.test.js b/src/test/Cell.test.js index a1a5dce..3772976 100644 --- a/src/test/Cell.test.js +++ b/src/test/Cell.test.js @@ -1,4 +1,4 @@ -const Cell = require("../components/Cell"); +import Cell from "../components/Cell"; describe("Cell functionality", () => { test("dispatch toggleLiving state should mark living cell dead", () => { @@ -42,5 +42,4 @@ describe("Cell functionality", () => { expect(cell.living).toEqual(state); }); }); - test.todo("dispatch setLiving should reset live neighbors"); }); diff --git a/src/test/GameField.test.js b/src/test/GameField.test.js new file mode 100644 index 0000000..6f620b2 --- /dev/null +++ b/src/test/GameField.test.js @@ -0,0 +1,24 @@ +import GameField from "../components/GameField"; + +describe("Game Field", () => { + test("smoke test", () => { + expect(new GameField([])).toEqual({ map: {} }); + }); +}); + +describe("Game Field seeds living Cells", () => { + const gameField = new GameField([ + [0, 1, 0], + [1, 0, 1], + ]); + [("0-1", "1-0", "1-2")].forEach((key) => { + test(`${key} should equal living Cell`, () => { + expect(gameField.map[key].living).toEqual(true); + }); + }); + ["0-0", "0-2", "1-1"].forEach((key) => { + test(`${key} should equal undefined`, () => { + expect(gameField.map[key]).toEqual(undefined); + }); + }); +});