Package h07.graph
Class DirectedGraphImplTest
- java.lang.Object
-
- h07.util.TestClass
-
- h07.graph.DirectedGraphImplTest
-
public class DirectedGraphImplTest extends TestClass
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class h07.util.TestClass
TestClass.MissingMemberException
-
-
Field Summary
Fields Modifier and Type Field Description Method
addNode
Method
object forDirectedGraph.addNode(V)
Method
connectNodes
Method
object forDirectedGraph.connectNodes(V, A, V)
private TemplateTests.DirectedGraphTemplateTest
directedGraph
Instance ofTemplateTests.DirectedGraphTemplateTest
Method
disconnectNodes
Method
object forDirectedGraph.disconnectNodes(V, V)
Method
getAllNodes
Method
object forDirectedGraph.getAllNodes()
Method
getArcWeightBetween
Method
object forDirectedGraph.getArcWeightBetween(V, V)
Method
getChildrenForNode
Method
object forDirectedGraph.getChildrenForNode(V)
Method
removeNode
Method
object forDirectedGraph.removeNode(V)
-
Fields inherited from class h07.util.TestClass
classDescriptor, className, constructor, fields, methods, RANDOM
-
-
Constructor Summary
Constructors Constructor Description DirectedGraphImplTest()
Creates a newDirectedGraphImplTest
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
newInstance(Object... params)
Returns a newDirectedGraphImpl
object.void
testAddNode(Character[] nodes, Integer[][] adjacencyMatrix)
Tests forDirectedGraphImpl.addNode(V)
.void
testConnectNodes(Character[] nodes, Integer[][] adjacencyMatrix)
Tests forDirectedGraphImpl.connectNodes(V, A, V)
.void
testDefinition()
Tests the definition ofDirectedGraphImpl
.void
testDisconnectNodes(Character[] nodes, Integer[][] adjacencyMatrix)
Tests forDirectedGraphImpl.disconnectNodes(V, V)
.void
testGetAllNodes(Character[] nodes, Integer[][] adjacencyMatrix)
Tests forDirectedGraphImpl.getAllNodes()
.void
testGetArcWeightBetween(Character[] nodes, Integer[][] adjacencyMatrix)
Tests forDirectedGraphImpl.getArcWeightBetween(V, V)
.void
testGetChildrenForNode(Character[] nodes, Integer[][] adjacencyMatrix)
Tests forDirectedGraphImpl.getChildrenForNode(V)
.void
testRemoveNode(Character[] nodes, Integer[][] adjacencyMatrix)
Tests forDirectedGraphImpl.removeNode(V)
.-
Methods inherited from class h07.util.TestClass
getClassForName, getFieldByCriteria, getFieldByName, getMethodByCriteria, getMethodByName, getMethodSignature, invokeExpectingException, newInstanceExpectingException, testInstance
-
-
-
-
Field Detail
-
getAllNodes
public final Method getAllNodes
Method
object forDirectedGraph.getAllNodes()
-
getChildrenForNode
public final Method getChildrenForNode
Method
object forDirectedGraph.getChildrenForNode(V)
-
getArcWeightBetween
public final Method getArcWeightBetween
Method
object forDirectedGraph.getArcWeightBetween(V, V)
-
addNode
public final Method addNode
Method
object forDirectedGraph.addNode(V)
-
removeNode
public final Method removeNode
Method
object forDirectedGraph.removeNode(V)
-
connectNodes
public final Method connectNodes
Method
object forDirectedGraph.connectNodes(V, A, V)
-
disconnectNodes
public final Method disconnectNodes
Method
object forDirectedGraph.disconnectNodes(V, V)
-
directedGraph
private final TemplateTests.DirectedGraphTemplateTest directedGraph
Instance ofTemplateTests.DirectedGraphTemplateTest
-
-
Constructor Detail
-
DirectedGraphImplTest
public DirectedGraphImplTest()
Creates a newDirectedGraphImplTest
object. Requires thatDirectedGraphImpl
exists and has a constructor with no parameters.
-
-
Method Detail
-
testDefinition
@Test public void testDefinition()
Tests the definition ofDirectedGraphImpl
.- Asserts that the class...
- is package-private
- is not abstract
- is generic and has the type parameters V and A
- implements
DirectedGraph
- Asserts that the constructor is package-private
- Asserts that all fields are private
- Asserts that all methods that are not defined in
DirectedGraph
or inherited are private - Asserts that all inner classes are private
- Specified by:
testDefinition
in classTestClass
- Asserts that the class...
-
testGetAllNodes
@ParameterizedTest @ArgumentsSource(GraphProvider.class) public void testGetAllNodes(Character[] nodes, Integer[][] adjacencyMatrix) throws ReflectiveOperationException
Tests forDirectedGraphImpl.getAllNodes()
.
Asserts that the collection returned by the tested method is immutable and has the same size and elements asnodes
.- Parameters:
nodes
- an array of nodes (supplied by the arguments provider)adjacencyMatrix
- a matrix of weights from one node to another (supplied by the arguments provider)- Throws:
ReflectiveOperationException
- if any invocation fails
-
testGetChildrenForNode
@ParameterizedTest @ArgumentsSource(GraphProvider.class) public void testGetChildrenForNode(Character[] nodes, Integer[][] adjacencyMatrix) throws ReflectiveOperationException
Tests forDirectedGraphImpl.getChildrenForNode(V)
.
Asserts that the collection returned by the tested method is immutable. Further asserts that the collection has the same size and elements as the expected set of children for a given node. Also asserts that the method throws aNullPointerException
if invoked withnull
and aNoSuchElementException
if invoked with a node that is not in this graph.- Parameters:
nodes
- an array of nodes (supplied by the arguments provider)adjacencyMatrix
- a matrix of weights from one node to another (supplied by the arguments provider)- Throws:
ReflectiveOperationException
- if any invocation fails
-
testGetArcWeightBetween
@ParameterizedTest @ArgumentsSource(GraphProvider.class) public void testGetArcWeightBetween(Character[] nodes, Integer[][] adjacencyMatrix) throws ReflectiveOperationException
Tests forDirectedGraphImpl.getArcWeightBetween(V, V)
.
Asserts that the value returned by the tested method equals the expected one, should an arc exist. If there is no arc fromnodes[i]
tonodes[j]
, asserts that the method throws aNoSuchElementException
. Also asserts that the method throws aNullPointerException
if invoked withnull
and aNoSuchElementException
if invoked with a node that is not in this graph.- Parameters:
nodes
- an array of nodes (supplied by the arguments provider)adjacencyMatrix
- a matrix of weights from one node to another (supplied by the arguments provider)- Throws:
ReflectiveOperationException
- if any invocation fails
-
testAddNode
@ParameterizedTest @ArgumentsSource(GraphProvider.class) public void testAddNode(Character[] nodes, Integer[][] adjacencyMatrix) throws ReflectiveOperationException
Tests forDirectedGraphImpl.addNode(V)
. RequiresDirectedGraphImpl.getAllNodes()
.
Asserts that the invocation of the tested method does not throw any exceptions and that aIllegalArgumentException
is thrown when attempting to add the same node again. After that, asserts that all nodes with whichDirectedGraphImpl.addNode(V)
was invoked actually have been added. Also asserts that the method throws aNullPointerException
if invoked withnull
.- Parameters:
nodes
- an array of nodes (supplied by the arguments provider)adjacencyMatrix
- a matrix of weights from one node to another (supplied by the arguments provider)- Throws:
ReflectiveOperationException
- if any invocation fails
-
testRemoveNode
@ParameterizedTest @ArgumentsSource(GraphProvider.class) public void testRemoveNode(Character[] nodes, Integer[][] adjacencyMatrix) throws ReflectiveOperationException
Tests forDirectedGraphImpl.removeNode(V)
. RequiresDirectedGraphImpl.getAllNodes()
andDirectedGraphImpl.getChildrenForNode(V)
(only exceptions).
Asserts that the invocation of the tested method does not throw any exceptions and that aNoSuchElementException
is thrown when attempting to remove the same node again. Asserts that the removed node was actually removed from the collection returned byDirectedGraphImpl.getAllNodes()
and that all arcs to and from the node have been removed. Also asserts that the method throws aNullPointerException
if invoked withnull
.- Parameters:
nodes
- an array of nodes (supplied by the arguments provider)adjacencyMatrix
- a matrix of weights from one node to another (supplied by the arguments provider)- Throws:
ReflectiveOperationException
- if any invocation fails
-
testConnectNodes
@ParameterizedTest @ArgumentsSource(GraphProvider.class) public void testConnectNodes(Character[] nodes, Integer[][] adjacencyMatrix) throws ReflectiveOperationException
Tests forDirectedGraphImpl.connectNodes(V, A, V)
. RequiresDirectedGraphImpl.getChildrenForNode(V)
. This test will attempt to connect every node to itself and all others.
Asserts that the invocation of the tested method does not throw any exceptions and that aIllegalArgumentException
is thrown when attempting to connect the same nodes again if there was no arc between them. If there was, asserts that the method throws aIllegalArgumentException
. Asserts that every node innodes
has a connection to every other node and itself. Also asserts that the method throws aNullPointerException
if invoked withnull
and aNoSuchElementException
if invoked with a node that is not in this graph.- Parameters:
nodes
- an array of nodes (supplied by the arguments provider)adjacencyMatrix
- a matrix of weights from one node to another (supplied by the arguments provider)- Throws:
ReflectiveOperationException
- if any invocation fails
-
testDisconnectNodes
@ParameterizedTest @ArgumentsSource(GraphProvider.class) public void testDisconnectNodes(Character[] nodes, Integer[][] adjacencyMatrix) throws ReflectiveOperationException
Tests forDirectedGraphImpl.disconnectNodes(V, V)
. RequiresDirectedGraphImpl.getChildrenForNode(V)
. This test will attempt to disconnect every node from itself and every other node.
Asserts that the invocation of the tested method does not throw any exceptions and that aNoSuchElementException
is thrown when attempting to disconnect the same nodes again if there was a arc between them. If there wasn't, asserts that the method throws aNoSuchElementException
. Asserts that every node innodes
has no connections to any other node nor itself. Also asserts that the method throws aNullPointerException
if invoked withnull
and aNoSuchElementException
if invoked with a node that is not in this graph.- Parameters:
nodes
- an array of nodes (supplied by the arguments provider)adjacencyMatrix
- a matrix of weights from one node to another (supplied by the arguments provider)- Throws:
ReflectiveOperationException
- if any invocation fails
-
newInstance
public Object newInstance(Object... params)
Returns a newDirectedGraphImpl
object.
It is necessary to overrideTestClass.newInstance(Object...)
because no constructors have been specified by the assignment, so usingAdjacencyMatrixFactory.createDirectedGraph()
is the way to go.- Overrides:
newInstance
in classTestClass
- Parameters:
params
- the parameters to supply to the constructor ofAdjacencyMatrixFactory
- Returns:
- a new
DirectedGraphImpl
instance
-
-