From 52b440351ddf64a031ed4781eab2a59cd9c6d948 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 23 Oct 2018 20:41:54 +0200 Subject: [PATCH] Add getCell and setCell method to Simulation --- lib/src/Simulation.dart | 4 ++++ test/simulation_test.dart | 32 ++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/src/Simulation.dart b/lib/src/Simulation.dart index f3efd39..1c9461d 100644 --- a/lib/src/Simulation.dart +++ b/lib/src/Simulation.dart @@ -72,6 +72,10 @@ class Simulation { return math.Point(cx.toInt(), cy.toInt()); } + bool getCell(int x, int y) => map.get(x, y); + + void setCell(int x, int y, bool value) => map.set(x, y, value); + void toggleCellState(int x, int y) { map.set(x, y, !map.get(x, y)); } diff --git a/test/simulation_test.dart b/test/simulation_test.dart index e2c6610..66a027b 100644 --- a/test/simulation_test.dart +++ b/test/simulation_test.dart @@ -7,6 +7,8 @@ import 'package:test/test.dart'; class MockGrid extends Mock implements Grid {} +// TODO: reinstate when decoupling rendering from Simulation @Tags(const ["nobrowser"]) + void main() { Simulation sut; setUp(() { @@ -25,7 +27,7 @@ void main() { var oldMap = sut.map; sut.gridSize = Point(10, 10); expect(sut.map, isNot(same(oldMap))); - }, tags: "nobrowser"); + }); }); group("resetMap", () { test("sets the internal map filled with 'false' ", () { @@ -38,7 +40,7 @@ void main() { sut.clearMap(); expect(sut.dirty, true); }); - }, tags: "nobrowser"); + }); group("save&load", () { test( "saves a copy of the map which does not change when the actual map changes", @@ -49,20 +51,38 @@ void main() { expect(sut.loadSnapshot(), isNot(equals(snapshot))); }); - }, tags: "nobrowser"); + }); + group("getCellState", () { + test("throws RangeError if outside map bounds", () { + expect(() => sut.getCell(9, 10), throwsRangeError); + }); + test("returns cell value", () { + sut.map.set(1, 1, true); + expect(sut.getCell(1, 1), true); + }); + }); + group("setCellState", () { + test("throws RangeError if outside map bounds", () { + expect(() => sut.setCell(9, 10, true), throwsRangeError); + }); + test("sets cell value", () { + sut.setCell(1, 1, true); + expect(sut.getCell(1, 1), true); + }); + }); group("toggleCellState", () { test("throws RangeError if outside the map bounds", () { expect(() => sut.toggleCellState(10, 9), throwsRangeError); - }, tags: const ["nobrowser"]); + }); test("sets the cell to false if currently true", () { sut.map.set(1, 1, true); sut.toggleCellState(1, 1); expect(sut.map.get(1, 1), false); - }, tags: const ["nobrowser"]); + }); test("sets the cell to true if currently false", () { sut.map.set(1, 1, false); sut.toggleCellState(1, 1); expect(sut.map.get(1, 1), true); - }, tags: const ["nobrowser"]); + }); }); }