def testModularity(self):
        numVertices = 6
        graph = SparseGraph(GeneralVertexList(numVertices))

        graph.addEdge(0,0)
        graph.addEdge(1,1)
        graph.addEdge(2,2)
        graph.addEdge(0,1)
        graph.addEdge(0,2)
        graph.addEdge(2,1)

        graph.addEdge(3,4,2)
        graph.addEdge(3,5,2)
        graph.addEdge(4,5,2)
        graph.addEdge(3,3,2)
        graph.addEdge(4,4,2)
        graph.addEdge(5,5,2)

        W = graph.getWeightMatrix()
        clustering = numpy.array([0,0,0,1,1,1])

        #This is the same as the igraph result
        Q = GraphUtils.modularity(W, clustering)
        self.assertEquals(Q, 4.0/9.0)

        Ws = scipy.sparse.csr_matrix(W)
        Q = GraphUtils.modularity(Ws, clustering)
        self.assertEquals(Q, 4.0/9.0)

        W = numpy.ones((numVertices, numVertices))
        Q = GraphUtils.modularity(W, clustering)

        self.assertEquals(Q, 0.0)

        Ws = scipy.sparse.csr_matrix(W)
        Q = GraphUtils.modularity(Ws, clustering)
        self.assertEquals(Q, 0.0)
dataset/ETHPy150Open charanpald/APGL/apgl/graph/test/GraphUtilsTest.py/AbstractMatrixGraphTest.testModularity/original