Add Simulation Saving and Loading Methods
This commit is contained in:
parent
befb345ddd
commit
0da2d08b74
2 changed files with 16 additions and 0 deletions
|
@ -10,6 +10,8 @@ enum CellPattern { SpaceShip, Blinker }
|
||||||
|
|
||||||
class Simulation {
|
class Simulation {
|
||||||
Grid<bool> map;
|
Grid<bool> map;
|
||||||
|
Grid<bool> _snapshot;
|
||||||
|
|
||||||
RuleSet rules = GameOfLife();
|
RuleSet rules = GameOfLife();
|
||||||
|
|
||||||
bool _dirty = true;
|
bool _dirty = true;
|
||||||
|
@ -151,4 +153,7 @@ class Simulation {
|
||||||
_renderEdges = on;
|
_renderEdges = on;
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void saveSnapshot() => _snapshot = map;
|
||||||
|
Grid<bool> loadSnapshot() => map = _snapshot;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import 'package:test/test.dart';
|
||||||
|
|
||||||
import 'package:rules_of_living/src/Simulation.dart';
|
import 'package:rules_of_living/src/Simulation.dart';
|
||||||
|
|
||||||
|
class MockGrid extends Mock implements Grid<bool> {}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
Simulation sut;
|
Simulation sut;
|
||||||
setUp(() {
|
setUp(() {
|
||||||
|
@ -34,4 +36,13 @@ void main() {
|
||||||
expect(sut.dirty, true);
|
expect(sut.dirty, true);
|
||||||
}, skip: "can not find a way to set dirty to true first yet");
|
}, 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));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue