Skip to content

Commit e0d8f16

Browse files
authored
Add files via upload
1 parent 0158fb7 commit e0d8f16

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.thealgorithms.backtracking;
2+
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
4+
import java.util.ArrayList;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class AStarSearchTest {
11+
12+
@Test
13+
void testSimpleAStar() {
14+
AStarSearch aStar = new AStarSearch();
15+
16+
List<List<AStarSearch.Edge>> graph = new ArrayList<>();
17+
for (int i = 0; i < 6; i++) {
18+
graph.add(new ArrayList<>());
19+
}
20+
21+
graph.get(0).add(new AStarSearch.Edge(1, 1.0));
22+
graph.get(1).add(new AStarSearch.Edge(2, 1.0));
23+
graph.get(2).add(new AStarSearch.Edge(3, 1.0));
24+
graph.get(3).add(new AStarSearch.Edge(4, 1.0));
25+
graph.get(4).add(new AStarSearch.Edge(5, 1.0));
26+
27+
Map<Integer, int[]> coordinates = new HashMap<>();
28+
coordinates.put(0, new int[]{0, 0});
29+
coordinates.put(1, new int[]{1, 1});
30+
coordinates.put(2, new int[]{2, 2});
31+
coordinates.put(3, new int[]{3, 3});
32+
coordinates.put(4, new int[]{4, 4});
33+
coordinates.put(5, new int[]{5, 5});
34+
35+
List<Integer> path = aStar.aStar(graph, new int[]{0, 0}, new int[]{5, 5}, coordinates);
36+
37+
assertEquals(Arrays.asList(0, 1, 2, 3, 4, 5), path);
38+
}
39+
}

0 commit comments

Comments
 (0)