mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-31 00:37:15 +08:00
@ -10,36 +10,30 @@ class HamiltonianCycleTest {
|
||||
|
||||
@Test
|
||||
void testFindHamiltonianCycleShouldReturnHamiltonianCycle() {
|
||||
int[] expectedArray = { 0, 1, 2, 4, 3, 0 };
|
||||
int[] expectedArray = {0, 1, 2, 4, 3, 0};
|
||||
int[][] inputArray = {
|
||||
{ 0, 1, 0, 1, 0 },
|
||||
{ 1, 0, 1, 1, 1 },
|
||||
{ 0, 1, 0, 0, 1 },
|
||||
{ 1, 1, 0, 0, 1 },
|
||||
{ 0, 1, 1, 1, 0 },
|
||||
{0, 1, 0, 1, 0},
|
||||
{1, 0, 1, 1, 1},
|
||||
{0, 1, 0, 0, 1},
|
||||
{1, 1, 0, 0, 1},
|
||||
{0, 1, 1, 1, 0},
|
||||
};
|
||||
|
||||
assertArrayEquals(
|
||||
expectedArray,
|
||||
hamiltonianCycle.findHamiltonianCycle(inputArray)
|
||||
);
|
||||
assertArrayEquals(expectedArray, hamiltonianCycle.findHamiltonianCycle(inputArray));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindHamiltonianCycleShouldReturnInfinityArray() {
|
||||
int[] expectedArray = { -1, -1, -1, -1, -1, -1 };
|
||||
int[] expectedArray = {-1, -1, -1, -1, -1, -1};
|
||||
|
||||
int[][] inputArray = {
|
||||
{ 0, 1, 0, 1, 0 },
|
||||
{ 1, 0, 1, 1, 1 },
|
||||
{ 0, 1, 0, 0, 1 },
|
||||
{ 1, 1, 0, 0, 0 },
|
||||
{ 0, 1, 1, 0, 0 },
|
||||
{0, 1, 0, 1, 0},
|
||||
{1, 0, 1, 1, 1},
|
||||
{0, 1, 0, 0, 1},
|
||||
{1, 1, 0, 0, 0},
|
||||
{0, 1, 1, 0, 0},
|
||||
};
|
||||
|
||||
assertArrayEquals(
|
||||
expectedArray,
|
||||
hamiltonianCycle.findHamiltonianCycle(inputArray)
|
||||
);
|
||||
assertArrayEquals(expectedArray, hamiltonianCycle.findHamiltonianCycle(inputArray));
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class KosarajuTest {
|
||||
@ -14,7 +13,7 @@ public class KosarajuTest {
|
||||
|
||||
@Test
|
||||
public void findStronglyConnectedComps() {
|
||||
//Create a adjacency list of graph
|
||||
// Create a adjacency list of graph
|
||||
var n = 8;
|
||||
var adjList = new ArrayList<List<Integer>>(n);
|
||||
|
||||
@ -36,10 +35,10 @@ public class KosarajuTest {
|
||||
List<List<Integer>> actualResult = kosaraju.kosaraju(n, adjList);
|
||||
List<List<Integer>> expectedResult = new ArrayList<>();
|
||||
/*
|
||||
Expected result:
|
||||
Expected result:
|
||||
0, 1, 2
|
||||
3
|
||||
5, 4, 6
|
||||
5, 4, 6
|
||||
7
|
||||
*/
|
||||
expectedResult.add(Arrays.asList(1, 2, 0));
|
||||
@ -51,7 +50,7 @@ public class KosarajuTest {
|
||||
|
||||
@Test
|
||||
public void findStronglyConnectedCompsShouldGetSingleNodes() {
|
||||
//Create a adjacency list of graph
|
||||
// Create a adjacency list of graph
|
||||
var n = 8;
|
||||
var adjList = new ArrayList<List<Integer>>(n);
|
||||
|
||||
@ -71,11 +70,10 @@ public class KosarajuTest {
|
||||
List<List<Integer>> actualResult = kosaraju.kosaraju(n, adjList);
|
||||
List<List<Integer>> expectedResult = new ArrayList<>();
|
||||
/*
|
||||
Expected result:
|
||||
Expected result:
|
||||
0, 1, 2, 3, 4, 5, 6, 7
|
||||
*/
|
||||
expectedResult.add(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 0));
|
||||
assertTrue(expectedResult.equals(actualResult));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,15 +5,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TarjansAlgorithmTest {
|
||||
|
||||
|
||||
TarjansAlgorithm tarjansAlgo = new TarjansAlgorithm();
|
||||
|
||||
@Test
|
||||
public void findStronglyConnectedComps(){
|
||||
public void findStronglyConnectedComps() {
|
||||
var v = 5;
|
||||
var graph = new ArrayList<List<Integer>>();
|
||||
for (int i = 0; i < v; i++) {
|
||||
@ -27,10 +26,10 @@ public class TarjansAlgorithmTest {
|
||||
|
||||
var actualResult = tarjansAlgo.stronglyConnectedComponents(v, graph);
|
||||
/*
|
||||
Expected result:
|
||||
Expected result:
|
||||
0, 1, 2
|
||||
3
|
||||
4
|
||||
4
|
||||
*/
|
||||
List<List<Integer>> expectedResult = new ArrayList<>();
|
||||
|
||||
@ -42,7 +41,7 @@ public class TarjansAlgorithmTest {
|
||||
|
||||
@Test
|
||||
public void findStronglyConnectedCompsShouldGetSingleNodes() {
|
||||
//Create a adjacency list of graph
|
||||
// Create a adjacency list of graph
|
||||
var n = 8;
|
||||
var adjList = new ArrayList<List<Integer>>(n);
|
||||
|
||||
@ -62,11 +61,10 @@ public class TarjansAlgorithmTest {
|
||||
List<List<Integer>> actualResult = tarjansAlgo.stronglyConnectedComponents(n, adjList);
|
||||
List<List<Integer>> expectedResult = new ArrayList<>();
|
||||
/*
|
||||
Expected result:
|
||||
Expected result:
|
||||
7, 6, 5, 4, 3, 2, 1, 0
|
||||
*/
|
||||
expectedResult.add(Arrays.asList(7, 6, 5, 4, 3, 2, 1, 0));
|
||||
assertTrue(expectedResult.equals(actualResult));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user