55 lines
1.3 KiB
Java
Raw Permalink Normal View History

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