diff --git a/lib/src/Simulation.dart b/lib/src/Simulation.dart index 54c7efa..5243b84 100644 --- a/lib/src/Simulation.dart +++ b/lib/src/Simulation.dart @@ -10,6 +10,8 @@ enum CellPattern { SpaceShip, Blinker } class Simulation { Grid map; + Grid _snapshot; + RuleSet rules = GameOfLife(); bool _dirty = true; @@ -151,4 +153,7 @@ class Simulation { _renderEdges = on; _dirty = true; } + + void saveSnapshot() => _snapshot = map; + Grid loadSnapshot() => map = _snapshot; } diff --git a/test/simulation_test.dart b/test/simulation_test.dart index b8f5db6..d137f97 100644 --- a/test/simulation_test.dart +++ b/test/simulation_test.dart @@ -5,6 +5,8 @@ import 'package:test/test.dart'; import 'package:rules_of_living/src/Simulation.dart'; +class MockGrid extends Mock implements Grid {} + void main() { Simulation sut; setUp(() { @@ -34,4 +36,13 @@ void main() { expect(sut.dirty, true); }, 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; + sut.saveSnapshot(); + sut.map = MockGrid(); + + expect(sut.loadSnapshot(), equals(snapshot)); + }); + }); }