22
33import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
44import static org .junit .jupiter .api .Assertions .assertThrows ;
5-
65import org .junit .jupiter .api .Test ;
76
87class KMeansTest {
@@ -123,7 +122,7 @@ void testEmptyClusterHandling() {
123122
124123 int [] result = KMeans .cluster (points , centroids , 100 , 0.0001 );
125124
126- assertArrayEquals (new int [] {0 , 0 , 0 }, result );
125+ assertArrayEquals (new int []{0 , 0 , 0 }, result );
127126 }
128127
129128 @ Test
@@ -136,4 +135,54 @@ void testImmediateConvergence() {
136135
137136 assertArrayEquals (expected , KMeans .cluster (points , centroids , 100 , 0.000001 ));
138137 }
138+
139+ @ Test
140+ void testFirstPointNull () {
141+ double [][] points = {
142+ null
143+ };
144+
145+ double [][] centroids = {
146+ {1.0 , 1.0 }
147+ };
148+
149+ assertThrows (
150+ IllegalArgumentException .class ,
151+ () -> KMeans .cluster (points , centroids , 100 , 0.0001 )
152+ );
153+ }
154+
155+ @ Test
156+ void testNullPointInDataset () {
157+ double [][] points = {
158+ {1.0 , 1.0 },
159+ null
160+ };
161+
162+ double [][] centroids = {
163+ {1.0 , 1.0 }
164+ };
165+
166+ assertThrows (
167+ IllegalArgumentException .class ,
168+ () -> KMeans .cluster (points , centroids , 100 , 0.0001 )
169+ );
170+ }
171+
172+ @ Test
173+ void testNullCentroidRow () {
174+ double [][] points = {
175+ {1.0 , 1.0 }
176+ };
177+
178+ double [][] centroids = {
179+ null
180+ };
181+
182+ assertThrows (
183+ IllegalArgumentException .class ,
184+ () -> KMeans .cluster (points , centroids , 100 , 0.0001 )
185+ );
186+ }
187+
139188}
0 commit comments