o
    &?eW                     @   sV   d Z ddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 eZG dd dZdS )z
====================
Generators - Classic
====================

Unit tests for various classic graph generators in generators/classic.py
    N)graph_could_be_isomorphic)edges_equalnodes_equalc                   @   sl  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYS )ZTestGeneratorClassicc                 C   s   dD ]h\}}t ||}| }|||d  d |d  ks J t |s'J | |d ks1J t |}|d dks>J |d || ksHJ || dksPJ ||d  |||  d ks`J t||d ksjJ qd S )N))   r   )   r   )   r      r   r   )nxbalanced_treeorderis_connectedsizedegree_histogramlen)selfrhtr   dh r   g/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/networkx/generators/tests/test_classic.pytest_balanced_tree   s    
 z'TestGeneratorClassic.test_balanced_treec                 C   sj   t jddd}t|t dsJ t jddd}t|t ds"J t jddd}t|t ds3J d S )Nr   r	   )r   r      
   )r
   r   is_isomorphic
star_graphr   r   r   r   r   test_balanced_tree_star$   s   z,TestGeneratorClassic.test_balanced_tree_starc                 C   s(   t dd}t d}t||sJ dS )z[Tests that the balanced tree with branching factor one is the
        path graph.

        r	      r   N)r
   r   
path_graphr   )r   TPr   r   r   test_balanced_tree_path-   s   
z,TestGeneratorClassic.test_balanced_tree_pathc                 C   s   d}d}t ||}| |ksJ t |sJ t |}|d dks&J |d dks.J || dks6J ||d  dks@J t||d ksJJ d S )Nr   	   r   r	   r   r   )r
   full_rary_treer   r   r   r   )r   r   nr   r   r   r   r   test_full_rary_tree7   s   
z(TestGeneratorClassic.test_full_rary_treec                 C   s*   t dd}t dd}t||sJ d S )Nr      r   )r
   r%   r   r   )r   r   thr   r   r   test_full_rary_tree_balancedD   s   z1TestGeneratorClassic.test_full_rary_tree_balancedc                 C   s$   t dd}t|t dsJ d S )Nr	   r   )r
   r%   r   r    r   r   r   r   test_full_rary_tree_pathI   s   z-TestGeneratorClassic.test_full_rary_tree_pathc                 C   sD   t dd}t|t dsJ t dd}t|t ds J d S )Nr   r   r   )r
   r%   r   empty_graphr   r   r   r   test_full_rary_tree_emptyM   s   z.TestGeneratorClassic.test_full_rary_tree_emptyc                 C   s    t dd}| dksJ d S )Nr      )r
   r%   r   r   r   r   r   test_full_rary_tree_3_20S   s   z-TestGeneratorClassic.test_full_rary_tree_3_20c                 C   s  d}d}t ||}t |d| | ksJ t |||d  | d ks(J d}d}t ||}t |d| | ks?J t |||d  | d ksPJ d}d}t ||}t |d| | ksgJ t |||d  | d ksxJ d}d}tt jt j|| d}d}tt jt j|| d}d}t ||}t|t |d sJ d}d}t ||}t|t |d sJ d}d}t ||}t|t |d sJ tjt jt j||t 	 d	 t j||t 
 d	}t| | sJ d S )
Nr   r   r   r	   r   r   r.   create_using)r
   Zbarbell_graphnumber_of_nodesnumber_of_edgespytestraisesNetworkXErrorr   r    DiGraph
