ioftools / networkxMiCe / networkxmaster / networkx / generators / tests / test_small.py @ 5cef0f13
History  View  Annotate  Download (6.73 KB)
1 
#!/usr/bin/env python


2  
3 
from nose.tools import * 
4 
from networkx import * 
5 
from networkx.algorithms.isomorphism.isomorph import graph_could_be_isomorphic 
6 
is_isomorphic = graph_could_be_isomorphic 
7  
8 
"""Generators  Small

9 
=====================

10 

11 
Some small graphs

12 
"""

13  
14 
null = null_graph() 
15  
16  
17 
class TestGeneratorsSmall(): 
18 
def test_make_small_graph(self): 
19 
d = ["adjacencylist", "Bull Graph", 5, [[2, 3], [1, 3, 4], [1, 2, 5], [2], [3]]] 
20 
G = make_small_graph(d) 
21 
assert_true(is_isomorphic(G, bull_graph())) 
22  
23 
def test__LCF_graph(self): 
24 
# If n<=0, then return the null_graph

25 
G = LCF_graph(10, [1, 2], 100) 
26 
assert_true(is_isomorphic(G, null)) 
27 
G = LCF_graph(0, [1, 2], 3) 
28 
assert_true(is_isomorphic(G, null)) 
29 
G = LCF_graph(0, [1, 2], 10) 
30 
assert_true(is_isomorphic(G, null)) 
31  
32 
# Test that LCF(n,[],0) == cycle_graph(n)

33 
for a, b, c in [(5, [], 0), (10, [], 0), (5, [], 1), (10, [], 10)]: 
34 
G = LCF_graph(a, b, c) 
35 
assert_true(is_isomorphic(G, cycle_graph(a))) 
36  
37 
# Generate the utility graph K_{3,3}

38 
G = LCF_graph(6, [3, 3], 3) 
39 
utility_graph = complete_bipartite_graph(3, 3) 
40 
assert_true(is_isomorphic(G, utility_graph)) 
41  
42 
def test_properties_named_small_graphs(self): 
43 
G = bull_graph() 
44 
assert_equal(G.number_of_nodes(), 5)

45 
assert_equal(G.number_of_edges(), 5)

46 
assert_equal(sorted(d for n, d in G.degree()), [1, 1, 2, 3, 3]) 
47 
assert_equal(diameter(G), 3)

48 
assert_equal(radius(G), 2)

49  
50 
G = chvatal_graph() 
51 
assert_equal(G.number_of_nodes(), 12)

52 
assert_equal(G.number_of_edges(), 24)

53 
assert_equal(list(d for n, d in G.degree()), 12 * [4]) 
54 
assert_equal(diameter(G), 2)

55 
assert_equal(radius(G), 2)

56  
57 
G = cubical_graph() 
58 
assert_equal(G.number_of_nodes(), 8)

59 
assert_equal(G.number_of_edges(), 12)

60 
assert_equal(list(d for n, d in G.degree()), 8 * [3]) 
61 
assert_equal(diameter(G), 3)

62 
assert_equal(radius(G), 3)

63  
64 
G = desargues_graph() 
65 
assert_equal(G.number_of_nodes(), 20)

66 
assert_equal(G.number_of_edges(), 30)

67 
assert_equal(list(d for n, d in G.degree()), 20 * [3]) 
68  
69 
G = diamond_graph() 
70 
assert_equal(G.number_of_nodes(), 4)

71 
assert_equal(sorted(d for n, d in G.degree()), [2, 2, 3, 3]) 
72 
assert_equal(diameter(G), 2)

73 
assert_equal(radius(G), 1)

74  
75 
G = dodecahedral_graph() 
76 
assert_equal(G.number_of_nodes(), 20)

77 
assert_equal(G.number_of_edges(), 30)

78 
assert_equal(list(d for n, d in G.degree()), 20 * [3]) 
79 
assert_equal(diameter(G), 5)

80 
assert_equal(radius(G), 5)

81  
82 
G = frucht_graph() 
83 
assert_equal(G.number_of_nodes(), 12)

84 
assert_equal(G.number_of_edges(), 18)

85 
assert_equal(list(d for n, d in G.degree()), 12 * [3]) 
86 
assert_equal(diameter(G), 4)

87 
assert_equal(radius(G), 3)

88  
89 
G = heawood_graph() 
90 
assert_equal(G.number_of_nodes(), 14)

91 
assert_equal(G.number_of_edges(), 21)

92 
assert_equal(list(d for n, d in G.degree()), 14 * [3]) 
93 
assert_equal(diameter(G), 3)

94 
assert_equal(radius(G), 3)

95  
96 
G = hoffman_singleton_graph() 
97 
assert_equal(G.number_of_nodes(), 50)

