Package h07.graph

Class DirectedGraphImplTest

    • Field Detail

      • getAllNodes

        public final Method getAllNodes
        Method object for DirectedGraph.getAllNodes()
      • getChildrenForNode

        public final Method getChildrenForNode
        Method object for DirectedGraph.getChildrenForNode(V)
      • getArcWeightBetween

        public final Method getArcWeightBetween
        Method object for DirectedGraph.getArcWeightBetween(V, V)
      • addNode

        public final Method addNode
        Method object for DirectedGraph.addNode(V)
      • removeNode

        public final Method removeNode
        Method object for DirectedGraph.removeNode(V)
      • connectNodes

        public final Method connectNodes
        Method object for DirectedGraph.connectNodes(V, A, V)
      • disconnectNodes

        public final Method disconnectNodes
        Method object for DirectedGraph.disconnectNodes(V, V)
    • Constructor Detail

      • DirectedGraphImplTest

        public DirectedGraphImplTest()
        Creates a new DirectedGraphImplTest object. Requires that DirectedGraphImpl exists and has a constructor with no parameters.
    • Method Detail

      • testDefinition

        @Test
        public void testDefinition()
        Tests the definition of DirectedGraphImpl.
        • 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 class TestClass
      • testGetChildrenForNode

        @ParameterizedTest
        @ArgumentsSource(GraphProvider.class)
        public void testGetChildrenForNode​(Character[] nodes,
                                           Integer[][] adjacencyMatrix)
                                    throws ReflectiveOperationException
        Tests for DirectedGraphImpl.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 a NullPointerException if invoked with null and a NoSuchElementException 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 for DirectedGraphImpl.addNode(V). Requires DirectedGraphImpl.getAllNodes().
        Asserts that the invocation of the tested method does not throw any exceptions and that a IllegalArgumentException is thrown when attempting to add the same node again. After that, asserts that all nodes with which DirectedGraphImpl.addNode(V) was invoked actually have been added. Also asserts that the method throws a NullPointerException if invoked with null.
        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 for DirectedGraphImpl.removeNode(V). Requires DirectedGraphImpl.getAllNodes() and DirectedGraphImpl.getChildrenForNode(V) (only exceptions).
        Asserts that the invocation of the tested method does not throw any exceptions and that a NoSuchElementException is thrown when attempting to remove the same node again. Asserts that the removed node was actually removed from the collection returned by DirectedGraphImpl.getAllNodes() and that all arcs to and from the node have been removed. Also asserts that the method throws a NullPointerException if invoked with null.
        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 for DirectedGraphImpl.connectNodes(V, A, V). Requires DirectedGraphImpl.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 a IllegalArgumentException 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 a IllegalArgumentException. Asserts that every node in nodes has a connection to every other node and itself. Also asserts that the method throws a NullPointerException if invoked with null and a NoSuchElementException 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 for DirectedGraphImpl.disconnectNodes(V, V). Requires DirectedGraphImpl.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 a NoSuchElementException 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 a NoSuchElementException. Asserts that every node in nodes has no connections to any other node nor itself. Also asserts that the method throws a NullPointerException if invoked with null and a NoSuchElementException 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 new DirectedGraphImpl object.
        It is necessary to override TestClass.newInstance(Object...) because no constructors have been specified by the assignment, so using AdjacencyMatrixFactory.createDirectedGraph() is the way to go.
        Overrides:
        newInstance in class TestClass
        Parameters:
        params - the parameters to supply to the constructor of AdjacencyMatrixFactory
        Returns:
        a new DirectedGraphImpl instance