Package h07.algorithm
Class DijkstraTest
- java.lang.Object
-
- h07.util.TestClass
-
- h07.algorithm.DijkstraTest
-
public class DijkstraTest extends TestClass
Tests for classDijkstra
.
Depends onTemplateTests.ShortestPathsAlgorithmTemplateTest
,DirectedGraphImplTest
andIntegerAdditionTest
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class h07.util.TestClass
TestClass.MissingMemberException
-
-
Field Summary
Fields Modifier and Type Field Description private static Integer[][]
ADJACENCY_MATRIX
Matrix of weights between nodesprivate DirectedGraphImplTest
directedGraph
Instance ofDirectedGraphImplTest
private IntegerAdditionTest
integerAddition
Instance ofIntegerAdditionTest
private static String[]
NODES
Array of city names to use as nodesMethod
shortestPaths
Method
object forShortestPathsAlgorithm.shortestPaths(DirectedGraph, V, Monoid, Comparator)
private TemplateTests.ShortestPathsAlgorithmTemplateTest
shortestPathsAlgorithm
Instance ofTemplateTests.ShortestPathsAlgorithmTemplateTest
-
Fields inherited from class h07.util.TestClass
classDescriptor, className, constructor, fields, methods, RANDOM
-
-
Constructor Summary
Constructors Constructor Description DijkstraTest()
Creates a newDijkstraTest
object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static String
pathToString(Object path)
Returns the string representation of a given path.void
testDefinition()
Tests the definition ofDijkstra
.void
testShortestPaths(String startNode, Map<String,String> paths)
Tests forDijkstra.shortestPaths(DirectedGraph, V, Monoid, Comparator)
.-
Methods inherited from class h07.util.TestClass
getClassForName, getFieldByCriteria, getFieldByName, getMethodByCriteria, getMethodByName, getMethodSignature, invokeExpectingException, newInstance, newInstanceExpectingException, testInstance
-
-
-
-
Field Detail
-
shortestPaths
public final Method shortestPaths
Method
object forShortestPathsAlgorithm.shortestPaths(DirectedGraph, V, Monoid, Comparator)
-
shortestPathsAlgorithm
private final TemplateTests.ShortestPathsAlgorithmTemplateTest shortestPathsAlgorithm
Instance ofTemplateTests.ShortestPathsAlgorithmTemplateTest
-
directedGraph
private final DirectedGraphImplTest directedGraph
Instance ofDirectedGraphImplTest
-
integerAddition
private final IntegerAdditionTest integerAddition
Instance ofIntegerAdditionTest
-
NODES
private static final String[] NODES
Array of city names to use as nodes
-
ADJACENCY_MATRIX
private static final Integer[][] ADJACENCY_MATRIX
Matrix of weights between nodes
-
-
Constructor Detail
-
DijkstraTest
public DijkstraTest()
Creates a newDijkstraTest
object. Requires thatDijkstra
exists and has a constructor with no parameters.
-
-
Method Detail
-
testDefinition
@Test public void testDefinition()
Tests the definition ofDijkstra
.- Asserts that the class...
- is public
- is not abstract
- is generic and has the type parameters V and A
- implements
ShortestPathsAlgorithm
- Specified by:
testDefinition
in classTestClass
- Asserts that the class...
-
testShortestPaths
@ParameterizedTest @ArgumentsSource(DijkstraProvider.class) public void testShortestPaths(String startNode, Map<String,String> paths) throws ReflectiveOperationException
Tests forDijkstra.shortestPaths(DirectedGraph, V, Monoid, Comparator)
.
Asserts that the path returned by the tested method is actually the shortest fromstartNode
to any other node.
Many thanks to Oshgnacknak for fixing a bug that occurred when the map returned by the tested method was empty.- Parameters:
startNode
- the starting nodepaths
- a map of all nodes and the shortest path to reach them fromstartNode
- Throws:
ReflectiveOperationException
- if any invocation fails
-
pathToString
private static String pathToString(Object path) throws ReflectiveOperationException
Returns the string representation of a given path.
RequiresPathImplTest
andPathImplTest.TraverserTest
.- Parameters:
path
- the path- Returns:
- the string representation of a given path
- Throws:
ReflectiveOperationException
- if any invocation fails
-
-