Add Simulation Saving and Loading Methods

This commit is contained in:
Unknown 2018-10-19 19:59:00 +02:00
parent befb345ddd
commit 0da2d08b74
2 changed files with 16 additions and 0 deletions

View File

@ -10,6 +10,8 @@ enum CellPattern { SpaceShip, Blinker }
class Simulation {
Grid<bool> map;
Grid<bool> _snapshot;
RuleSet rules = GameOfLife();
bool _dirty = true;
@ -151,4 +153,7 @@ class Simulation {
_renderEdges = on;
_dirty = true;
}
void saveSnapshot() => _snapshot = map;
Grid<bool> loadSnapshot() => map = _snapshot;
}

View File

@ -5,6 +5,8 @@ import 'package:test/test.dart';
import 'package:rules_of_living/src/Simulation.dart';
class MockGrid extends Mock implements Grid<bool> {}
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));
});
});
}