def test_positive_graph(self):
        expected_positive_graph = copy.copy(self.graph)
        expected_positive_graph.delete_edges([1, 3])

        splitter = graph_splitter.GraphSplitter()
        positive_graph = splitter.positive_graph(self.graph)

        comparer = graph_comparer.GraphComparer()
        self.assertTrue(comparer.equal(positive_graph,
                                       expected_positive_graph))
    def test_negative_graph(self):
        expected_negative_graph = copy.copy(self.graph)
        expected_negative_graph.delete_edges([0, 2])

        splitter = graph_splitter.GraphSplitter()
        negative_graph = splitter.negative_graph(self.graph)

        comparer = graph_comparer.GraphComparer()
        self.assertTrue(comparer.equal(expected_negative_graph,
                                       negative_graph))
    def test_compare_graph_and_graph_copy(self):
        graph_copy = copy.copy(self.graph)

        comparer = graph_comparer.GraphComparer()

        self.assertTrue(comparer.equal(self.graph, graph_copy))
        self.assertTrue(comparer.edges_equal(self.graph, graph_copy))
        self.assertTrue(comparer.edge_lists_equal(self.graph, graph_copy))
        self.assertTrue(comparer.edge_sequence_attributes_equal(self.graph, graph_copy))
        self.assertTrue(comparer.edge_attributes_equal(self.graph, graph_copy))
        self.assertTrue(comparer.vertices_equal(self.graph, graph_copy))
        self.assertTrue(comparer.number_vertices_equal(self.graph, graph_copy))
        self.assertTrue(comparer.vertex_sequence_attributes_equal(self.graph, graph_copy))
        self.assertTrue(comparer.vertex_attributes_equal(self.graph, graph_copy))
        self.assertTrue(comparer.attributes_equal(self.graph, graph_copy))
    def test_load_pickle(self):
        helper = path_helper.PathHelper()
        loader = graph_loader.GraphLoader(helper)

        file_directory = helper.path_to_module_directory(test_files)
        file_path = helper.join_paths(file_directory, 'test graph.pickle')

        # TODO make the graph from scratch that is equivalent to the graph from
        # the file
        compared_graph = igraph.Graph.Read_Pickle(file_path)

        test_graph = loader.graph_from_file(file_path)

        comparer = graph_comparer.GraphComparer()

        self.assertTrue(comparer.equal(compared_graph, test_graph))
    def test_add_edge_attribute(self):
        changed_graph = copy.copy(self.graph)
        changed_graph.es[0]['new edge attribute'] = 'new edge attribute value'

        comparer = graph_comparer.GraphComparer()

        self.assertFalse(comparer.equal(self.graph, changed_graph))
        self.assertFalse(comparer.edges_equal(self.graph, changed_graph))
        self.assertTrue(comparer.edge_lists_equal(self.graph, changed_graph))
        self.assertFalse(comparer.edge_sequence_attributes_equal(self.graph, changed_graph))
        self.assertFalse(comparer.edge_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertices_equal(self.graph, changed_graph))
        self.assertTrue(comparer.number_vertices_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertex_sequence_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertex_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.attributes_equal(self.graph, changed_graph))
    def test_add_edge(self):
        changed_graph = copy.copy(self.graph)
        changed_graph.add_edges([(1, 3)])

        comparer = graph_comparer.GraphComparer()

        self.assertFalse(comparer.equal(self.graph, changed_graph))
        self.assertFalse(comparer.edges_equal(self.graph, changed_graph))
        self.assertFalse(comparer.edge_lists_equal(self.graph, changed_graph))
        self.assertTrue(comparer.edge_sequence_attributes_equal(self.graph, changed_graph))
        self.assertFalse(comparer.edge_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertices_equal(self.graph, changed_graph))
        self.assertTrue(comparer.number_vertices_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertex_sequence_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertex_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.attributes_equal(self.graph, changed_graph))
    def test_change_vertex_sequence_attribute_value(self):
        changed_graph = copy.copy(self.graph)
        changed_graph.vs['vertex sequence attribute'] = 3

        comparer = graph_comparer.GraphComparer()

        self.assertFalse(comparer.equal(self.graph, changed_graph))
        self.assertTrue(comparer.edges_equal(self.graph, changed_graph))
        self.assertTrue(comparer.edge_lists_equal(self.graph, changed_graph))
        self.assertTrue(comparer.edge_sequence_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.edge_attributes_equal(self.graph, changed_graph))
        self.assertFalse(comparer.vertices_equal(self.graph, changed_graph))
        self.assertTrue(comparer.number_vertices_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertex_sequence_attributes_equal(self.graph, changed_graph))
        self.assertFalse(comparer.vertex_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.attributes_equal(self.graph, changed_graph))
Esempio n. 8
0
    def setUp(self):
        self.graph = igraph.Graph()

        self.graph.add_vertices(7)
        self.graph.add_edges([(1, 2), (3, 4), (2, 4), (4, 5), (5, 6)])
        self.graph.es['sign'] = [1, -1, 1, -1, -1]

        self.graph.es['edge sequence attribute'] = (
            'edge sequence attribute value')
        self.graph.es[2]['edge attribute'] = 'edge attribute value'
        self.graph.vs['vertex sequence attribute'] = (
            'vertex sequence attribute value')
        self.graph.vs[5]['vertex attribute'] = 'vertex attribute value'
        self.graph['graph attribute'] = 'graph attribute value'

        splitter = graph_splitter.GraphSplitter()
        self.finder = community_finder.CommunityFinder(splitter)
        self.comparer = graph_comparer.GraphComparer()
    def test_change_edge_attribute_value(self):
        changed_graph = copy.copy(self.graph)
        changed_graph.es[0]['edge attribute'] = (
                'edge attribute replacement value'
                )

        comparer = graph_comparer.GraphComparer()

        self.assertFalse(comparer.equal(self.graph, changed_graph))
        self.assertFalse(comparer.edges_equal(self.graph, changed_graph))
        self.assertTrue(comparer.edge_lists_equal(self.graph, changed_graph))
        self.assertTrue(comparer.edge_sequence_attributes_equal(self.graph, changed_graph))
        self.assertFalse(comparer.edge_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertices_equal(self.graph, changed_graph))
        self.assertTrue(comparer.number_vertices_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertex_sequence_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.vertex_attributes_equal(self.graph, changed_graph))
        self.assertTrue(comparer.attributes_equal(self.graph, changed_graph))