2019-04-01 20:27:14 +02:00
|
|
|
package search.uninformed.iterativedeepening;
|
2019-03-27 20:38:47 +01:00
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import search.EightPuzzleNode;
|
2021-04-13 17:28:23 +02:00
|
|
|
import search.LabyrinthineNode;
|
2019-03-27 20:38:47 +01:00
|
|
|
|
|
|
|
import static search.SearchTestUtils.printSolution;
|
|
|
|
|
|
|
|
class IterativeDeepeningTest
|
|
|
|
{
|
|
|
|
@Test
|
2021-04-13 17:28:23 +02:00
|
|
|
void shouldReturnCorrectTargetEightPuzzle()
|
2019-03-27 20:38:47 +01:00
|
|
|
{
|
2019-04-02 20:34:15 +02:00
|
|
|
final int[][] state = {
|
2019-03-27 20:38:47 +01:00
|
|
|
{5, 0, 3},
|
|
|
|
{2, 1, 6},
|
|
|
|
{4, 7, 8}
|
|
|
|
};
|
2019-04-02 20:34:15 +02:00
|
|
|
final var root = new EightPuzzleNode(state);
|
2019-03-27 20:38:47 +01:00
|
|
|
|
2019-04-02 20:34:15 +02:00
|
|
|
final int[][] targetState = {
|
2019-03-27 20:38:47 +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 20:38:47 +01:00
|
|
|
|
2019-04-02 20:34:15 +02:00
|
|
|
final var actual = new IterativeDeepening().iterativeDeepening(root, expected);
|
2019-03-27 20:38:47 +01:00
|
|
|
|
|
|
|
printSolution(actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-04-13 17:28:23 +02:00
|
|
|
void shouldReturnCorrectTargetCubekNodeEightPuzzle()
|
2019-03-27 20:38:47 +01:00
|
|
|
{
|
2019-04-02 20:34:15 +02:00
|
|
|
final int[][] state = {
|
2019-03-27 20:38:47 +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 20:38:47 +01:00
|
|
|
|
2019-04-02 20:34:15 +02:00
|
|
|
final int[][] targetState = {
|
2019-03-27 20:38:47 +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 20:38:47 +01:00
|
|
|
|
2019-04-02 20:34:15 +02:00
|
|
|
final var actual = new IterativeDeepening().iterativeDeepening(root, expected);
|
2019-03-27 20:38:47 +01:00
|
|
|
|
|
|
|
printSolution(actual);
|
|
|
|
}
|
|
|
|
}
|