Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / algorithms / tests / test_covering.py @ 5cef0f13

History | View | Annotate | Download (2.08 KB)

1
#    Copyright 2016-2019 NetworkX developers.
2
#    Copyright (C) 2016 by
3
#    Nishant Nikhil <nishantiam@gmail.com>
4
#    All rights reserved.
5
#    BSD license.
6

    
7
from nose.tools import assert_equal, assert_true, assert_false
8
import networkx as nx
9

    
10

    
11
class TestMinEdgeCover:
12
    """Tests for :func:`networkx.algorithms.min_edge_cover`"""
13

    
14
    def test_empty_graph(self):
15
        G = nx.Graph()
16
        assert_equal(nx.min_edge_cover(G), set())
17

    
18
    def test_graph_with_loop(self):
19
        G = nx.Graph()
20
        G.add_edge(0, 0)
21
        assert_equal(nx.min_edge_cover(G), {(0, 0)})
22

    
23
    def test_graph_single_edge(self):
24
        G = nx.Graph()
25
        G.add_edge(0, 1)
26
        assert_equal(nx.min_edge_cover(G),
27
                     {(0, 1)})
28

    
29
    def test_bipartite_explicit(self):
30
        G = nx.Graph()
31
        G.add_nodes_from([1, 2, 3, 4], bipartite=0)
32
        G.add_nodes_from(['a', 'b', 'c'], bipartite=1)
33
        G.add_edges_from([(1, 'a'), (1, 'b'), (2, 'b'),
34
                          (2, 'c'), (3, 'c'), (4, 'a')])
35
        min_cover = nx.min_edge_cover(G, nx.algorithms.bipartite.matching.
36
                                      eppstein_matching)
37
        min_cover2 = nx.min_edge_cover(G)
38
        assert_true(nx.is_edge_cover(G, min_cover))
39
        assert_equal(len(min_cover), 8)
40

    
41
    def test_complete_graph(self):
42
        G = nx.complete_graph(10)
43
        min_cover = nx.min_edge_cover(G)
44
        assert_true(nx.is_edge_cover(G, min_cover))
45
        assert_equal(len(min_cover), 5)
46

    
47

    
48
class TestIsEdgeCover:
49
    """Tests for :func:`networkx.algorithms.is_edge_cover`"""
50

    
51
    def test_empty_graph(self):
52
        G = nx.Graph()
53
        assert_true(nx.is_edge_cover(G, set()))
54

    
55
    def test_graph_with_loop(self):
56
        G = nx.Graph()
57
        G.add_edge(1, 1)
58
        assert_true(nx.is_edge_cover(G, {(1, 1)}))
59

    
60
    def test_graph_single_edge(self):
61
        G = nx.Graph()
62
        G.add_edge(0, 1)
63
        assert_true(nx.is_edge_cover(G, {(0, 0), (1, 1)}))
64
        assert_true(nx.is_edge_cover(G, {(0, 1), (1, 0)}))
65
        assert_true(nx.is_edge_cover(G, {(0, 1)}))
66
        assert_false(nx.is_edge_cover(G, {(0, 0)}))