File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
main/kotlin/de/ronny_h/aoc/extensions/grids
test/kotlin/de/ronny_h/aoc/extensions/grids Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -76,9 +76,13 @@ abstract class Grid<T>(
7676 ? : fallbackElement
7777 }
7878
79+ operator fun set (row : Int , col : Int , value : T ) {
80+ grid[row][col] = value
81+ }
82+
7983 fun getAt (position : Coordinates ) = get(position.row, position.col)
8084 fun setAt (position : Coordinates , element : T ) {
81- grid [position.row][ position.col] = element
85+ this [position.row, position.col] = element
8286 }
8387
8488 /* *
Original file line number Diff line number Diff line change @@ -88,6 +88,15 @@ class GridTest : StringSpec() {
8888 grid[1 , 1 ] shouldBe ' 4'
8989 }
9090
91+ " set with array access sets the element at the given coordinates" {
92+ val grid = SimpleCharGrid (listOf (" 12" , " 34" ))
93+ grid[1 , 0 ] = ' 5'
94+ grid[0 , 0 ] shouldBe ' 1'
95+ grid[0 , 1 ] shouldBe ' 2'
96+ grid[1 , 0 ] shouldBe ' 5'
97+ grid[1 , 1 ] shouldBe ' 4'
98+ }
99+
91100 " subGridAt returns a sub grid at the given coordinates" {
92101 val input = """
93102 1234
You can’t perform that action at this time.
0 commit comments