Fix toggleCell Function in Simulation
This commit is contained in:
parent
c8e2417ab8
commit
b1d96efc84
2 changed files with 11 additions and 1 deletions
|
@ -73,7 +73,7 @@ class Simulation {
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCellState(int x, int y) {
|
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() {
|
Map<int, bool> update() {
|
||||||
|
|
|
@ -54,5 +54,15 @@ void main() {
|
||||||
test("throws RangeError if outside the map bounds", () {
|
test("throws RangeError if outside the map bounds", () {
|
||||||
expect(() => sut.toggleCellState(10, 9), throwsRangeError);
|
expect(() => sut.toggleCellState(10, 9), throwsRangeError);
|
||||||
}, tags: const ["nobrowser"]);
|
}, 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