Add getCell and setCell method to Simulation
This commit is contained in:
parent
5116aff8a4
commit
52b440351d
2 changed files with 30 additions and 6 deletions
|
@ -72,6 +72,10 @@ class Simulation {
|
|||
return math.Point<int>(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));
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import 'package:test/test.dart';
|
|||
|
||||
class MockGrid extends Mock implements Grid<bool> {}
|
||||
|
||||
// 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"]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue