def test_read_write_json(self): g = nx.karate_club_graph() communities = algorithms.louvain(g) readwrite.write_community_json(communities, "coms.json") communities_r = readwrite.read_community_json("coms.json") self.assertListEqual(communities.communities, communities_r.communities) os.remove("coms.json") communities = algorithms.louvain(g) readwrite.write_community_json(communities, "coms.gzip", zip=True) communities_r = readwrite.read_community_json("coms.gzip", zip=True) self.assertListEqual(communities.communities, communities_r.communities) os.remove("coms.gzip") communities = algorithms.frc_fgsn(g, 1, 0.5, 3) readwrite.write_community_json(communities, "coms.json") communities_r = readwrite.read_community_json("coms.json") self.assertListEqual(communities.communities, communities_r.communities) os.remove("coms.json") communities = algorithms.hierarchical_link_community(g) readwrite.write_community_json(communities, "coms.json") communities_r = readwrite.read_community_json("coms.json") self.assertListEqual(communities.communities, communities_r.communities) with open("coms.json") as f: cr = f.read() readwrite.read_community_from_json_string(cr) os.remove("coms.json")
def test_frc_fgsn(self): g = get_string_graph() coms = algorithms.frc_fgsn(g, 1, 0.5, 3) self.assertEqual(type(coms.communities), list) if len(coms.communities) > 0: self.assertEqual(type(coms.communities[0]), list) self.assertEqual(type(coms.communities[0][0]), tuple) self.assertIsInstance(coms.allocation_matrix, dict) self.assertEqual(len(coms.allocation_matrix), g.number_of_nodes())
def test_to_json(self): g = nx.karate_club_graph() coms = algorithms.louvain(g) self.assertIsInstance(coms, NodeClustering) js = coms.to_json() self.assertIsInstance(js, str) self.assertEqual(coms.node_coverage, 1.0) coms = algorithms.frc_fgsn(g, 0.5, 0.3, 1) js = coms.to_json() self.assertIsInstance(js, str)