MultiGraphr   edges)r   m1m2bmbr   r   r   test_barbell_graphW   sL   """z'TestGeneratorClassic.test_barbell_graphc                 C   sn   d t jt jt jt jf}|D ]'}tdD ] }t ||}t |d| ks&J t |d| d ks3J qqd S )Nr   r   r	   )	r
   Graphr8   r9   MultiDiGraphrangeZbinomial_treer3   r4   )r   Zgraphsr2   r&   r=   r   r   r   test_binomial_tree   s   z'TestGeneratorClassic.test_binomial_treec                 C   s  dD ]}t |}t ||ksJ t |||d  d ks!J qt j|t jd}t| | s5J t d}t| g dsEJ |	 dksMJ t d}t| g ds]J |	 d	kseJ t jdt jd}t| g dsxJ |	 d
ksJ d S )Nr   r	   r   r   r	   r   r1   abc)ar=   cr   abcbr   r   )
r
   complete_graphr3   r4   r9   r   r:   r   nodesr   )r   mgmgr   r   r   test_complete_graph   s   
 

z(TestGeneratorClassic.test_complete_graphc                 C   s   dD ] }t j|t jd}t ||ksJ t |||d  ks"J qt jdt jd}t|dks3J | dks;J | sAJ d S )NrD   r1   r	   rE   r   r   )r
   rI   r8   r3   r4   r   r   is_directed)r   rK   rL   r   r   r   test_complete_digraph   s   z*TestGeneratorClassic.test_complete_digraphc                 C   sL   t d}tjt jt jdt jd t jdt jd}t| | s$J d S )Nr   r1   )	r
   Zcircular_ladder_graphr5   r6   r7   r8   r9   r   r:   )r   GmGr   r   r   test_circular_ladder_graph   s   
z/TestGeneratorClassic.test_circular_ladder_graphc                 C   s   t ddg}t d}t| | sJ t dg d}t d}t| | s/J t dddg}t dd}t||sDJ d S )Nr   r	      r	   r   r   r   )r
   Zcirculant_graphcycle_graphr   r:   rI   complete_bipartite_graphr   )r   ZCi6_1ZC6ZCi7ZK7ZCi6_1_3ZK3_3r   r   r   test_circulant_graph   s   

z)TestGeneratorClassic.test_circulant_graphc                 C   sB  t d}t| g dsJ t jdt jd}t| g ds#J t jdt jd}|ddr3J |dds;J | sAJ t d}t|dksNJ |	 dksVJ t d}t|dkscJ |	 dkskJ t dt j}t|dkszJ |	 dksJ | sJ t dt j}t|dksJ |	 dksJ d S )	Nr   )r   r	   )r   r   r	   r   )r   r   r1   r   r	   rE   r   rH   )
r
   rV   r   r:   r9   r8   has_edgerO   r   r   )r   rQ   rR   rL   r   r   r   test_cycle_graph   s*   


z%TestGeneratorClassic.test_cycle_graphc                 C   s  t d}t| dgsJ tt|ddgsJ t d}t| g ds*J t |dks3J tt |	 g dksBJ t d}t 
|dksPJ t |d	ksYJ |dd
ksbJ |dd
kskJ |dd
kstJ tjt jt jdt jd tjt jt jdt jd d S )Nr   rY   r	   )rY   )r   r   rZ   g      ?)r	   r	   r	   r   iVs  i  i   r   rT   r1   )r
   Z dorogovtsev_goltsev_mendes_graphr   r:   r   listZaverage_clusteringsortedZ	trianglesvaluesr3   r4   degreer5   r6   r7   r8   r9   )r   rQ   r   r   r   %test_dorogovtsev_goltsev_mendes_graph   s2   



z:TestGeneratorClassic.test_dorogovtsev_goltsev_mendes_graphc                 C   s  t  }t|t jsJ tjtt jdd tjtt jdd t jt jd}t|t js-J t jt jd}t|t js<J t jt jt jd}t|t jsMJ t jd t jd}t|t js]J t jt jd}t|t jslJ t 	d}t j|d}|
 r}J | rJ t|dksJ ||u sJ t jt  d}|
 sJ | rJ ||usJ G dd	 d	tj}G d
d d|t j}t j|d}d S )Ng        r1   r@   )r2   default)rb   r   r   c                   @      e Zd ZdS )z5TestGeneratorClassic.test_create_using.<locals>.MixinN__name__
__module____qualname__r   r   r   r   Mixin%      rh   c                   @   rc   )z7TestGeneratorClassic.test_create_using.<locals>.MyGraphNrd   r   r   r   r   MyGraph(  ri   rj   )r
   r,   
isinstancer@   r5   r6   	TypeErrorr9   r8   r    Zis_multigraphrO   r   typingProtocol)r   rQ   Hrh   rj   r   r   r   test_create_using  s6   
z&TestGeneratorClassic.test_create_usingc                 C   sT  t  }t |dksJ t d}t |dksJ t |dks$J t d}t|dks1J | dks9J t jdt jddd}t |dksMJ t |dksVJ t|t js^J t jdt jddd}t |dksrJ t |dks{J t|t jsJ t 	 }t jd|d}t |dksJ t |dksJ t|t j
sJ d S )Nr   *   rE   r   Zduh)namer1   )r
   r,   r3   r4   r   r   r8   rk   r9   Zpetersen_graphr@   )r   rQ   Zpeter   r   r   test_empty_graph-  s*   

z%TestGeneratorClassic.test_empty_graphc                 C   s   dt dfdt dfdt dfdt ddgffD ]\}}tt ||s*J qtjt j	t jdt j
d t d}t jdt jd}t| | sOJ d S )Nr   r	   r   r   r1   )r
   r,   r    Zhypercube_graphZ
grid_graphr   Zladder_graphr5   r6   r7   r8   r9   r   r:   )r   irQ   rL   rM   r   r   r   test_ladder_graphK  s   
z&TestGeneratorClassic.test_ladder_graphc                 C   s   dD ]&\}}t ||}t ||| ksJ t |||d  d | ks(J qdD ]/\}}t|t|}}t ||}t ||| ksIJ t |||d  d | ksZJ q+d S )N)r   r   r   r   r   r.   r	   r   )ab rE   Zdefg)r
   lollipop_graphr3   r4   r   r   r;   r<   rQ   firstsecondr   r   r   test_lollipop_graph_right_sizesZ  s   $$z4TestGeneratorClassic.test_lollipop_graph_right_sizesc                 C   s   t tjtjdd t tjtjdd t tjtjdd t tjtjdd t tjtjdd t tj tjddtjd	 W d    n1 sLw   Y  t tj tjddtjd	 W d    d S 1 slw   Y  d S )
Nr   r	   r.   r{   rF   r   r0   r1   )r5   r6   r
   r7   r}   r8   rA   r   r   r   r   test_lollipop_graph_exceptionsg  s   "z3TestGeneratorClassic.test_lollipop_graph_exceptionsc                 C   6   dD ]\}}t ||}t|t |d sJ qd S N))r   r   )r   r   )r   r   )rz   r.   r   )r
   r}   r   r    r   r;   r<   rQ   r   r   r   -test_lollipop_graph_same_as_path_when_m1_is_2w     zBTestGeneratorClassic.test_lollipop_graph_same_as_path_when_m1_is_2c                 C   8   t dd}t jddt jd}t| | sJ d S Nr   r.   r1   )r
   r}   r9   r   r:   r   rQ   ZMGr   r   r   "test_lollipop_graph_for_multigraph}     z7TestGeneratorClassic.test_lollipop_graph_for_multigraphc                 C   sZ   ddg ddfdg dfg}|D ]\}}t ||}t|dks"J | dks*J qd S )	Nr   rE   abcdr   r	   r   r   r   rE   r   rU   rT   r$   )r
   r}   r   r   r   casesr;   r<   rQ   r   r   r   &test_lollipop_graph_mixing_input_types     z;TestGeneratorClassic.test_lollipop_graph_mixing_input_typesc                 C   sF   t d}t|d|d}t|dksJ | dks!J d S )Nnumpyr   r   rT   r$   )r5   importorskipr
   r}   int32int64r   r   r   nprQ   r   r   r   *test_lollipop_graph_not_int_integer_inputs     
z?TestGeneratorClassic.test_lollipop_graph_not_int_integer_inputsc                 C      t t  dksJ d S )Nr   )r
   r3   
null_graphr   r   r   r   test_null_graph     z$TestGeneratorClassic.test_null_graphc                 C   s  t d}t|t  sJ t d}t|t dsJ t d}t |s)J tdd | D g dks:J | d |	 ksFJ t jdt j
d}|ddsVJ |ddr^J t jdt jd}t| | sqJ t d	}t|dks~J |	 d
ksJ t d}t|dksJ |	 d
ksJ t d	t j
}t|dksJ |	 d
ksJ | sJ t dt j
}t|dksJ |	 dksJ t d}|d
dsJ d S )Nr   r	   r   c                 s       | ]\}}|V  qd S Nr   .0r&   dr   r   r   	<genexpr>      z7TestGeneratorClassic.test_path_graph.<locals>.<genexpr>)
r	   r	   r   r   r   r   r   r   r   r   r   r1   rE   r   rH   )r	   r   r   r   r   r   )r
   r    r   r   r,   r   r^   r`   r   r   r8   r[   r9   r   r:   r   rO   )r   pZdpmprQ   rL   r   r   r   test_path_graph  s8   


"


z$TestGeneratorClassic.test_path_graphc                 C   s  t tdtdsJ t tg tdsJ t tdtds'J t tdtds4J t tdtdsAJ t tdtddsOJ td}tdd	 | D g d
kseJ tj	tj
tjdtjd tjdtjd}t| | sJ td}t|dksJ | dksJ td}t|dksJ | dksJ tjdtjd}t|dksJ | dksJ td}t|dksJ | dksJ d S )Nr{   r   r	   r   r   r   r   c                 s   r   r   r   r   r   r   r   r     r   z7TestGeneratorClassic.test_star_graph.<locals>.<genexpr>)r	   r	   r	   r	   r	   r	   r	   r	   r	   r	   r   r1   rE   rH   ZabcdefgrT   r   )r   r
   r   r,   r    rW   r^   r`   r5   r6   r7   r8   r9   r   r:   r   r   )r   smsrQ   r   r   r   test_star_graph  s.   
"


z$TestGeneratorClassic.test_star_graphc                 C   s>   t d}t|d}t|dksJ | dksJ d S )Nr   r   r   )r5   r   r
   r   r   r   r   r   r   r   r   $test_non_int_integers_for_star_graph     
z9TestGeneratorClassic.test_non_int_integers_for_star_graphc                 C   s   dD ]$\}}t ||}t ||| ksJ t ||| |dk ks&J qdD ]8\}}t|t|}}t|| t ||}t|  t ||| ksRJ t ||| |dk ksaJ q)d S )N))r   r   rv   rw   rx   r   )ry   )rz   rG   r|   )r
   tadpole_graphr3   r4   r   printr:   r~   r   r   r   test_tadpole_graph_right_sizes  s    
 z3TestGeneratorClassic.test_tadpole_graph_right_sizesc                 C   s   t tjtjdd t tjtjdd t tjtjdd t tjtjdd t tj tjddtjd	 W d    n1 sBw   Y  t tj tjddtjd	 W d    d S 1 sbw   Y  d S )
Nr   r   r   r	   r   r0   r   r.   r1   )r5   r6   r
   r7   r   r8   rA   r   r   r   r   test_tadpole_graph_exceptions  s   "z2TestGeneratorClassic.test_tadpole_graph_exceptionsc                 C   r   r   )r
   r   r   r    r   r   r   r   1test_tadpole_graph_same_as_path_when_m1_is_2_or_0  r   zFTestGeneratorClassic.test_tadpole_graph_same_as_path_when_m1_is_2_or_0c                 C   s2   dD ]\}}t ||}t|t |sJ qd S )N))r   r   )rT   r   )r
   r   r   rV   r   r   r   r   -test_tadpole_graph_same_as_cycle_when_m2_is_0   s   zBTestGeneratorClassic.test_tadpole_graph_same_as_cycle_when_m2_is_0c                 C   r   r   )r
   r   r9   r   r:   r   r   r   r   !test_tadpole_graph_for_multigraph  r   z6TestGeneratorClassic.test_tadpole_graph_for_multigraphc                 C   sZ   ddg ddfdg dfg}|D ]\}}t ||}t|dks"J | dks*J qd S )Nr   r   r   rE   r   rU   rT   )r
   r   r   r   r   r   r   r   %test_tadpole_graph_mixing_input_types  r   z:TestGeneratorClassic.test_tadpole_graph_mixing_input_typesc                 C   sF   t d}t|d|d}t|dksJ | dks!J d S )Nr   r   r   rT   )r5   r   r
   r   r   r   r   r   r   r   r   r   )test_tadpole_graph_not_int_integer_inputs  r   z>TestGeneratorClassic.test_tadpole_graph_not_int_integer_inputsc                 C   r   )Nr	   )r
   r3   Ztrivial_graphr   r   r   r   test_trivial_graph  r   z'TestGeneratorClassic.test_trivial_graphc                 C   s@   t t dddksJ tt ddt ddddsJ d S )N   r   ?   r   )r
   r4   Zturan_graphr   complete_multipartite_graphr   r   r   r   test_turan_graph  s   z%TestGeneratorClassic.test_turan_graphc              	   C   s\  dt  fdt  fdt dfdt dfdt dfdt dffD ]\}}t |}t||s4J q$t d}tdd	 | D g d
ksKJ t	j
t jt jdt jd t jdt  d}t| | skJ t d}t|dksxJ | dksJ t d}t|dksJ | dksJ t dt j}t|dksJ | dksJ d S )Nr{   r   r	   r   r   r   r   c                 s   r   r   r   r   r   r   r   r   /  r   z8TestGeneratorClassic.test_wheel_graph.<locals>.<genexpr>)
r   r   r   r   r   r   r   r   r   r$   r1   rE   rH   r   )r
   r   r,   r    rI   wheel_graphr   r^   r`   r5   r6   r7   r8   r9   r   r:   r   r   )r   r&   rQ   rL   rM   r   r   r   test_wheel_graph"  s.   



"

z%TestGeneratorClassic.test_wheel_graphc                 C   s>   t d}t|d}t|dksJ | dksJ d S )Nr   r   )r5   r   r
   r   r   r   r   r   r   r   r   %test_non_int_integers_for_wheel_graphA  r   z:TestGeneratorClassic.test_non_int_integers_for_wheel_graphc                 C   s8   t  }t  }t||sJ t| | sJ dS )z:Tests that the complete 0-partite graph is the null graph.N)r
   r   r   r   r   r:   r   rQ   ro   r   r   r   test_complete_0_partite_graphG  s   z2TestGeneratorClassic.test_complete_0_partite_graphc                 C   s<   t d}t d}t||sJ t| | sJ dS )z;Tests that the complete 1-partite graph is the empty graph.r   N)r
   r   r,   r   r   r:   r   r   r   r   test_complete_1_partite_graphN  s   

z2TestGeneratorClassic.test_complete_1_partite_graphc                 C   s@   t dd}t dd}t||sJ t| | sJ dS )zZTests that the complete 2-partite graph is the complete bipartite
        graph.

        r   r   N)r
   r   rW   r   r   r:   r   r   r   r   test_complete_2_partite_graphU  s   z2TestGeneratorClassic.test_complete_2_partite_graphc                 C   s   t ddd}g d}|D ]!}t|dD ]\}}||| vs!J |j| |j| ks-J qqt|dD ]#\}}t||D ]\}}||| v sKJ |j| |j| ksWJ q?q5tjt j	dd t ddd W d   dS 1 stw   Y  dS )	z5Tests for generating the complete multipartite graph.r   r   r   )rY   )r   r   r   )r   r   rT      zNegative number of nodes)matchN)
r
   r   	itertoolscombinations_with_replacementrJ   combinationsproductr5   r6   r7   )r   rQ   blocksblockuvZblock1Zblock2r   r   r    test_complete_multipartite_graph_  s   "z5TestGeneratorClassic.test_complete_multipartite_graphN)/re   rf   rg   r   r   r#   r'   r*   r+   r-   r/   r?   rC   rN   rP   rS   rX   r\   ra   rp   rs   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      sZ    	
6'$
r   )__doc__r   rm   r5   Znetworkxr
   Z(networkx.algorithms.isomorphism.isomorphr   Znetworkx.utilsr   r   r   r   r   r   r   r   <module>   s    