98 
assert_equal(G.number_of_edges(), 175)

99 
assert_equal(list(d for n, d in G.degree()), 50 * [7]) 
100 
assert_equal(diameter(G), 2)

101 
assert_equal(radius(G), 2)

102  
103 
G = house_graph() 
104 
assert_equal(G.number_of_nodes(), 5)

105 
assert_equal(G.number_of_edges(), 6)

106 
assert_equal(sorted(d for n, d in G.degree()), [2, 2, 2, 3, 3]) 
107 
assert_equal(diameter(G), 2)

108 
assert_equal(radius(G), 2)

109  
110 
G = house_x_graph() 
111 
assert_equal(G.number_of_nodes(), 5)

112 
assert_equal(G.number_of_edges(), 8)

113 
assert_equal(sorted(d for n, d in G.degree()), [2, 3, 3, 4, 4]) 
114 
assert_equal(diameter(G), 2)

115 
assert_equal(radius(G), 1)

116  
117 
G = icosahedral_graph() 
118 
assert_equal(G.number_of_nodes(), 12)

119 
assert_equal(G.number_of_edges(), 30)

120 
assert_equal(list(d for n, d in G.degree()), 
121 
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) 
122 
assert_equal(diameter(G), 3)

123 
assert_equal(radius(G), 3)

124  
125 
G = krackhardt_kite_graph() 
126 
assert_equal(G.number_of_nodes(), 10)

127 
assert_equal(G.number_of_edges(), 18)

128 
assert_equal(sorted(d for n, d in G.degree()), 
129 
[1, 2, 3, 3, 3, 4, 4, 5, 5, 6]) 
130  
131 
G = moebius_kantor_graph() 
132 
assert_equal(G.number_of_nodes(), 16)

133 
assert_equal(G.number_of_edges(), 24)

134 
assert_equal(list(d for n, d in G.degree()), 16 * [3]) 
135 
assert_equal(diameter(G), 4)

136  
137 
G = octahedral_graph() 
138 
assert_equal(G.number_of_nodes(), 6)

139 
assert_equal(G.number_of_edges(), 12)

140 
assert_equal(list(d for n, d in G.degree()), 6 * [4]) 
141 
assert_equal(diameter(G), 2)

142 
assert_equal(radius(G), 2)

143  
144 
G = pappus_graph() 
145 
assert_equal(G.number_of_nodes(), 18)

146 
assert_equal(G.number_of_edges(), 27)

147 
assert_equal(list(d for n, d in G.degree()), 18 * [3]) 
148 
assert_equal(diameter(G), 4)

149  
150 
G = petersen_graph() 
151 
assert_equal(G.number_of_nodes(), 10)

152 
assert_equal(G.number_of_edges(), 15)

153 
assert_equal(list(d for n, d in G.degree()), 10 * [3]) 
154 
assert_equal(diameter(G), 2)

155 
assert_equal(radius(G), 2)

156  
157 
G = sedgewick_maze_graph() 
158 
assert_equal(G.number_of_nodes(), 8)

159 
assert_equal(G.number_of_edges(), 10)

160 
assert_equal(sorted(d for n, d in G.degree()), [1, 2, 2, 2, 3, 3, 3, 4]) 
161  
162 
G = tetrahedral_graph() 
163 
assert_equal(G.number_of_nodes(), 4)

164 
assert_equal(G.number_of_edges(), 6)

165 
assert_equal(list(d for n, d in G.degree()), [3, 3, 3, 3]) 
166 
assert_equal(diameter(G), 1)

167 
assert_equal(radius(G), 1)

168  
169 
G = truncated_cube_graph() 
170 
assert_equal(G.number_of_nodes(), 24)

171 
assert_equal(G.number_of_edges(), 36)

172 
assert_equal(list(d for n, d in G.degree()), 24 * [3]) 
173  
174 
G = truncated_tetrahedron_graph() 
175 
assert_equal(G.number_of_nodes(), 12)

176 
assert_equal(G.number_of_edges(), 18)

177 
assert_equal(list(d for n, d in G.degree()), 12 * [3]) 
178  
179 
G = tutte_graph() 
180 
assert_equal(G.number_of_nodes(), 46)

181 
assert_equal(G.number_of_edges(), 69)

182 
assert_equal(list(d for n, d in G.degree()), 46 * [3]) 
183  
184 
# Test create_using with directed or multigraphs on small graphs

185 
assert_raises(networkx.exception.NetworkXError, tutte_graph, 
186 
create_using=DiGraph()) 
187 
MG = tutte_graph(create_using=MultiGraph()) 
188 
assert_equal(sorted(MG.edges()), sorted(G.edges())) 