comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_covering.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import networkx as nx
2
3
4 class TestMinEdgeCover:
5 """Tests for :func:`networkx.algorithms.min_edge_cover`"""
6
7 def test_empty_graph(self):
8 G = nx.Graph()
9 assert nx.min_edge_cover(G) == set()
10
11 def test_graph_with_loop(self):
12 G = nx.Graph()
13 G.add_edge(0, 0)
14 assert nx.min_edge_cover(G) == {(0, 0)}
15
16 def test_graph_single_edge(self):
17 G = nx.Graph()
18 G.add_edge(0, 1)
19 assert nx.min_edge_cover(G) in ({(0, 1)}, {(1, 0)})
20
21 def test_bipartite_explicit(self):
22 G = nx.Graph()
23 G.add_nodes_from([1, 2, 3, 4], bipartite=0)
24 G.add_nodes_from(["a", "b", "c"], bipartite=1)
25 G.add_edges_from([(1, "a"), (1, "b"), (2, "b"), (2, "c"), (3, "c"), (4, "a")])
26 min_cover = nx.min_edge_cover(
27 G, nx.algorithms.bipartite.matching.eppstein_matching
28 )
29 min_cover2 = nx.min_edge_cover(G)
30 assert nx.is_edge_cover(G, min_cover)
31 assert len(min_cover) == 8
32
33 def test_complete_graph(self):
34 G = nx.complete_graph(10)
35 min_cover = nx.min_edge_cover(G)
36 assert nx.is_edge_cover(G, min_cover)
37 assert len(min_cover) == 5
38
39
40 class TestIsEdgeCover:
41 """Tests for :func:`networkx.algorithms.is_edge_cover`"""
42
43 def test_empty_graph(self):
44 G = nx.Graph()
45 assert nx.is_edge_cover(G, set())
46
47 def test_graph_with_loop(self):
48 G = nx.Graph()
49 G.add_edge(1, 1)
50 assert nx.is_edge_cover(G, {(1, 1)})
51
52 def test_graph_single_edge(self):
53 G = nx.Graph()
54 G.add_edge(0, 1)
55 assert nx.is_edge_cover(G, {(0, 0), (1, 1)})
56 assert nx.is_edge_cover(G, {(0, 1), (1, 0)})
57 assert nx.is_edge_cover(G, {(0, 1)})
58 assert not nx.is_edge_cover(G, {(0, 0)})