public double calculateDensity(Graph graph, boolean isGraphDirected) {
        double result;

        double edgesCount = graph.getEdgeCount();
        double nodesCount = graph.getNodeCount();
        double multiplier = 1;

        if (!isGraphDirected) {
            multiplier = 2;
        }
        result = (multiplier * edgesCount) / (nodesCount * nodesCount - nodesCount);
        return result;
    }
@Test
    public void testCompleteGraphWithSelfLoopsDensity() {
        GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(3);
        UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
        Node n1 = undirectedGraph.getNode("0");
        Node n2 = undirectedGraph.getNode("1");
        Node n3 = undirectedGraph.getNode("2");
        Edge currentEdge = graphModel.factory().newEdge(n1, n1, false);
        undirectedGraph.addEdge(currentEdge);
        currentEdge = graphModel.factory().newEdge(n2, n2, false);
        undirectedGraph.addEdge(currentEdge);
        currentEdge = graphModel.factory().newEdge(n3, n3, false);
        undirectedGraph.addEdge(currentEdge);
        Graph graph = graphModel.getGraph();
        GraphDensity d = new GraphDensity();
        double density = d.calculateDensity(graph, false);
        assertEquals(density, 2.0);
    }