Skip to content

Commit 422b80d

Browse files
committed
refactor: ♻️ make dimensions a global constant for 3D tests
I have replaced the `dimensions` constant in every 3D test with a single global constant called `dimensions3DCount` to reduce code repetition. The suffix `3DCount` must be added to prevent clashes with future tests with different dimensions that would also require a similar global constant.
1 parent d86d7bd commit 422b80d

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

tests/kdtree_3d_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
types "github.com/rishitc/go-kd-tree/internal/types"
99
)
1010

11+
const dimensions3DCount = 3
12+
1113
func Test3DNearestNeighbor1(t *testing.T) {
12-
const dimensions = 3
1314
ps := []types.Tensor3D{
1415
{2, 3, 3},
1516
{5, 4, 2},
@@ -27,7 +28,7 @@ func Test3DNearestNeighbor1(t *testing.T) {
2728
{2, 1, 3},
2829
{8, 7, 6},
2930
}
30-
tree := kdtree.NewKDTreeWithValues(dimensions, ps)
31+
tree := kdtree.NewKDTreeWithValues(dimensions3DCount, ps)
3132
testTable := []struct {
3233
input, expected types.Tensor3D
3334
}{
@@ -45,7 +46,6 @@ func Test3DNearestNeighbor1(t *testing.T) {
4546
}
4647

4748
func Test3DNearestNeighbor2(t *testing.T) {
48-
const dimensions = 2
4949
ps := []types.Tensor3D{
5050
{5, 4},
5151
{3, 1},
@@ -54,7 +54,7 @@ func Test3DNearestNeighbor2(t *testing.T) {
5454
{10, 2},
5555
{13, 3},
5656
}
57-
tree := kdtree.NewKDTreeWithValues(dimensions, ps)
57+
tree := kdtree.NewKDTreeWithValues(dimensions3DCount, ps)
5858
testTable := []struct {
5959
input, expected types.Tensor3D
6060
}{
@@ -72,7 +72,6 @@ func Test3DNearestNeighbor2(t *testing.T) {
7272
}
7373

7474
func Test3DNearestNeighbor3(t *testing.T) {
75-
const dimensions = 2
7675
ps := []types.Tensor3D{
7776
{207, 313},
7877
{70, 721},
@@ -82,7 +81,7 @@ func Test3DNearestNeighbor3(t *testing.T) {
8281
{479, 449},
8382
{888, 585},
8483
}
85-
tree := kdtree.NewKDTreeWithValues(dimensions, ps)
84+
tree := kdtree.NewKDTreeWithValues(dimensions3DCount, ps)
8685
testTable := []struct {
8786
input, expected types.Tensor3D
8887
}{
@@ -100,7 +99,6 @@ func Test3DNearestNeighbor3(t *testing.T) {
10099
}
101100

102101
func Test3DNearestNeighbor4(t *testing.T) {
103-
const dimensions = 2
104102
ps := []types.Tensor3D{
105103
{272, 59},
106104
{259, 189},
@@ -123,7 +121,7 @@ func Test3DNearestNeighbor4(t *testing.T) {
123121
{662, 798},
124122
{879, 810},
125123
}
126-
tree := kdtree.NewKDTreeWithValues(dimensions, ps)
124+
tree := kdtree.NewKDTreeWithValues(dimensions3DCount, ps)
127125
testTable := []struct {
128126
input, expected types.Tensor3D
129127
}{

0 commit comments

Comments
 (0)