2018-10-19 17:35:09 +00:00
|
|
|
import 'dart:math';
|
2018-10-21 12:00:01 +00:00
|
|
|
|
2018-10-19 17:35:09 +00:00
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
import 'package:rules_of_living/src/Grid.dart';
|
|
|
|
import 'package:rules_of_living/src/Simulation.dart';
|
2018-10-21 12:00:01 +00:00
|
|
|
import 'package:test/test.dart';
|
2018-10-19 17:35:09 +00:00
|
|
|
|
2018-10-19 17:59:00 +00:00
|
|
|
class MockGrid extends Mock implements Grid<bool> {}
|
|
|
|
|
2018-10-19 17:35:09 +00:00
|
|
|
void main() {
|
|
|
|
Simulation sut;
|
|
|
|
setUp(() {
|
|
|
|
sut = Simulation(10, 10);
|
|
|
|
});
|
|
|
|
group("gridSize", () {
|
|
|
|
test(
|
|
|
|
"returns the width and height of the underlying grid",
|
|
|
|
() => expect(
|
|
|
|
sut.gridSize, equals(Point<int>(sut.map.width, sut.map.height))));
|
|
|
|
test("sets the underlying grid width and height", () {
|
|
|
|
sut.gridSize = Point(2, 3);
|
|
|
|
expect(sut.gridSize, equals(Point(2, 3)));
|
|
|
|
});
|
|
|
|
test("creates a new underlying grid on resizing", () {
|
|
|
|
var oldMap = sut.map;
|
|
|
|
sut.gridSize = Point(10, 10);
|
2018-10-21 09:07:46 +00:00
|
|
|
expect(sut.map, isNot(same(oldMap)));
|
2018-10-21 12:00:01 +00:00
|
|
|
}, tags: "nobrowser");
|
2018-10-19 17:35:09 +00:00
|
|
|
});
|
2018-10-21 09:38:57 +00:00
|
|
|
group("resetMap", () {
|
|
|
|
test("sets the internal map filled with 'false' ", () {
|
|
|
|
sut.map.set(1, 1, true);
|
2018-10-21 12:00:01 +00:00
|
|
|
sut.clearMap();
|
2018-10-21 09:38:57 +00:00
|
|
|
expect(sut.map, allOf(TypeMatcher<Grid>(), isNot(contains(true))));
|
2018-10-19 17:35:09 +00:00
|
|
|
});
|
|
|
|
test("sets the simulation to need re-rendering", () {
|
2018-10-21 09:38:57 +00:00
|
|
|
sut.dirty = false;
|
2018-10-21 12:00:01 +00:00
|
|
|
sut.clearMap();
|
2018-10-19 17:35:09 +00:00
|
|
|
expect(sut.dirty, true);
|
2018-10-21 09:38:57 +00:00
|
|
|
});
|
2018-10-21 12:00:01 +00:00
|
|
|
}, tags: "nobrowser");
|
2018-10-19 17:59:00 +00:00
|
|
|
group("save&load", () {
|
2018-10-19 18:49:59 +00:00
|
|
|
test(
|
|
|
|
"saves a copy of the map which does not change when the actual map changes",
|
|
|
|
() {
|
2018-10-19 17:59:00 +00:00
|
|
|
sut.saveSnapshot();
|
2018-10-19 18:49:59 +00:00
|
|
|
sut.mergeStateChanges({1: true, 2: true});
|
|
|
|
var snapshot = Grid.from(sut.map);
|
2018-10-19 17:59:00 +00:00
|
|
|
|
2018-10-19 18:49:59 +00:00
|
|
|
expect(sut.loadSnapshot(), isNot(equals(snapshot)));
|
2018-10-19 17:59:00 +00:00
|
|
|
});
|
2018-10-21 12:00:01 +00:00
|
|
|
}, tags: "nobrowser");
|
2018-10-23 18:21:02 +00:00
|
|
|
group("toggleCellState", () {
|
|
|
|
test("throws RangeError if outside the map bounds", () {
|
|
|
|
expect(() => sut.toggleCellState(10, 9), throwsRangeError);
|
|
|
|
}, tags: const ["nobrowser"]);
|
|
|
|
});
|
2018-10-19 17:35:09 +00:00
|
|
|
}
|