Error out on bad gridsize input
This commit is contained in:
parent
873bd9c881
commit
04d61bfa02
2 changed files with 14 additions and 2 deletions
|
@ -32,7 +32,12 @@ class Engine {
|
||||||
/// Grid Size
|
/// Grid Size
|
||||||
///
|
///
|
||||||
/// Number of cells on x coordinate and y coordinate. Can be set individually.
|
/// Number of cells on x coordinate and y coordinate. Can be set individually.
|
||||||
Point gridSize = Point<int>(100, 100);
|
Point get gridSize => Point<int>(_grid.w, _grid.h);
|
||||||
|
void set gridSize(Point<int> 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 _updateLag = 0.0;
|
||||||
num _drawLag = 0.0;
|
num _drawLag = 0.0;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'dart:html' as html;
|
import 'dart:html' as html;
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
@TestOn('browser')
|
@TestOn('browser')
|
||||||
|
|
||||||
import 'package:rules_of_living/src/Engine.dart';
|
import 'package:rules_of_living/src/Engine.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
@ -31,5 +31,12 @@ void main() {
|
||||||
expect(sut.canvas, isNotNull);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue