<s> from nose . tools import assert_equal , assert_true , assert_false <EOL> import networkx as nx <EOL> def _generate_no_biconnected ( max_attempts = <NUM_LIT:50> ) : <EOL> attempts = <NUM_LIT:0> <EOL> while True : <EOL> G = nx . fast_gnp_random_graph ( <NUM_LIT:100> , <NUM_LIT> ) <EOL> if nx . is_connected ( G ) and not nx . is_biconnected ( G ) : <EOL> attempts = <NUM_LIT:0> <EOL> yield G <EOL> else : <EOL> if attempts >= max_attempts : <EOL> msg = "<STR_LIT>" <EOL> raise Exception ( msg % max_attempts ) <EOL> else : <EOL> attempts += <NUM_LIT:1> <EOL> def is_dominating_set ( G , nbunch ) : <EOL> allnodes = set ( G ) <EOL> testset = set ( n for n in nbunch if n in G ) <EOL> nbrs = set ( ) <EOL> for n in testset : <EOL> nbrs . update ( G [ n ] ) <EOL> if nbrs - allnodes : <EOL> return False <EOL> else : <EOL> return True <EOL> def test_average_connectivity ( ) : <EOL> G1 = nx . path_graph ( <NUM_LIT:3> ) <EOL> G1 . add_edges_from ( [ ( <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:4> ) ] ) <EOL> assert_equal ( nx . average_node_connectivity ( G1 ) , <NUM_LIT:1> ) <EOL> G2 = nx . path_graph ( <NUM_LIT:3> ) <EOL> G2 . add_edges_from ( [ ( <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:4> ) , ( <NUM_LIT:0> , <NUM_LIT:3> ) , ( <NUM_LIT:0> , <NUM_LIT:4> ) , ( <NUM_LIT:3> , <NUM_LIT:4> ) ] ) <EOL> assert_equal ( nx . average_node_connectivity ( G2 ) , <NUM_LIT> ) <EOL> G3 = nx . Graph ( ) <EOL> assert_equal ( nx . average_node_connectivity ( G3 ) , <NUM_LIT:0> ) <EOL> def test_articulation_points ( ) : <EOL> Ggen = _generate_no_biconnected ( ) <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> G = next ( Ggen ) <EOL> assert_equal ( nx . node_connectivity ( G ) , <NUM_LIT:1> ) <EOL> def test_brandes_erlebach ( ) : <EOL> G = nx . Graph ( ) <EOL> G . add_edges_from ( [ ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:4> ) , ( <NUM_LIT:1> , <NUM_LIT:5> ) , ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:2> , <NUM_LIT:6> ) , ( <NUM_LIT:3> , <NUM_LIT:4> ) , <EOL> ( <NUM_LIT:3> , <NUM_LIT:6> ) , ( <NUM_LIT:4> , <NUM_LIT:6> ) , ( <NUM_LIT:4> , <NUM_LIT:7> ) , ( <NUM_LIT:5> , <NUM_LIT:7> ) , ( <NUM_LIT:6> , <NUM_LIT:8> ) , ( <NUM_LIT:6> , <NUM_LIT:9> ) , ( <NUM_LIT:7> , <NUM_LIT:8> ) , <EOL> ( <NUM_LIT:7> , <NUM_LIT:10> ) , ( <NUM_LIT:8> , <NUM_LIT:11> ) , ( <NUM_LIT:9> , <NUM_LIT:10> ) , ( <NUM_LIT:9> , <NUM_LIT:11> ) , ( <NUM_LIT:10> , <NUM_LIT:11> ) ] ) <EOL> assert_equal ( <NUM_LIT:3> , nx . local_edge_connectivity ( G , <NUM_LIT:1> , <NUM_LIT:11> ) ) <EOL> assert_equal ( <NUM_LIT:3> , nx . edge_connectivity ( G , <NUM_LIT:1> , <NUM_LIT:11> ) ) <EOL> assert_equal ( <NUM_LIT:2> , nx . local_node_connectivity ( G , <NUM_LIT:1> , <NUM_LIT:11> ) ) <EOL> assert_equal ( <NUM_LIT:2> , nx . node_connectivity ( G , <NUM_LIT:1> , <NUM_LIT:11> ) ) <EOL> assert_equal ( <NUM_LIT:2> , nx . edge_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:2> , nx . node_connectivity ( G ) ) <EOL> def test_white_harary_1 ( ) : <EOL> G = nx . disjoint_union ( nx . complete_graph ( <NUM_LIT:4> ) , nx . complete_graph ( <NUM_LIT:4> ) ) <EOL> G . remove_node ( <NUM_LIT:7> ) <EOL> for i in range ( <NUM_LIT:4> , <NUM_LIT:7> ) : <EOL> G . add_edge ( <NUM_LIT:0> , i ) <EOL> G = nx . disjoint_union ( G , nx . complete_graph ( <NUM_LIT:4> ) ) <EOL> G . remove_node ( G . order ( ) - <NUM_LIT:1> ) <EOL> for i in range ( <NUM_LIT:7> , <NUM_LIT:10> ) : <EOL> G . add_edge ( <NUM_LIT:0> , i ) <EOL> assert_equal ( <NUM_LIT:1> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:3> , nx . edge_connectivity ( G ) ) <EOL> def test_white_harary_2 ( ) : <EOL> G = nx . disjoint_union ( nx . complete_graph ( <NUM_LIT:4> ) , nx . complete_graph ( <NUM_LIT:4> ) ) <EOL> G . add_edge ( <NUM_LIT:0> , <NUM_LIT:4> ) <EOL> assert_equal ( <NUM_LIT:3> , min ( nx . core_number ( G ) . values ( ) ) ) <EOL> assert_equal ( <NUM_LIT:1> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:1> , nx . edge_connectivity ( G ) ) <EOL> def test_complete_graphs ( ) : <EOL> for n in range ( <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> ) : <EOL> G = nx . complete_graph ( n ) <EOL> assert_equal ( n - <NUM_LIT:1> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( n - <NUM_LIT:1> , nx . node_connectivity ( G . to_directed ( ) ) ) <EOL> assert_equal ( n - <NUM_LIT:1> , nx . edge_connectivity ( G ) ) <EOL> assert_equal ( n - <NUM_LIT:1> , nx . edge_connectivity ( G . to_directed ( ) ) ) <EOL> def test_empty_graphs ( ) : <EOL> for k in range ( <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> ) : <EOL> G = nx . empty_graph ( k ) <EOL> assert_equal ( <NUM_LIT:0> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:0> , nx . edge_connectivity ( G ) ) <EOL> def test_petersen ( ) : <EOL> G = nx . petersen_graph ( ) <EOL> assert_equal ( <NUM_LIT:3> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:3> , nx . edge_connectivity ( G ) ) <EOL> def test_tutte ( ) : <EOL> G = nx . tutte_graph ( ) <EOL> assert_equal ( <NUM_LIT:3> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:3> , nx . edge_connectivity ( G ) ) <EOL> def test_dodecahedral ( ) : <EOL> G = nx . dodecahedral_graph ( ) <EOL> assert_equal ( <NUM_LIT:3> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:3> , nx . edge_connectivity ( G ) ) <EOL> def test_octahedral ( ) : <EOL> G = nx . octahedral_graph ( ) <EOL> assert_equal ( <NUM_LIT:4> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:4> , nx . edge_connectivity ( G ) ) <EOL> def test_icosahedral ( ) : <EOL> G = nx . icosahedral_graph ( ) <EOL> assert_equal ( <NUM_LIT:5> , nx . node_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:5> , nx . edge_connectivity ( G ) ) <EOL> def test_directed_edge_connectivity ( ) : <EOL> G = nx . cycle_graph ( <NUM_LIT:10> , create_using = nx . DiGraph ( ) ) <EOL> D = nx . cycle_graph ( <NUM_LIT:10> ) . to_directed ( ) <EOL> assert_equal ( <NUM_LIT:1> , nx . edge_connectivity ( G ) ) <EOL> assert_equal ( <NUM_LIT:1> , nx . local_edge_connectivity ( G , <NUM_LIT:1> , <NUM_LIT:4> ) ) <EOL> assert_equal ( <NUM_LIT:1> , nx . edge_connectivity ( G , <NUM_LIT:1> , <NUM_LIT:4> ) ) <EOL> assert_equal ( <NUM_LIT:2> , nx . edge_connectivity ( D ) ) <EOL> assert_equal ( <NUM_LIT:2> , nx . local_edge_connectivity ( D , <NUM_LIT:1> , <NUM_LIT:4> ) ) <EOL> assert_equal ( <NUM_LIT:2> , nx . edge_connectivity ( D , <NUM_LIT:1> , <NUM_LIT:4> ) ) <EOL> def test_dominating_set ( ) : <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> G = nx . gnp_random_graph ( <NUM_LIT:100> , <NUM_LIT:0.1> ) <EOL> D = nx . dominating_set ( G ) <EOL> assert_true ( is_dominating_set ( G , D ) ) </s>
