Add KCenters algorithm (#5806)

This commit is contained in:
Hardik Pawar
2024-10-26 11:45:24 +05:30
committed by GitHub
parent e0ab1d357c
commit c40eb8dbac
3 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
package com.thealgorithms.greedyalgorithms;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class KCentersTest {
@Test
public void testFindKCenters() {
int[][] distances = {{0, 2, 3, 4}, {2, 0, 5, 1}, {3, 5, 0, 7}, {4, 1, 7, 0}};
assertEquals(4, KCenters.findKCenters(distances, 2));
assertEquals(2, KCenters.findKCenters(distances, 4));
}
}