Add Save and Load Functions to SimService
This commit is contained in:
parent
2ea974bbd5
commit
22dabda987
2 changed files with 29 additions and 2 deletions
|
@ -9,9 +9,10 @@ class SimulationService {
|
|||
static final int DEFAULT_GRID_SIZE = 50;
|
||||
|
||||
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;
|
||||
_sim.addRandomPattern(amount: 15, dispersal: 5);
|
||||
}
|
||||
|
@ -36,4 +37,7 @@ class SimulationService {
|
|||
void toggleGrid() {
|
||||
_sim.renderEdges = !_sim.renderEdges;
|
||||
}
|
||||
|
||||
void save() => _sim.saveSnapshot();
|
||||
void load() => _sim.loadSnapshot();
|
||||
}
|
||||
|
|
23
test/service/simulation_service_test.dart
Normal file
23
test/service/simulation_service_test.dart
Normal 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());
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue