2019-03-24 16:41:14 +01:00
|
|
|
package search.breadthfirstsearch;
|
|
|
|
|
|
|
|
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-03-24 16:58:10 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
void shouldReturnCorrectTargetChubekNode()
|
2019-03-25 19:14:17 +01:00
|
|
|
{
|
2019-03-27 19:59:28 +01:00
|
|
|
int[][] state = {
|
|
|
|
{2, 0, 4},
|
|
|
|
{6, 7, 1},
|
|
|
|
{8, 5, 3}
|
|
|
|
};
|
|
|
|
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);
|
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
|
|
|
}
|