/usr/lib/python3/dist-packages/networkx/algorithms/tree/tests/test_recognition.py is in python3-networkx 1.11-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | from nose.tools import *
import networkx as nx
class TestTreeRecognition(object):
graph = nx.Graph
multigraph = nx.MultiGraph
def setUp(self):
self.T1 = self.graph()
self.T2 = self.graph()
self.T2.add_node(1)
self.T3 = self.graph()
self.T3.add_nodes_from(range(5))
edges = [(i,i+1) for i in range(4)]
self.T3.add_edges_from(edges)
self.T5 = self.multigraph()
self.T5.add_nodes_from(range(5))
edges = [(i,i+1) for i in range(4)]
self.T5.add_edges_from(edges)
self.T6 = self.graph()
self.T6.add_nodes_from([6,7])
self.T6.add_edge(6,7)
self.F1 = nx.compose(self.T6, self.T3)
self.N4 = self.graph()
self.N4.add_node(1)
self.N4.add_edge(1,1)
self.N5 = self.graph()
self.N5.add_nodes_from(range(5))
self.N6 = self.graph()
self.N6.add_nodes_from(range(3))
self.N6.add_edges_from([(0,1),(1,2),(2,0)])
self.NF1 = nx.compose(self.T6,self.N6)
@raises(nx.NetworkXPointlessConcept)
def test_null_tree(self):
nx.is_tree(self.graph())
nx.is_tree(self.multigraph())
@raises(nx.NetworkXPointlessConcept)
def test_null_forest(self):
nx.is_forest(self.graph())
nx.is_forest(self.multigraph())
def test_is_tree(self):
assert_true(nx.is_tree(self.T2))
assert_true(nx.is_tree(self.T3))
assert_true(nx.is_tree(self.T5))
def test_is_not_tree(self):
assert_false(nx.is_tree(self.N4))
assert_false(nx.is_tree(self.N5))
assert_false(nx.is_tree(self.N6))
def test_is_forest(self):
assert_true(nx.is_forest(self.T2))
assert_true(nx.is_forest(self.T3))
assert_true(nx.is_forest(self.T5))
assert_true(nx.is_forest(self.F1))
assert_true(nx.is_forest(self.N5))
def test_is_not_forest(self):
assert_false(nx.is_forest(self.N4))
assert_false(nx.is_forest(self.N6))
assert_false(nx.is_forest(self.NF1))
class TestDirectedTreeRecognition(TestTreeRecognition):
graph = nx.DiGraph
multigraph = nx.MultiDiGraph
def test_disconnected_graph():
# https://github.com/networkx/networkx/issues/1144
G = nx.Graph()
G.add_edges_from([(0, 1), (1, 2), (2, 0), (3, 4)])
assert_false(nx.is_tree(G))
G = nx.DiGraph()
G.add_edges_from([(0, 1), (1, 2), (2, 0), (3, 4)])
assert_false(nx.is_tree(G))
def test_dag_nontree():
G = nx.DiGraph()
G.add_edges_from([(0,1), (0,2), (1,2)])
assert_false(nx.is_tree(G))
assert_true(nx.is_directed_acyclic_graph(G))
def test_multicycle():
G = nx.MultiDiGraph()
G.add_edges_from([(0,1), (0,1)])
assert_false(nx.is_tree(G))
assert_true(nx.is_directed_acyclic_graph(G))
def test_emptybranch():
G = nx.DiGraph()
G.add_nodes_from(range(10))
assert_true(nx.is_branching(G))
assert_false(nx.is_arborescence(G))
def test_path():
G = nx.DiGraph()
G.add_path(range(5))
assert_true(nx.is_branching(G))
assert_true(nx.is_arborescence(G))
def test_notbranching1():
# Acyclic violation.
G = nx.MultiDiGraph()
G.add_nodes_from(range(10))
G.add_edges_from([(0,1),(1,0)])
assert_false(nx.is_branching(G))
assert_false(nx.is_arborescence(G))
def test_notbranching2():
# In-degree violation.
G = nx.MultiDiGraph()
G.add_nodes_from(range(10))
G.add_edges_from([(0,1),(0,2),(3,2)])
assert_false(nx.is_branching(G))
assert_false(nx.is_arborescence(G))
def test_notarborescence1():
# Not an arborescence due to not spanning.
G = nx.MultiDiGraph()
G.add_nodes_from(range(10))
G.add_edges_from([(0,1),(0,2),(1,3),(5,6)])
assert_true(nx.is_branching(G))
assert_false(nx.is_arborescence(G))
def test_notarborescence2():
# Not an arborescence due to in-degree violation.
G = nx.MultiDiGraph()
G.add_path(range(5))
G.add_edge(6, 4)
assert_false(nx.is_branching(G))
assert_false(nx.is_arborescence(G))
|