@Override
    public Matrix toMatrix() {
        return Matrix.of(graph);
    }
@Test
    public void testToMatrix() {
        System.out.println("toMatrix digraph = false");

        AdjacencyMatrix graph = new AdjacencyMatrix(8, false);
        graph.addEdge(0, 2);
        graph.addEdge(1, 7);
        graph.addEdge(2, 6);
        graph.addEdge(7, 4);
        graph.addEdge(3, 4);
        graph.addEdge(3, 5);
        graph.addEdge(5, 4);

        Matrix matrix = graph.toMatrix();

        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                System.out.print(matrix.get(i, j) + " ");
            }
            System.out.println();
        }

        assertEquals(1.0, matrix.get(0, 2), 1E-10);
        assertEquals(1.0, matrix.get(1, 7), 1E-10);
        assertEquals(1.0, matrix.get(2, 6), 1E-10);
        assertEquals(1.0, matrix.get(7, 4), 1E-10);
        assertEquals(1.0, matrix.get(3, 4), 1E-10);
        assertEquals(1.0, matrix.get(3, 5), 1E-10);
        assertEquals(1.0, matrix.get(5, 4), 1E-10);

        // Graph is undirected.
        assertEquals(1.0, matrix.get(2, 0), 1E-10);
        assertEquals(1.0, matrix.get(7, 1), 1E-10);
        assertEquals(1.0, matrix.get(6, 2), 1E-10);
        assertEquals(1.0, matrix.get(4, 7), 1E-10);
        assertEquals(1.0, matrix.get(4, 3), 1E-10);
        assertEquals(1.0, matrix.get(5, 3), 1E-10);
        assertEquals(1.0, matrix.get(4, 5), 1E-10);
    }