Repository: TheAlgorithms/Java
File: src/test/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithmTest.java (Java)

Code before:
        edges.add(new BoruvkaAlgorithm.Edge(5, 7, 6));
        edges.add(new BoruvkaAlgorithm.Edge(6, 7, 9));
        edges.add(new BoruvkaAlgorithm.Edge(6, 8, 2));
        edges.add(new BoruvkaAlgorithm.Edge(7, 8, 11));

        final var graph = new Graph(9, edges);
        /**
         * Adjacency matrix
         *    0   1   2   3   4   5   6   7   8
         * 0  0  10  12   0   0   0   0   0   0
         * 1 10   0   9   8   0   0   0   0   0
         * 2 12   9   0   0   3   1   0   0   0
         * 3  0   8   0   0   7   0   8   5   0
         * 4  0   0   3   7   0   3   0   0   0
         * 5  0   0   1   0   3   0   0   6   0
         * 6  0   0   0   8   0   0   0   9   2
         * 7  0   0   0   5   0   6   9   0  11
         * 8  0   0   0   0   0   0   2  11   0
         */

        final var result = BoruvkaAlgorithm.boruvkaMST(graph);
        // Expected result:
        // Edges: 8
        // Total weight: 43
        assertEquals(8, result.size());
        assertEquals(43, BoruvkaAlgorithm.computeTotalWeight(result));
    }

    @Test
    void testBoruvkaMSTV2E1() {
        List<BoruvkaAlgorithm.Edge> edges = new ArrayList<>();

        edges.add(new BoruvkaAlgorithm.Edge(0, 1, 10));

        final var graph = new Graph(2, edges);

        /**
         * Adjacency matrix
         *    0  1
         * 0  0  10
         * 1  10  0
         */
        final var result = BoruvkaAlgorithm.boruvkaMST(graph);
        // Expected result:
        // Edges: 1
        // Total weight: 10
        assertEquals(1, result.size());
        assertEquals(10, BoruvkaAlgorithm.computeTotalWeight(result));
    }

    @Test

Review comment (suggestion):
`computeTotalWeight` should be a method in `BoruvkaAlgorithmTest`.

Code after:
        edges.add(new BoruvkaAlgorithm.Edge(5, 7, 6));
        edges.add(new BoruvkaAlgorithm.Edge(6, 7, 9));
        edges.add(new BoruvkaAlgorithm.Edge(6, 8, 2));
        edges.add(new BoruvkaAlgorithm.Edge(7, 8, 11));

        final var graph = new Graph(9, edges);
        /**
         * Adjacency matrix
         *    0   1   2   3   4   5   6   7   8
         * 0  0  10  12   0   0   0   0   0   0
         * 1 10   0   9   8   0   0   0   0   0
         * 2 12   9   0   0   3   1   0   0   0
         * 3  0   8   0   0   7   0   8   5   0
         * 4  0   0   3   7   0   3   0   0   0
         * 5  0   0   1   0   3   0   0   6   0
         * 6  0   0   0   8   0   0   0   9   2
         * 7  0   0   0   5   0   6   9   0  11
         * 8  0   0   0   0   0   0   2  11   0
         */
        final var result = BoruvkaAlgorithm.boruvkaMST(graph);
        assertEquals(8, result.size());
        assertEquals(43, computeTotalWeight(result));
    }

    @Test
    void testBoruvkaMSTV2E1() {
        List<BoruvkaAlgorithm.Edge> edges = new ArrayList<>();

        edges.add(new BoruvkaAlgorithm.Edge(0, 1, 10));

        final var graph = new Graph(2, edges);

        /**
         * Adjacency matrix
         *    0  1
         * 0  0  10
         * 1  10  0
         */
        final var result = BoruvkaAlgorithm.boruvkaMST(graph);
        assertEquals(1, result.size());
        assertEquals(10, computeTotalWeight(result));
    }

    @Test
    void testCompleteGraphK4() {
        List<BoruvkaAlgorithm.Edge> edges = new ArrayList<>();
        edges.add(new BoruvkaAlgorithm.Edge(0, 1, 7));
        edges.add(new BoruvkaAlgorithm.Edge(0, 2, 2));
        edges.add(new BoruvkaAlgorithm.Edge(0, 3, 5));
        edges.add(new BoruvkaAlgorithm.Edge(1, 2, 3));
        edges.add(new BoruvkaAlgorithm.Edge(1, 3, 4));