2018-08-29 20:12:19 +00:00
|
|
|
import 'package:rules_of_living/src/Grid.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
@Tags(const ["nobrowser"])
|
|
|
|
void main() {
|
|
|
|
group("Instantiation", () {
|
|
|
|
List<String> l;
|
|
|
|
setUp(() {
|
|
|
|
l = [
|
|
|
|
"Hey",
|
|
|
|
"you",
|
|
|
|
"me",
|
|
|
|
"together",
|
|
|
|
"Hello",
|
|
|
|
"World",
|
|
|
|
"I",
|
|
|
|
"am",
|
|
|
|
"ready."
|
|
|
|
];
|
|
|
|
});
|
|
|
|
test("gets created with the correct length for given quadratic gridsize",
|
|
|
|
() {
|
|
|
|
Grid sut = Grid(3, 3);
|
|
|
|
expect(sut.length, 9);
|
2018-08-30 07:36:57 +00:00
|
|
|
}, tags: const ["happy"]);
|
2018-08-29 20:12:19 +00:00
|
|
|
test("gets created with the correct length for given rectangular gridsize",
|
|
|
|
() {
|
|
|
|
Grid sut = Grid(87, 85);
|
|
|
|
expect(sut.length, 7395);
|
2018-08-30 07:36:57 +00:00
|
|
|
}, tags: const ["happy"]);
|
2018-08-29 20:12:19 +00:00
|
|
|
test("copies the content of another grid on .from Constructor call", () {
|
|
|
|
Grid original = Grid(2, 2);
|
|
|
|
original[0] = "Hey";
|
|
|
|
original[1] = "you";
|
|
|
|
original[2] = "me";
|
|
|
|
original[3] = "together";
|
|
|
|
|
|
|
|
Grid sut = Grid.from(original);
|
|
|
|
expect(sut, containsAllInOrder(["Hey", "you", "me", "together"]));
|
2018-08-30 07:36:57 +00:00
|
|
|
}, tags: const ["happy"]);
|
2018-08-29 20:12:19 +00:00
|
|
|
test("copies the length of another grid on .from Constructor call", () {
|
|
|
|
Grid original = Grid(2, 2);
|
|
|
|
original[0] = "Hey";
|
|
|
|
original[1] = "you";
|
|
|
|
original[2] = "me";
|
|
|
|
original[3] = "together";
|
|
|
|
|
|
|
|
Grid sut = Grid.from(original);
|
|
|
|
expect(sut.length, 4);
|
2018-08-30 07:36:57 +00:00
|
|
|
}, tags: const ["happy"]);
|
2018-08-29 20:12:19 +00:00
|
|
|
test("sets the length for list passed in on .fromList Constructor call",
|
|
|
|
() {
|
|
|
|
Grid sut = Grid.fromList(l, 3);
|
|
|
|
|
|
|
|
expect(sut.length, 9);
|
2018-08-30 07:36:57 +00:00
|
|
|
}, tags: const ["happy"]);
|
2018-08-29 20:12:19 +00:00
|
|
|
test("sets the contents of list passed in on .fromList Constructor call",
|
|
|
|
() {
|
|
|
|
Grid sut = Grid.fromList(l, 3);
|
|
|
|
|
|
|
|
expect(sut[3], "together");
|
2018-08-30 07:36:57 +00:00
|
|
|
}, tags: const ["happy"]);
|
2018-08-29 20:12:19 +00:00
|
|
|
test(
|
|
|
|
"sets the correct height for list passed in on .fromList Constructor call",
|
|
|
|
() {
|
|
|
|
Grid sut = Grid.fromList(l, 3);
|
|
|
|
|
|
|
|
expect(sut.width, 3);
|
2018-08-30 07:36:57 +00:00
|
|
|
}, tags: const ["happy"]);
|
2018-08-29 20:12:19 +00:00
|
|
|
});
|
2018-08-30 07:41:43 +00:00
|
|
|
group("toIndex", () {
|
|
|
|
Grid sut;
|
2018-08-29 20:12:19 +00:00
|
|
|
setUp(() {
|
|
|
|
sut = Grid(3, 3);
|
|
|
|
});
|
2018-08-30 07:41:43 +00:00
|
|
|
test("throws RangeError on negative x argument", () {
|
|
|
|
expect(() => sut.toIndex(-1, 2), throwsA(isRangeError));
|
|
|
|
}, tags: const ["bad"]);
|
|
|
|
test("throws RangeError on negative y argument", () {
|
|
|
|
expect(() => sut.toIndex(2, -1), throwsA(isRangeError));
|
|
|
|
}, tags: const ["bad"]);
|
|
|
|
test("calculates correct index for first element", () {
|
|
|
|
expect(sut.toIndex(0, 0), equals(0));
|
|
|
|
}, tags: const ["happy"]);
|
|
|
|
test("calculates correct index for last element", () {
|
|
|
|
expect(sut.toIndex(2, 2), equals(8));
|
|
|
|
}, tags: const ["happy"]);
|
|
|
|
test("calculates correct index for element on first row", () {
|
|
|
|
expect(sut.toIndex(2, 0), equals(2));
|
|
|
|
}, tags: const ["happy"]);
|
|
|
|
test("calculates correct index for example element", () {
|
|
|
|
expect(sut.toIndex(1, 1), equals(4));
|
|
|
|
}, tags: const ["happy"]);
|
|
|
|
});
|
2018-08-29 20:12:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|