ó žÃÒYc@smddlZddlZddlmZmZmZmZm Z ddl m Z ddl m Z mZddlmZd„Zd„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z!d„Z"d„Z#d„Z$d„Z%d„Z&d„Z'd„Z(d„Z)d„Z*d „Z+dS(!iÿÿÿÿN(t assert_equaltassert_not_equaltassert_greater_equalt assert_raisest assert_in(tpairwise(tbridge_componentstEdgeComponentAuxGraph(tgeneral_k_edge_subgraphscCsttt|ƒƒS(s' allows == to be used for list of sets (tsettmapt frozenset(t list_of_sets((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pytfsetscCsUxN|D]F}|j|ƒ}t|ƒdkrtj|ƒ}t||ƒqqWdS(s— tests properties of k-edge-connected subgraphs the actual edge connectivity should be no less than k unless the cc is a single node. iN(tsubgraphtlentnxtedge_connectivityR(tGt ccs_subgraphtktcctCt connectivity((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt"_assert_subgraph_edge_connectivitys  cCsm||f}||kr ||S|jƒsO||f}||krO||Sntj||Œ||<||S(N(t is_directedRR(Rtutvtmemotedgetredge((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt_memo_connectivity's      cCsvxotj|dƒD][\}}t||||ƒ}|jƒrat|t||||ƒƒ}nt||ƒqWdS(Ni(titt combinationsRRtminR(RRRRRRR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt_all_pairs_connectivity3s  !cCsjxc|D][}t|ƒdkr|j|ƒ}tj|ƒ}||krbt||||ƒqbqqWdS(sÌ tests properties of k-edge-connected components the local edge connectivity between each pair of nodes in the the original graph should be no less than k unless the cc is a single node. iN(RRRRR#(Rt ccs_localRRRRR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt"_assert_local_cc_edge_connectivity=s   c Csýtj|ƒ}i}xátjdƒD]Ð}t|j|ƒƒ}t|j|ƒƒ}t||||ƒt|||ƒ|dks|dkr°|j ƒ r°t ||dƒn|j ƒr|dkrˆtt j |ƒƒ}t ||dƒt ||dƒqˆn…|dkrGtt j |ƒƒ}t ||dƒt ||dƒnA|dkrˆtt|ƒƒ}t ||dƒt ||dƒntgt|d|ƒD]} t| jƒƒ^qžƒ} t | |dƒ|dkr%td„|Dƒƒr%Pq%q%Wd S( sê Helper - generates all k-edge-components using the aux graph. Checks the both local and subgraph edge connectivity of each cc. Also checks that alternate methods of computing the k-edge-ccs generate the same result. iisXSubgraphs and components should be the same when k == 1 or (k == 2 and not G.directed())sk=1 failed altsk=2 failed altRsalt subgraph method failedcss!|]}t|ƒdkVqdS(iN(R(t.0R((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pys …sN(Rt constructR tcountR tk_edge_componentstk_edge_subgraphsR%RRRRtstrongly_connected_componentstconnected_componentsRRR tnodestall( Rt aux_graphRRR$Rtalt_sccstalt_ccstalt_bridge_ccsRtalt_subgraph_ccs((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt_check_edge_connectivityPs:%      1 "cCs¥tjƒ}tttj|ddƒtttj|ddƒtj|ƒ}ttt|jddƒƒttt|jddƒƒtttt |ddƒƒdS(NRi( RtGraphRt ValueErrorR)R*RR'tlistR(RR/((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_zero_k_exceptions cCs¤tjƒ}tgttj|ddƒƒƒtgttj|ddƒƒƒtjƒ}tgttj|ddƒƒƒtgttj|ddƒƒƒdS(NRi(RR5RR7R)R*tDiGraph(R((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_empty_input›s  "" "cCsŠtjƒ}ttjtj|ƒttjtj|ddƒttjtj|ddƒttjt|ƒttjttj ƒƒdS(NRi( Rt MultiGraphRtNetworkXNotImplementedRR'R)R*RR9(R((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_not_implemented¥s  cCsÈtjƒ}|jdƒtt|ddƒƒ}tt|ƒdƒx!|D]}t|jƒdƒqKW|jdƒtt|ddƒƒ}tt|ƒdƒx!|D]}t|jƒdƒq§WdS(NiRii(RR5tadd_nodeR7RRRtnumber_of_nodes(Rt subgraphsR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt)test_general_k_edge_subgraph_quick_return®s     cCsCddg}x0|D](}tjddd|ƒ}t|ƒqWdS(NI]Z ¦ié¥%rigš™™™™™É?tseed(Rtgnp_random_graphR4(tseedsRBR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_random_gnpÂs  cCsƒdddddg}xg|D]_}tjdd|dd ƒ}tjtj|d|ƒƒ}|jtj|ƒƒt|ƒqWdS( NI¦0¢I´ªB“i&eIó.à²I©0 iRBttriesiˆ(Rtrandom_powerlaw_tree_sequenceR5tconfiguration_modeltremove_edges_fromtselfloop_edgesR4(RDRBtdeg_seqR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_configurationËs  cCsIdg}x9|D]1}d d g}tj|d|ƒ}t|ƒqWdS( Ni\)¡zi iFgš™™™™™é?ii(g333333ã?RB(i iFgš™™™™™é?(ii(g333333ã?(Rtrandom_shell_graphR4(RDRBt constructorR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt test_shellÔs    cCstjƒ}t|ƒdS(N(Rtkarate_club_graphR4(R((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt test_karateÝs c CsXdddddg}dddg}tjtjd„||DƒŒƒ}t|ƒdS(Niiiiiiiii i iiiii i ii css|]}t|ƒVqdS(N(R(R&tpath((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pys ës(iiiiii(iiii(ii i i(iiiii(i i ii i i(ii(ii(ii(RR5R tchainR4(tccstbridgesR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_tarjan_bridgeâs   &c CsËdddg}ddddg}tjtjd„||DƒŒƒ}tt|ƒƒ}tddddhd hdddhdd d hd hd hdhdhdhg ƒ}t||ƒt|ƒdS(Niiiiii i i i i iiiiiicss|]}t|ƒVqdS(N(R(R&RR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pys ós(iiiiii(ii i i(i i i i (ii(ii(ii(iii(RR5R RSR RRR4(tcc2RURt bridge_ccst target_ccs((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_bridge_ccïs&3! c Cs…d\ }}}}}}}}}|||||f|||f|||||||f||f|||f||fg} tjtjg| D]} t| ƒ^qŽŒƒ} tj| ƒ} t| jddƒƒ} t|||||||h||hgƒ}t || ƒttj| ddƒƒ}t || ƒt| jddƒƒ}t|||||||h|h|hgƒ}t ||ƒttj| ddƒƒ}t ||ƒt| jddƒƒ}t|h||||h|h|h|h|hgƒ}t ||ƒt| jddƒƒ}t|h|h|h|h|h|h|h|h|hg ƒ}t ||ƒt | ƒdS(Nt abcdefghiRiiii( RR5R RSRRR'R R*RR4(tatbtctdtetftgthtitpathsRRRR/t components_1ttarget_1talt_1t components_2ttarget_2talt_2t components_3ttarget_3t components_4ttarget_4((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_undirected_aux_graphýs4!   1-  0  9 B c Cs!ddddddg}tjtjg|D]}t|ƒ^q+Œƒ}tj|ƒ}t|jd ƒƒ}td hd hd hd hddddhddddhgƒ}t ||ƒt|j d ƒƒ}td hd hd hd hddddddddhgƒ}t ||ƒdS(Ni i i iiiiiieifigihi(i i i ii i ii (iiiiiiii(i iei(i ifi(i igi(iihi( RR5R RSRRR'R R*RR)(ReRRRR/t subgraph_ccstsubgraph_targett local_ccst local_target((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_local_subgraph_difference's  1' $cCsðddg}tjtjg|D]}t|ƒ^qŒƒ}tttj|ddƒƒttj|ddƒƒƒt ttj|ddƒƒttj|ddƒƒƒtttj|ddƒƒttj|ddƒƒƒt |ƒdS(NiiiiR(iiiii(iii( RR9R RSRRR R)R*RR4(tdipathsRRR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyt'test_local_subgraph_difference_directedBs 1cCsód d d g}tjtjg|D]}t|ƒ^q"Œƒ}tttj|ddƒƒttj|ddƒƒƒtttj|dd ƒƒttj|dd ƒƒƒtttj|dd ƒƒttj|dd ƒƒƒt |ƒdS(Ni i i iiiRiii(i i i i (iiii(i i( RR5R RSRRR R)R*R4(ReRRR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_triangles^s 1c Cs ddddddg}tjtjg|D]}t|ƒ^q+Œƒ}ttj|d d ƒƒ}ttj|d d ƒƒ}t||ƒt |dƒ}t |dƒ}t |j |ƒj d hƒ|ƒt ||ƒt ||ƒt |j d ƒd ƒt|ƒdS(Ni i i iiiiiidiÈi,Riii(i i i ii i ii (iiiiiiii(idi (i idi(i iÈi(ii,i(RR5R RSRR R)R*RR RtunionRtdegreeR4(ReRRRRsR@tclique1tclique2((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_four_cliqueys" 1 "  cCswtjtjdƒtjdƒƒ}d d ddg}|jtjg|D]}t|ƒ^qIŒƒttt tj |ƒƒj ƒƒd ƒtt tj |d dƒƒt tj|d dƒƒƒtt tj |d d ƒƒt tj|d d ƒƒƒtt tj |d dƒƒt tj|d dƒƒƒtt tj |d dƒƒt tj|d dƒƒƒt|ƒdS(NiiidiiiiiÈiiR(iidi(iidi(iiÈi(iiÈid(Rtdisjoint_uniontcomplete_graphtadd_edges_fromR RSRRR"tdictRztvaluesR R)R*RR4(RReRR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_five_cliquešs"$/(c Csûd\ }}}}}}}}}|||||f|||f|||||||f||f|||f||fg} tjtjg| D]} t| ƒ^qŽŒƒ} tj| ƒ} t| jddƒƒ} t|||||||h|h|hgƒ}t || ƒttj | ƒƒ}t || ƒt| jddƒƒ}t|h|h|h||||h|h|hgƒ}t ||ƒt| jddƒƒ}t|h|h|h|h|h|h|h|h|hg ƒ}t ||ƒdS(NR[Riii( RR9R RSRRR'R R*RR+(R\R]R^R_R`RaRbRcRdRvRRRR/RfRgRhRiRjRlRm((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_directed_aux_graphÄs(!   10  9 BcCsFdg}x6|D].}tjdddtd|ƒ}t|ƒqWdS(NI6h‚igš™™™™™É?tdirectedRB(RRCtTrueR4(RDRBR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_random_gnp_directedäs  cCswdg}xg|D]_}tjdd|ddƒ}tjtj|d|ƒƒ}|jtj|ƒƒt|ƒqWdS(NiC(iRBRFiˆ(RRGR9RHRIRJR4(RDRBRKR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_configuration_directedìs   cCsOdg}x?|D]7}d d g}tj|d|ƒjƒ}t|ƒqWdS( NI/uͺi iFgš™™™™™é?ii(g333333ã?RB(i iFgš™™™™™é?(ii(g333333ã?(RRMt to_directedR4(RDRBRNR((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_shell_directedös    cCs tjƒjƒ}t|ƒdS(N(RRPR‰R4(R((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyttest_karate_directedÿs(,tnetworkxRt itertoolsR t nose.toolsRRRRRtnetworkx.utilsRt networkx.algorithms.connectivityRRt1networkx.algorithms.connectivity.edge_kcomponentsRR RRR#R%R4R8R:R=RARERLRORQRVRZRpRuRwRxR}RƒR„R‡RˆRŠR‹(((s’/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/tests/test_edge_kcomponents.pyts@  (    =     *    ! *