diff --git a/lib/src/Engine.dart b/lib/src/Engine.dart index aa2a36c..b06e53a 100644 --- a/lib/src/Engine.dart +++ b/lib/src/Engine.dart @@ -32,7 +32,12 @@ class Engine { /// Grid Size /// /// Number of cells on x coordinate and y coordinate. Can be set individually. - Point gridSize = Point(100, 100); + Point get gridSize => Point(_grid.w, _grid.h); + void set gridSize(Point value) { + if (value.x <= 0 || value.y <= 0) + throw ArgumentError("grid size must not be smaller than 1"); + _grid = Grid(value.x, value.y); + } num _updateLag = 0.0; num _drawLag = 0.0; diff --git a/test/src/engine_test.dart b/test/src/engine_test.dart index 7707418..fcfefc2 100644 --- a/test/src/engine_test.dart +++ b/test/src/engine_test.dart @@ -1,7 +1,7 @@ import 'dart:html' as html; +import 'dart:math'; @TestOn('browser') - import 'package:rules_of_living/src/Engine.dart'; import 'package:test/test.dart'; @@ -31,5 +31,12 @@ void main() { expect(sut.canvas, isNotNull); }); }); + group("gridSize", () { + test("zero gridSizes throw ArgumentErrors", () { + expect(() => sut.gridSize = Point(0, 5), throwsArgumentError); + }); + test("negative gridSizes throw ArgumentErrors", () { + expect(() => sut.gridSize = Point(1, -5), throwsArgumentError); + }); }); }