From b1d96efc842636f04decfd91e6201f57986978b0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 23 Oct 2018 20:30:20 +0200 Subject: [PATCH] Fix toggleCell Function in Simulation --- lib/src/Simulation.dart | 2 +- test/simulation_test.dart | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/src/Simulation.dart b/lib/src/Simulation.dart index b00ede5..ddd6086 100644 --- a/lib/src/Simulation.dart +++ b/lib/src/Simulation.dart @@ -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 update() { diff --git a/test/simulation_test.dart b/test/simulation_test.dart index a7073db..e2c6610 100644 --- a/test/simulation_test.dart +++ b/test/simulation_test.dart @@ -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"]); }); }