From 873bd9c8814b8105b50611d00bc389d09e65b924 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 27 Aug 2018 20:13:19 +0200 Subject: [PATCH] Allow Optional Injection of grid size into engine on creation --- lib/src/Engine.dart | 6 ++--- test/service/engine_service_test.dart | 6 ++--- test/src/engine_test.dart | 33 +++++++++++++++------------ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/src/Engine.dart b/lib/src/Engine.dart index b05f79c..aa2a36c 100644 --- a/lib/src/Engine.dart +++ b/lib/src/Engine.dart @@ -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); @@ -115,7 +115,7 @@ class Engine { /// the internal engine processing. Does not do anything if no canvas is /// defined. void render([num interp]) { - if(canvas != null) _grid.render(canvas, interp); + if (canvas != null) _grid.render(canvas, interp); } void addPattern( diff --git a/test/service/engine_service_test.dart b/test/service/engine_service_test.dart index 209fd47..cbd9655 100644 --- a/test/service/engine_service_test.dart +++ b/test/service/engine_service_test.dart @@ -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 {} diff --git a/test/src/engine_test.dart b/test/src/engine_test.dart index 43ea13e..7707418 100644 --- a/test/src/engine_test.dart +++ b/test/src/engine_test.dart @@ -10,23 +10,26 @@ void main() { setUp(() { sut = Engine(); }); + group("canvas", () { + test("Engine can be instantiated without canvas", () { + expect(sut, isNot(throwsNoSuchMethodError)); + }); - test("Engine can be instantiated without canvas", () { - expect(sut, isNot(throwsNoSuchMethodError)); - }); + test("Engine does not throw errors when calling render directly", () { + // 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", () { - // anonymous function necessary since throws can not use functions with args - expect(() => sut.render, isNot(throwsNoSuchMethodError)); - }); + 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)); + }); - 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)); + test("setCanvas allows setting a canvas for an engine at any point", () { + sut.canvas = new html.CanvasElement(); + 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); }); -} \ No newline at end of file +}