Commit
This commit is contained in:
parent
d2c1cb698c
commit
237782d518
@ -1,6 +1,7 @@
|
|||||||
package search.breadthfirstsearch;
|
package search.breadthfirstsearch;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BreadthFirstSearch
|
public class BreadthFirstSearch
|
||||||
@ -19,7 +20,7 @@ public class BreadthFirstSearch
|
|||||||
newNodes.addAll(node.generateSuccessors());
|
newNodes.addAll(node.generateSuccessors());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newNodes.isEmpty())
|
if (!newNodes.isEmpty())
|
||||||
{
|
{
|
||||||
return breadthFirstSearch(newNodes, target);
|
return breadthFirstSearch(newNodes, target);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@ package search.breadthfirstsearch;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class BreadthFirstSearchTest
|
class BreadthFirstSearchTest
|
||||||
@ -9,6 +12,28 @@ class BreadthFirstSearchTest
|
|||||||
@Test
|
@Test
|
||||||
void shouldReturnCorrectTarget()
|
void shouldReturnCorrectTarget()
|
||||||
{
|
{
|
||||||
|
int[][] state = {
|
||||||
|
{1, 2, 3},
|
||||||
|
{4, 5, 6},
|
||||||
|
{7, 0, 8}
|
||||||
|
};
|
||||||
|
var root = new EightPuzzleNode(state);
|
||||||
|
|
||||||
|
|
||||||
|
int[][] targetState = {
|
||||||
|
{1, 2, 3},
|
||||||
|
{4, 5, 6},
|
||||||
|
{7, 8, 0}
|
||||||
|
};
|
||||||
|
var expected = new EightPuzzleNode(targetState);
|
||||||
|
|
||||||
|
var actual = new BreadthFirstSearch().breadthFirstSearch(List.of(root), expected);
|
||||||
|
|
||||||
|
var a = ((EightPuzzleNode) actual).getState();
|
||||||
|
|
||||||
|
for (int[] b : a)
|
||||||
|
{
|
||||||
|
System.out.println(Arrays.toString(b));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user