Fix toggleCell Function in Simulation

This commit is contained in:
Unknown 2018-10-23 20:30:20 +02:00
parent c8e2417ab8
commit b1d96efc84
2 changed files with 11 additions and 1 deletions

View File

@ -73,7 +73,7 @@ class Simulation {
}
void toggleCellState(int x, int y) {
map.get(x, y) == null ? map.set(x, y, true) : map.set(x, y, false);
map.get(x, y) == false ? map.set(x, y, true) : map.set(x, y, false);
}
Map<int, bool> update() {

View File

@ -54,5 +54,15 @@ void main() {
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"]);
});
}