Add Save and Load Functions to SimService

This commit is contained in:
Unknown 2018-10-19 20:50:24 +02:00
parent 2ea974bbd5
commit 22dabda987
2 changed files with 29 additions and 2 deletions

View file

@ -9,9 +9,10 @@ class SimulationService {
static final int DEFAULT_GRID_SIZE = 50; static final int DEFAULT_GRID_SIZE = 50;
final EngineService _engine; final EngineService _engine;
final Simulation _sim = Simulation(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE); final Simulation _sim;
SimulationService(this._engine) { SimulationService(this._engine, [Simulation sim])
: this._sim = sim ?? Simulation(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE) {
_engine.simulation = _sim; _engine.simulation = _sim;
_sim.addRandomPattern(amount: 15, dispersal: 5); _sim.addRandomPattern(amount: 15, dispersal: 5);
} }
@ -36,4 +37,7 @@ class SimulationService {
void toggleGrid() { void toggleGrid() {
_sim.renderEdges = !_sim.renderEdges; _sim.renderEdges = !_sim.renderEdges;
} }
void save() => _sim.saveSnapshot();
void load() => _sim.loadSnapshot();
} }

View file

@ -0,0 +1,23 @@
import 'package:rules_of_living/service/engine_service.dart';
import 'package:rules_of_living/service/simulation_service.dart';
import 'package:rules_of_living/src/Simulation.dart';
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
class MockSimulation extends Mock implements Simulation {}
class MockEngineService extends Mock implements EngineService {}
void main() {
SimulationService sut;
MockSimulation mockSim = MockSimulation();
setUp(() => sut = SimulationService(MockEngineService(), mockSim));
test("calling save calls through to Simulation.saveSnapshot", () {
sut.save();
verify(mockSim.saveSnapshot());
});
test("calling load calls through to Simulation.loadSnapshot", () {
sut.load();
verify(mockSim.loadSnapshot());
});
}