Add Grid.fill constructor

Will completely fill the grid with the value passed in.
This commit is contained in:
Marty Oehme 2018-08-30 10:32:34 +02:00
parent eef7a23c8f
commit 2dc1d7fecd
2 changed files with 21 additions and 0 deletions

View file

@ -10,6 +10,9 @@ class Grid<E> extends DelegatingList<E> {
Grid(int width, int height) : this._(List<E>(width * height), width, height); Grid(int width, int height) : this._(List<E>(width * height), width, height);
Grid.fill(int width, int height, E fillValue)
: this._(List<E>.filled(width * height, fillValue), width, height);
Grid.from(Grid<E> l) Grid.from(Grid<E> l)
: this._(List<E>.from(l.getRange(0, l.length)), l.width, l.height); : this._(List<E>.from(l.getRange(0, l.length)), l.width, l.height);

View file

@ -73,6 +73,24 @@ void main() {
expect(sut.width, 3); expect(sut.width, 3);
}, tags: const ["happy"]); }, tags: const ["happy"]);
}); });
group(".fill", () {
test("fills list with results of function passed in", () {
Grid<String> sut = Grid.fill(3, 3, "testValue");
expect(
sut,
containsAllInOrder([
"testValue",
"testValue",
"testValue",
"testValue",
"testValue",
"testValue",
"testValue",
"testValue",
"testValue"
]));
}, tags: const ["happy"]);
});
}); });
group("toIndex", () { group("toIndex", () {
Grid sut; Grid sut;