Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 8df4b35

Browse files
committed
Expose RawMatrix in Matrix struct
1 parent 8f8c026 commit 8df4b35

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

common/util/matrix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
type Matrix[T any] struct {
9-
matrix [][]T
9+
RawMatrix [][]T
1010
MaxX int
1111
MaxY int
1212
}
@@ -41,7 +41,7 @@ func NewMatrixFromRows[T any](
4141
}
4242

4343
return Matrix[T]{
44-
matrix: matrix,
44+
RawMatrix: matrix,
4545
MaxX: maxX,
4646
MaxY: maxY,
4747
}, nil
@@ -76,7 +76,7 @@ func (m Matrix[T]) Get(
7676
var zeroValue T
7777
return zeroValue, fmt.Errorf("invalid point (%d,%d)", x, y)
7878
}
79-
return m.matrix[y][x], nil
79+
return m.RawMatrix[y][x], nil
8080
}
8181

8282
func (m Matrix[T]) GetOrDefault(
@@ -100,6 +100,6 @@ func (m Matrix[T]) Set(
100100
return fmt.Errorf("invalid point (%d,%d)", x, y)
101101
}
102102

103-
m.matrix[y][x] = value
103+
m.RawMatrix[y][x] = value
104104
return nil
105105
}

common/util/matrix_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ var rawMatrix = [][]Coordinate{
1717
{c(0, 4), c(1, 4), c(2, 4), c(3, 4)},
1818
}
1919
var matrix = Matrix[Coordinate]{
20-
matrix: rawMatrix,
21-
MaxX: 3,
22-
MaxY: 4,
20+
RawMatrix: rawMatrix,
21+
MaxX: 3,
22+
MaxY: 4,
2323
}
2424

2525
func TestNewMatrixFromRows(t *testing.T) {
@@ -38,7 +38,7 @@ func TestNewMatrixFromRows(t *testing.T) {
3838
t.Errorf("Expected MaxY=%d, but was %d", matrix.MaxY, testMatrix.MaxY)
3939
}
4040

41-
for y, tmRow := range testMatrix.matrix {
41+
for y, tmRow := range testMatrix.RawMatrix {
4242
for x, actual := range tmRow {
4343
expected := rawMatrix[y][x]
4444
if actual != expected {
@@ -57,7 +57,7 @@ func TestNewMatrixFromRows(t *testing.T) {
5757
t.Errorf("Expected error '%s' but got %v", errorMsg, err)
5858
}
5959

60-
if testMatrix.MaxX != 0 && testMatrix.MaxY != 0 && len(testMatrix.matrix) != 0 {
60+
if testMatrix.MaxX != 0 && testMatrix.MaxY != 0 && len(testMatrix.RawMatrix) != 0 {
6161
t.Errorf("Expected zero-matrix in response, but was %q", testMatrix)
6262
}
6363
})
@@ -71,7 +71,7 @@ func TestNewMatrixFromRows(t *testing.T) {
7171
t.Errorf("Expected error '%s' but got %v", errorMsg, err)
7272
}
7373

74-
if testMatrix.MaxX != 0 && testMatrix.MaxY != 0 && len(testMatrix.matrix) != 0 {
74+
if testMatrix.MaxX != 0 && testMatrix.MaxY != 0 && len(testMatrix.RawMatrix) != 0 {
7575
t.Errorf("Expected zero-matrix in response, but was %q", testMatrix)
7676
}
7777
})
@@ -99,7 +99,7 @@ func TestNewCharMatrix(t *testing.T) {
9999
t.Errorf("Expected MaxY=2, but was %d", testMatrix.MaxY)
100100
}
101101

102-
for y, tmRow := range testMatrix.matrix {
102+
for y, tmRow := range testMatrix.RawMatrix {
103103
for x, actual := range tmRow {
104104
expected := sl[y][x]
105105
if actual != expected {
@@ -118,7 +118,7 @@ func TestNewCharMatrix(t *testing.T) {
118118
t.Errorf("Expected error '%s' but got %v", errorMsg, err)
119119
}
120120

121-
if testMatrix.MaxX != 0 && testMatrix.MaxY != 0 && len(testMatrix.matrix) != 0 {
121+
if testMatrix.MaxX != 0 && testMatrix.MaxY != 0 && len(testMatrix.RawMatrix) != 0 {
122122
t.Errorf("Expected zero-matrix in response, but was %q", testMatrix)
123123
}
124124
})
@@ -132,7 +132,7 @@ func TestNewCharMatrix(t *testing.T) {
132132
t.Errorf("Expected error '%s' but got %v", errorMsg, err)
133133
}
134134

135-
if testMatrix.MaxX != 0 && testMatrix.MaxY != 0 && len(testMatrix.matrix) != 0 {
135+
if testMatrix.MaxX != 0 && testMatrix.MaxY != 0 && len(testMatrix.RawMatrix) != 0 {
136136
t.Errorf("Expected zero-matrix in response, but was %q", testMatrix)
137137
}
138138
})

0 commit comments

Comments
 (0)