Allow Optional Injection of grid size into engine on creation

This commit is contained in:
Marty Oehme 2018-08-27 20:13:19 +02:00
parent 9886f13d69
commit 873bd9c881
3 changed files with 24 additions and 21 deletions

View file

@ -46,8 +46,8 @@ class Engine {
Grid _grid;
bool running = false;
Engine([this.canvas]) {
_grid = Grid(gridSize.x, gridSize.y);
Engine([x = 100, y = 100, this.canvas]) {
_grid = Grid(x, y);
_elapsed.start();
_grid.addPattern(amount: 15, dispersal: 5);

View file

@ -1,8 +1,8 @@
import 'package:mockito/mockito.dart';
import 'package:rules_of_living/service/engine_service.dart';
import 'package:rules_of_living/src/Engine.dart';
@TestOn('browser')
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
import 'package:rules_of_living/src/Engine.dart';
import 'package:rules_of_living/service/engine_service.dart';
class MockEngine extends Mock implements Engine {}

View file

@ -10,7 +10,7 @@ void main() {
setUp(() {
sut = Engine();
});
group("canvas", () {
test("Engine can be instantiated without canvas", () {
expect(sut, isNot(throwsNoSuchMethodError));
});
@ -20,7 +20,8 @@ void main() {
expect(() => sut.render, isNot(throwsNoSuchMethodError));
});
test("Engine does not throw errors when processing without attached canvas", () {
test("Engine does not throw errors when processing without attached canvas",
() {
// anonymous function necessary since throws can not use functions with args
expect(() => sut.process, isNot(throwsNoSuchMethodError));
});
@ -29,4 +30,6 @@ void main() {
sut.canvas = new html.CanvasElement();
expect(sut.canvas, isNotNull);
});
});
});
}