Made all variables and parameter final where available

This commit is contained in:
Niklas Birk
2019-04-02 20:34:15 +02:00
parent 4a0b04aefe
commit d4e54493c7
13 changed files with 95 additions and 117 deletions

View File

@ -9,7 +9,7 @@ class EightPuzzleNodeTest
@Test
public void shouldThrowExceptionWhileStateHasDuplicateNumbers()
{
int[][] state = {
final int[][] state = {
{1, 1, 3},
{4, 5, 6},
{7, 8, 0}
@ -21,7 +21,7 @@ class EightPuzzleNodeTest
@Test
public void shouldThrowExceptionWhileStateHasNumbersOutOfRange()
{
int[][] state = {
final int[][] state = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
@ -33,14 +33,14 @@ class EightPuzzleNodeTest
@Test
public void shouldReturnTrueWhenTargetReached()
{
int[][] state = {
final int[][] state = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}
};
var node = new EightPuzzleNode(state);
var target = new EightPuzzleNode(state);
final var node = new EightPuzzleNode(state);
final var target = new EightPuzzleNode(state);
Assertions.assertTrue(node.isTargetReached(target));
}
@ -48,20 +48,20 @@ class EightPuzzleNodeTest
@Test
public void shouldReturnFalseWhenTargetNotReached()
{
int[][] actualState = {
final int[][] actualState = {
{7, 1, 6},
{0, 4, 2},
{3, 5, 8}
};
int[][] targetState = {
final int[][] targetState = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}
};
var node = new EightPuzzleNode(actualState);
var target = new EightPuzzleNode(targetState);
final var node = new EightPuzzleNode(actualState);
final var target = new EightPuzzleNode(targetState);
Assertions.assertFalse(node.isTargetReached(target));
}
@ -69,50 +69,45 @@ class EightPuzzleNodeTest
@Test
public void shouldReturnNonEmptyListOfSuccessors()
{
int[][] state = {
final int[][] state = {
{7, 1, 6},
{0, 4, 2},
{3, 5, 8}
};
var node = new EightPuzzleNode(state);
var successors = node.generateSuccessors();
final var node = new EightPuzzleNode(state);
final var successors = node.generateSuccessors();
Assertions.assertFalse(successors.isEmpty());
}
@Test
public void shouldReturnEmptyListOfSuccessors()
{
}
@Test
public void shouldReturnCorrectSuccessors()
{
int[][] state = {
final int[][] state = {
{7, 1, 6},
{0, 4, 2},
{3, 5, 8}
};
var node = new EightPuzzleNode(state);
var successors = node.generateSuccessors();
final var node = new EightPuzzleNode(state);
final var successors = node.generateSuccessors();
Assertions.assertEquals(3, successors.size());
int[][] newState1 = {
final int[][] newState1 = {
{0, 1, 6},
{7, 4, 2},
{3, 5, 8}
};
int[][] newState2 = {
final int[][] newState2 = {
{7, 1, 6},
{4, 0, 2},
{3, 5, 8}
};
int[][] newState3 = {
final int[][] newState3 = {
{7, 1, 6},
{3, 4, 2},
{0, 5, 8}

View File

@ -2,7 +2,7 @@ package search;
public class SearchTestUtils
{
public static <T> void printSolution(Node<T> targetNode)
public static <T> void printSolution(final Node<T> targetNode)
{
var node = targetNode;

View File

@ -0,0 +1,8 @@
package search.heuristic;
import static org.junit.jupiter.api.Assertions.*;
class AStarTest
{
}

View File

@ -12,21 +12,21 @@ class BreadthFirstSearchTest
@Test
void shouldReturnCorrectTarget()
{
int[][] state = {
final int[][] state = {
{5, 0, 3},
{2, 1, 6},
{4, 7, 8}
};
var root = new EightPuzzleNode(state);
final var root = new EightPuzzleNode(state);
int[][] targetState = {
final int[][] targetState = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}
};
var expected = new EightPuzzleNode(targetState);
final var expected = new EightPuzzleNode(targetState);
var actual = new BreadthFirstSearch().breadthFirstSearch(List.of(root), expected);
final var actual = new BreadthFirstSearch().breadthFirstSearch(List.of(root), expected);
printSolution(actual);
}
@ -34,21 +34,21 @@ class BreadthFirstSearchTest
@Test
void shouldReturnCorrectTargetCubekNode()
{
int[][] state = {
final int[][] state = {
{2, 0, 4},
{6, 7, 1},
{8, 5, 3}
};
var root = new EightPuzzleNode(state);
final var root = new EightPuzzleNode(state);
int[][] targetState = {
final int[][] targetState = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}
};
var expected = new EightPuzzleNode(targetState);
final var expected = new EightPuzzleNode(targetState);
var actual = new BreadthFirstSearch().breadthFirstSearch(List.of(root), expected);
final var actual = new BreadthFirstSearch().breadthFirstSearch(List.of(root), expected);
printSolution(actual);
}

View File

@ -10,21 +10,21 @@ class DepthFirstSearchTest
@Test
void shouldReturnCorrectTarget()
{
int[][] state = {
final int[][] state = {
{1, 2, 3},
{4, 5, 6},
{7, 0, 8}
};
var root = new EightPuzzleNode(state);
final var root = new EightPuzzleNode(state);
int[][] targetState = {
final int[][] targetState = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}
};
var expected = new EightPuzzleNode(targetState);
final var expected = new EightPuzzleNode(targetState);
var actual = new DepthFirstSearch().depthFirstSearch(root, expected);
final var actual = new DepthFirstSearch().depthFirstSearch(root, expected);
printSolution(actual);
}

View File

@ -10,21 +10,21 @@ class IterativeDeepeningTest
@Test
void shouldReturnCorrectTarget()
{
int[][] state = {
final int[][] state = {
{5, 0, 3},
{2, 1, 6},
{4, 7, 8}
};
var root = new EightPuzzleNode(state);
final var root = new EightPuzzleNode(state);
int[][] targetState = {
final int[][] targetState = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}
};
var expected = new EightPuzzleNode(targetState);
final var expected = new EightPuzzleNode(targetState);
var actual = new IterativeDeepening().iterativeDeepening(root, expected);
final var actual = new IterativeDeepening().iterativeDeepening(root, expected);
printSolution(actual);
}
@ -32,21 +32,21 @@ class IterativeDeepeningTest
@Test
void shouldReturnCorrectTargetCubekNode()
{
int[][] state = {
final int[][] state = {
{2, 0, 4},
{6, 7, 1},
{8, 5, 3}
};
var root = new EightPuzzleNode(state);
final var root = new EightPuzzleNode(state);
int[][] targetState = {
final int[][] targetState = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 0}
};
var expected = new EightPuzzleNode(targetState);
final var expected = new EightPuzzleNode(targetState);
var actual = new IterativeDeepening().iterativeDeepening(root, expected);
final var actual = new IterativeDeepening().iterativeDeepening(root, expected);
printSolution(actual);
}