o
    ˷e^L                     @   sN   d 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                   @   s4  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'dKS )L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   ]/var/www/ideatree/venv/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_tree6   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_balancedC   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_pathH   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_emptyL   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_20R   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
   barbell_graphnumber_of_nodesnumber_of_edgespytestraisesNetworkXErrorr   r    DiGraph
MultiGraphr   edges)r   m1m2bmbr   r   r   test_barbell_graphV   sL   """z'TestGeneratorClassic.test_barbell_graphc                 C   sp   d t jt jt jt jf}|D ](}tddD ] }t ||}t |d| ks'J t |d| d ks4J qqd S )Nr   r   r   r	   )	r
   Graphr9   r:   MultiDiGraphrangebinomial_treer4   r5   )r   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_graphr4   r5   r:   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 )NrG   r1   r	   rH   r   r   )r
   rL   r9   r4   r5   r   r   is_directed)r   rN   rO   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
   circular_ladder_graphr6   r7   r8   r9   r:   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
   circulant_graphcycle_graphr   r;   rL   complete_bipartite_graphr   )r   Ci6_1C6Ci7K7Ci6_1_3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	   rH   r   rK   )
r
   r[   r   r;   r:   r9   has_edgerR   r   r   )r   rU   rV   rO   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   rd   r	   )rd   )r   r   re   g      ?)r	   r	   r	   r   iVs  i  i   r   rX   r1   )r
    dorogovtsev_goltsev_mendes_graphr   r;   r   listaverage_clusteringsorted	trianglesvaluesr4   r5   degreer6   r7   r8   r9   r:   )r   rU   r   r   r   %test_dorogovtsev_goltsev_mendes_graph   s2   



z:TestGeneratorClassic.test_dorogovtsev_goltsev_mendes_graphc                 C   sZ  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 d S )Ng        r1   rA   )r2   default)rp   r   r   )r
   r,   
isinstancerA   r6   r7   	TypeErrorr:   r9   r    is_multigraphrR   r   r   rU   Hr   r   r   test_create_using  s0   
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   *   rH   r   duh)namer1   )r
   r,   r4   r5   r   r   r9   rq   r:   petersen_graphrA   )r   rU   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    hypercube_graph
grid_graphr   ladder_graphr6   r7   r8   r9   r:   r   r;   )r   irU   rO   rP   r   r   r   test_ladder_graphA  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 )rH   defg)r
   lollipop_graphr4   r5   r   )r   r<   r=   rU   firstsecondr   r   r   test_lollipop_graph_right_sizesP  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   rI   r   r0   r1   )r6   r7   r
   r8   r   r9   rB   r   r   r   r   test_lollipop_graph_exceptions]  s   "z3TestGeneratorClassic.test_lollipop_graph_exceptionsc                 C   s6   dD ]\}}t ||}t|t |d sJ qd S )N))r   r   )r   r   )r   r   )r   r.   r   )r
   r   r   r    )r   r<   r=   rU   r   r   r   -test_lollipop_graph_same_as_path_when_m1_is_2m  s   zBTestGeneratorClassic.test_lollipop_graph_same_as_path_when_m1_is_2c                 C   s8   t dd}t jddt jd}t| | sJ d S )Nr   r.   r1   )r
   r   r:   r   r;   )r   rU   MGr   r   r   "test_lollipop_graph_for_multigraphs  s   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   rH   )abcdr   )r	   r   r   r   rH   r   rY   rX   r$   )r
   r   r   r   )r   casesr<   r=   rU   r   r   r   &test_lollipop_graph_mixing_input_typesx  s   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   rX   r$   )r6   importorskipr
   r   int32int64r   r   r   nprU   r   r   r   *test_lollipop_graph_not_int_integer_inputs  s   
z?TestGeneratorClassic.test_lollipop_graph_not_int_integer_inputsc                 C      t t  dksJ d S )Nr   )r
   r4   
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   rH   r   rK   )r	   r   r   r   r   r   )r
   r    r   r   r,   r   rk   rn   r   r   r9   rf   r:   r   r;   r   rR   )r   pdpmprU   rO   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   rH   rK   abcdefgrX   r   )r   r
   r   r,   r    r\   rk   rn   r6   r7   r8   r9   r:   r   r;   r   r   )r   smsrU   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   )r6   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   r   )Nr	   )r
   r4   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
   r5   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   rH   rK   r   )r
   r   r,   r    rL   wheel_graphr   rk   rn   r6   r7   r8   r9   r:   r   r;   r   r   )r   r&   rU   rO   rP   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   )r6   r   r
   r   r   r   r   r   r   r   r   %test_non_int_integers_for_wheel_graph  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;   rt   r   r   r   test_complete_0_partite_graph   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;   rt   r   r   r   test_complete_1_partite_graph  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   r\   r   r   r;   rt   r   r   r   test_complete_2_partite_graph  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?q5dS )z5Tests for generating the complete multipartite graph.r   r   r   )rd   )r   r   r   )r   r   rX      N)r
   r   	itertoolscombinations_with_replacementrM   combinationsproduct)r   rU   blocksblockuvblock1block2r   r   r    test_complete_multipartite_graph  s   z5TestGeneratorClassic.test_complete_multipartite_graphN)(__name__
__module____qualname__r   r   r#   r'   r*   r+   r-   r/   r@   rF   rQ   rS   rW   rc   rg   ro   rv   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      sL    	
6$
r   )__doc__r   r6   networkxr
   (networkx.algorithms.isomorphism.isomorphr   networkx.utilsr   r   r   r   r   r   r   r   <module>   s    