2019-04-01 20:27:14 +02:00
|
|
|
package search.uninformed.breadthfirstsearch;
|
2019-03-24 16:41:14 +01:00
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
2019-03-27 19:59:28 +01:00
|
|
|
import search.EightPuzzleNode;
|
2019-03-24 16:41:14 +01:00
|
|
|
|
2019-03-24 16:58:10 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-03-27 19:59:28 +01:00
|
|
|
import static search.SearchTestUtils.printSolution;
|
|
|
|
|
2019-03-24 16:41:14 +01:00
|
|
|
class BreadthFirstSearchTest
|
|
|
|
{
|
|
|
|
@Test
|
|
|
|
void shouldReturnCorrectTarget()
|
|
|
|
{
|
2019-04-02 20:34:15 +02:00
|
|
|
final int[][] state = {
|
2019-03-24 17:25:51 +01:00
|
|
|
{5, 0, 3},
|
|
|
|
{2, 1, 6},
|
|
|
|
{4, 7, 8}
|
2019-03-24 16:58:10 +01:00
|
|
|
};
|
2019-04-02 20:34:15 +02:00
|
|
|
final var root = new EightPuzzleNode(state);
|
2019-03-24 16:58:10 +01:00
|
|
|
|
2019-04-02 20:34:15 +02:00
|
|
|
final int[][] targetState = {
|
2019-03-24 16:58:10 +01:00
|
|
|
{1, 2, 3},
|
|
|
|
{4, 5, 6},
|
|
|
|
{7, 8, 0}
|
|
|
|
};
|
2019-04-02 20:34:15 +02:00
|
|
|
final var expected = new EightPuzzleNode(targetState);
|
2019-03-24 16:58:10 +01:00
|
|
|
|
2019-04-02 20:34:15 +02:00
|
|
|
final var actual = new BreadthFirstSearch().breadthFirstSearch(List.of(root), expected);
|
2019-03-24 16:58:10 +01:00
|
|
|
|
2019-03-27 19:59:28 +01:00
|
|
|
printSolution(actual);
|
2019-03-24 16:41:14 +01:00
|
|
|
}
|
2019-03-25 19:14:17 +01:00
|
|
|
|
2019-03-27 19:59:28 +01:00
|
|
|
@Test
|
2019-04-01 20:27:14 +02:00
|
|
|
void shouldReturnCorrectTargetCubekNode()
|
2019-03-25 19:14:17 +01:00
|
|
|
{
|
2019-04-02 20:34:15 +02:00
|
|
|
final int[][] state = {
|
2019-03-27 19:59:28 +01:00
|
|
|
{2, 0, 4},
|
|
|
|
{6, 7, 1},
|
|
|
|
{8, 5, 3}
|
|
|
|
};
|
2019-04-02 20:34:15 +02:00
|
|
|
final var root = new EightPuzzleNode(state);
|
2019-03-27 19:59:28 +01:00
|
|
|
|
2019-04-02 20:34:15 +02:00
|
|
|
final int[][] targetState = {
|
2019-03-27 19:59:28 +01:00
|
|
|
{1, 2, 3},
|
|
|
|
{4, 5, 6},
|
|
|
|
{7, 8, 0}
|
|
|
|
};
|
2019-04-02 20:34:15 +02:00
|
|
|
final var expected = new EightPuzzleNode(targetState);
|
2019-03-27 19:59:28 +01:00
|
|
|
|
2019-04-02 20:34:15 +02:00
|
|
|
final var actual = new BreadthFirstSearch().breadthFirstSearch(List.of(root), expected);
|
2019-03-25 19:14:17 +01:00
|
|
|
|
2019-03-27 19:59:28 +01:00
|
|
|
printSolution(actual);
|
2019-03-25 19:14:17 +01:00
|
|
|
}
|
2019-03-24 16:41:14 +01:00
|
|
|
}
|