Allow Optional Injection of grid size into engine on creation
This commit is contained in:
parent
9886f13d69
commit
873bd9c881
3 changed files with 24 additions and 21 deletions
|
@ -46,8 +46,8 @@ class Engine {
|
||||||
Grid _grid;
|
Grid _grid;
|
||||||
bool running = false;
|
bool running = false;
|
||||||
|
|
||||||
Engine([this.canvas]) {
|
Engine([x = 100, y = 100, this.canvas]) {
|
||||||
_grid = Grid(gridSize.x, gridSize.y);
|
_grid = Grid(x, y);
|
||||||
|
|
||||||
_elapsed.start();
|
_elapsed.start();
|
||||||
_grid.addPattern(amount: 15, dispersal: 5);
|
_grid.addPattern(amount: 15, dispersal: 5);
|
||||||
|
@ -115,7 +115,7 @@ class Engine {
|
||||||
/// the internal engine processing. Does not do anything if no canvas is
|
/// the internal engine processing. Does not do anything if no canvas is
|
||||||
/// defined.
|
/// defined.
|
||||||
void render([num interp]) {
|
void render([num interp]) {
|
||||||
if(canvas != null) _grid.render(canvas, interp);
|
if (canvas != null) _grid.render(canvas, interp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPattern(
|
void addPattern(
|
||||||
|
|
|
@ -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')
|
@TestOn('browser')
|
||||||
import 'package:test/test.dart';
|
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 {}
|
class MockEngine extends Mock implements Engine {}
|
||||||
|
|
||||||
|
|
|
@ -10,23 +10,26 @@ void main() {
|
||||||
setUp(() {
|
setUp(() {
|
||||||
sut = Engine();
|
sut = Engine();
|
||||||
});
|
});
|
||||||
|
group("canvas", () {
|
||||||
|
test("Engine can be instantiated without canvas", () {
|
||||||
|
expect(sut, isNot(throwsNoSuchMethodError));
|
||||||
|
});
|
||||||
|
|
||||||
test("Engine can be instantiated without canvas", () {
|
test("Engine does not throw errors when calling render directly", () {
|
||||||
expect(sut, isNot(throwsNoSuchMethodError));
|
// anonymous function necessary since throws can not use functions with args
|
||||||
});
|
expect(() => sut.render, isNot(throwsNoSuchMethodError));
|
||||||
|
});
|
||||||
|
|
||||||
test("Engine does not throw errors when calling render directly", () {
|
test("Engine does not throw errors when processing without attached canvas",
|
||||||
// anonymous function necessary since throws can not use functions with args
|
() {
|
||||||
expect(() => sut.render, isNot(throwsNoSuchMethodError));
|
// anonymous function necessary since throws can not use functions with args
|
||||||
});
|
expect(() => sut.process, isNot(throwsNoSuchMethodError));
|
||||||
|
});
|
||||||
|
|
||||||
test("Engine does not throw errors when processing without attached canvas", () {
|
test("setCanvas allows setting a canvas for an engine at any point", () {
|
||||||
// anonymous function necessary since throws can not use functions with args
|
sut.canvas = new html.CanvasElement();
|
||||||
expect(() => sut.process, isNot(throwsNoSuchMethodError));
|
expect(sut.canvas, isNotNull);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("setCanvas allows setting a canvas for an engine at any point", () {
|
|
||||||
sut.canvas = new html.CanvasElement();
|
|
||||||
expect(sut.canvas, isNotNull);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue