diff --git a/lib/src/Grid.dart b/lib/src/Grid.dart index 40b87ea..e2a62fc 100644 --- a/lib/src/Grid.dart +++ b/lib/src/Grid.dart @@ -10,6 +10,9 @@ class Grid extends DelegatingList { Grid(int width, int height) : this._(List(width * height), width, height); + Grid.fill(int width, int height, E fillValue) + : this._(List.filled(width * height, fillValue), width, height); + Grid.from(Grid l) : this._(List.from(l.getRange(0, l.length)), l.width, l.height); diff --git a/test/src/grid_test.dart b/test/src/grid_test.dart index d6eae8f..fce1b3f 100644 --- a/test/src/grid_test.dart +++ b/test/src/grid_test.dart @@ -73,6 +73,24 @@ void main() { expect(sut.width, 3); }, tags: const ["happy"]); }); + group(".fill", () { + test("fills list with results of function passed in", () { + Grid sut = Grid.fill(3, 3, "testValue"); + expect( + sut, + containsAllInOrder([ + "testValue", + "testValue", + "testValue", + "testValue", + "testValue", + "testValue", + "testValue", + "testValue", + "testValue" + ])); + }, tags: const ["happy"]); + }); }); group("toIndex", () { Grid sut;