diff --git a/lib/src/Simulation.dart b/lib/src/Simulation.dart index 5243b84..0955c9a 100644 --- a/lib/src/Simulation.dart +++ b/lib/src/Simulation.dart @@ -154,6 +154,10 @@ class Simulation { _dirty = true; } - void saveSnapshot() => _snapshot = map; - Grid loadSnapshot() => map = _snapshot; + void saveSnapshot() => _snapshot = Grid.from(map); + Grid loadSnapshot() { + map = Grid.from(_snapshot); + _dirty = true; + return map; + } } diff --git a/test/simulation_test.dart b/test/simulation_test.dart index d137f97..7b8bf82 100644 --- a/test/simulation_test.dart +++ b/test/simulation_test.dart @@ -37,12 +37,14 @@ void main() { }, skip: "can not find a way to set dirty to true first yet"); }); group("save&load", () { - test("saves the current map, can be loaded by loadSnapshot", () { - var snapshot = sut.map; + test( + "saves a copy of the map which does not change when the actual map changes", + () { sut.saveSnapshot(); - sut.map = MockGrid(); + sut.mergeStateChanges({1: true, 2: true}); + var snapshot = Grid.from(sut.map); - expect(sut.loadSnapshot(), equals(snapshot)); + expect(sut.loadSnapshot(), isNot(equals(snapshot))); }); }); }