Skip to content

Commit 37d77ef

Browse files
committed
Apply clang-format formatting
1 parent a8c385d commit 37d77ef

1 file changed

Lines changed: 36 additions & 52 deletions

File tree

src/test/java/com/thealgorithms/machinelearning/KNearestNeighborsTest.java

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class KNearestNeighborsTest {
1111
@Test
1212
void predictsCorrectClassOnSeparableDataset() {
1313
double[][] features = {
14-
{0, 0},
15-
{1, 1},
16-
{8, 8},
17-
{9, 9},
14+
{0, 0},
15+
{1, 1},
16+
{8, 8},
17+
{9, 9},
1818
};
1919

2020
int[] labels = {0, 0, 1, 1};
@@ -29,10 +29,10 @@ void predictsCorrectClassOnSeparableDataset() {
2929
@Test
3030
void predictsBatchClassesOnSeparableDataset() {
3131
double[][] features = {
32-
{0, 0},
33-
{1, 1},
34-
{8, 8},
35-
{9, 9},
32+
{0, 0},
33+
{1, 1},
34+
{8, 8},
35+
{9, 9},
3636
};
3737

3838
int[] labels = {0, 0, 1, 1};
@@ -55,10 +55,10 @@ void throwsExceptionWhenKIsNotPositive() {
5555
@Test
5656
void throwsExceptionWhenKIsGreaterThanNumberOfTrainingSamples() {
5757
double[][] features = {
58-
{0, 0},
59-
{1, 1},
60-
{8, 8},
61-
{9, 9},
58+
{0, 0},
59+
{1, 1},
60+
{8, 8},
61+
{9, 9},
6262
};
6363

6464
int[] labels = {0, 0, 1, 1};
@@ -93,23 +93,21 @@ void nullLabelsArrayThrowsIllegalArgumentException() {
9393
void emptyLabelsArrayThrowsIllegalArgumentException() {
9494
KNearestNeighbors knn = new KNearestNeighbors(1);
9595

96-
assertThrows(IllegalArgumentException.class,
97-
() -> knn.fit(new double[][] {{1, 1}, {2, 2}}, new int[] {}));
96+
assertThrows(IllegalArgumentException.class, () -> knn.fit(new double[][] {{1, 1}, {2, 2}}, new int[] {}));
9897
}
9998

10099
@Test
101100
void mismatchedFeatureAndLabelLengthsThrowsIllegalArgumentException() {
102101
KNearestNeighbors knn = new KNearestNeighbors(3);
103102

104-
assertThrows(IllegalArgumentException.class,
105-
() -> knn.fit(new double[][] {{0, 0}, {1, 1}, {8, 8}, {9, 9}}, new int[] {0, 0, 1}));
103+
assertThrows(IllegalArgumentException.class, () -> knn.fit(new double[][] {{0, 0}, {1, 1}, {8, 8}, {9, 9}}, new int[] {0, 0, 1}));
106104
}
107105

108106
@Test
109107
void firstFeatureVectorNullThrowsIllegalArgumentException() {
110108
KNearestNeighbors knn = new KNearestNeighbors(1);
111109

112-
assertThrows(IllegalArgumentException.class,() -> knn.fit(new double[][] {null, {1, 1}}, new int[] {0, 1}));
110+
assertThrows(IllegalArgumentException.class, () -> knn.fit(new double[][] {null, {1, 1}}, new int[] {0, 1}));
113111
}
114112

115113
@Test
@@ -123,16 +121,14 @@ void emptyFeatureVectorThrowsIllegalArgumentException() {
123121
void nullFeatureSampleThrowsIllegalArgumentException() {
124122
KNearestNeighbors knn = new KNearestNeighbors(2);
125123

126-
assertThrows(IllegalArgumentException.class,
127-
() -> knn.fit(new double[][] {{0, 0}, null, {8, 8}}, new int[] {0, 0, 1}));
124+
assertThrows(IllegalArgumentException.class, () -> knn.fit(new double[][] {{0, 0}, null, {8, 8}}, new int[] {0, 0, 1}));
128125
}
129126

130127
@Test
131128
void mismatchedDimensionThrowsIllegalArgumentException() {
132129
KNearestNeighbors knn = new KNearestNeighbors(2);
133130

134-
assertThrows(IllegalArgumentException.class,
135-
() -> knn.fit(new double[][] {{0, 0}, {1, 1, 2}, {8, 8}}, new int[] {0, 0, 1}));
131+
assertThrows(IllegalArgumentException.class, () -> knn.fit(new double[][] {{0, 0}, {1, 1, 2}, {8, 8}}, new int[] {0, 0, 1}));
136132
}
137133

138134
@Test
@@ -145,10 +141,10 @@ void predictBeforeFitThrowsIllegalStateException() {
145141
@Test
146142
void nullTestPointThrowsIllegalArgumentException() {
147143
double[][] features = {
148-
{0, 0},
149-
{1, 1},
150-
{8, 8},
151-
{9, 9},
144+
{0, 0},
145+
{1, 1},
146+
{8, 8},
147+
{9, 9},
152148
};
153149

154150
int[] labels = {0, 0, 1, 1};
@@ -163,10 +159,10 @@ void nullTestPointThrowsIllegalArgumentException() {
163159
@Test
164160
void mismatchedTestPointLengthThrowsIllegalArgumentException() {
165161
double[][] features = {
166-
{0, 0},
167-
{1, 1},
168-
{8, 8},
169-
{9, 9},
162+
{0, 0},
163+
{1, 1},
164+
{8, 8},
165+
{9, 9},
170166
};
171167

172168
int[] labels = {0, 0, 1, 1};
@@ -179,12 +175,7 @@ void mismatchedTestPointLengthThrowsIllegalArgumentException() {
179175

180176
@Test
181177
void tieBreakReturnsSmallerLabel() {
182-
double[][] features = {
183-
{0, 0},
184-
{0, 2},
185-
{2, 0},
186-
{2, 2}
187-
};
178+
double[][] features = {{0, 0}, {0, 2}, {2, 0}, {2, 2}};
188179

189180
int[] labels = {0, 1, 0, 1};
190181

@@ -196,12 +187,7 @@ void tieBreakReturnsSmallerLabel() {
196187

197188
@Test
198189
void tieBreakKeepsCurrentWinnerWhenLabelIsGreater() {
199-
double[][] features = {
200-
{0, 0},
201-
{0, 2},
202-
{2, 0},
203-
{2, 2}
204-
};
190+
double[][] features = {{0, 0}, {0, 2}, {2, 0}, {2, 2}};
205191

206192
int[] labels = {1, 0, 1, 0};
207193

@@ -214,10 +200,10 @@ void tieBreakKeepsCurrentWinnerWhenLabelIsGreater() {
214200
@Test
215201
void nullBatchSampleThrowsIllegalArgumentException() {
216202
double[][] features = {
217-
{0, 0},
218-
{1, 1},
219-
{8, 8},
220-
{9, 9},
203+
{0, 0},
204+
{1, 1},
205+
{8, 8},
206+
{9, 9},
221207
};
222208

223209
int[] labels = {0, 0, 1, 1};
@@ -231,19 +217,17 @@ void nullBatchSampleThrowsIllegalArgumentException() {
231217
@Test
232218
void invalidBatchSampleThrowsIllegalArgumentException() {
233219
double[][] features = {
234-
{0, 0},
235-
{1, 1},
236-
{8, 8},
237-
{9, 9},
220+
{0, 0},
221+
{1, 1},
222+
{8, 8},
223+
{9, 9},
238224
};
239225

240226
int[] labels = {0, 0, 1, 1};
241227

242228
KNearestNeighbors knn = new KNearestNeighbors(3);
243229
knn.fit(features, labels);
244230

245-
assertThrows(IllegalArgumentException.class,
246-
() -> knn.predict(new double[][] {{1.5, 1.5}, {8.5, 8.5, 8.5}}));
231+
assertThrows(IllegalArgumentException.class, () -> knn.predict(new double[][] {{1.5, 1.5}, {8.5, 8.5, 8.5}}));
247232
}
248-
249233
}

0 commit comments

Comments
 (0)