@@ -99,3 +99,40 @@ def is_constant(d):
9999 print (d1 , d2 , sp , r )
100100
101101 assert (math .isnan (sp ) and math .isnan (r )) or sp == pytest .approx (r )
102+
103+
104+ @given (undirected_network (max_verts = 30 ))
105+ def test_connected_components (net ):
106+ ccs = ret .connected_components (net )
107+
108+ # check that it is a partition
109+ assert set (net .vertices ()) == set ().union (* ccs )
110+
111+ lcc = ret .largest_connected_component (net )
112+ if ccs :
113+ assert lcc == max (ccs , key = len )
114+ else :
115+ assert list (lcc ) == []
116+
117+ connected_subgraph = ret .vertex_induced_subgraph (net , lcc )
118+ assert ret .is_connected (connected_subgraph )
119+
120+ from itertools import product
121+ for cc in ccs :
122+ for v in cc :
123+ assert ret .connected_component (net , v ) == cc
124+
125+ for v1 , v2 in product (cc , repeat = 2 ):
126+ assert ret .is_reachable (net , v1 , v2 )
127+
128+ from itertools import combinations
129+ for c1 , c2 in combinations (ccs , r = 2 ):
130+ for v1 , v2 in product (c1 , c2 ):
131+ assert not ret .is_reachable (net , v1 , v2 )
132+ assert not ret .is_reachable (net , v2 , v1 )
133+
134+
135+ @given (undirected_network (self_loops = False ))
136+ def test_graphicality (net ):
137+ degs = ret .degree_sequence (net )
138+ assert ret .is_graphic (degs )
0 commit comments