U
    ?h/                     @   s<   d dl Z d dlZd dlmZ G dd dZG dd dZdS )    N)convert_node_labels_to_integersc                   @   s   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!S )"TestCliquesc                 C   s   dddddddddddg}t tj|dd| _tt| j| _td}t	|dd t
dD }|d	d
dddg || _d S )N            )Zfirst_label   c                 S   s   i | ]}||d  qS r    ).0ir
   r
   W/var/www/html/venv/lib/python3.8/site-packages/networkx/algorithms/tests/test_clique.py
<dictcomp>   s      z,TestCliques.setup_method.<locals>.<dictcomp>)r   r   )r      )r   r   )r   r   )r   r   )cnltinx
generatorsZhavel_hakimi_graphGlistfind_cliquesclZcomplete_graphrelabel_nodesrangeZremove_edges_fromH)selfzr   r
   r
   r   setup_method   s    
zTestCliques.setup_methodc                 C   s   t t| j}t| j}ddddgdddgdddgdd	gd
dgg}ttt|ttt|ksftttt|ttt|kstd S )Nr   r   r   r   r   r         	   
      )r   r   r   r   find_cliques_recursivesortedmapAssertionErrorr   r   rclexpectedr
   r
   r   test_find_cliques1   s
    * zTestCliques.test_find_cliques1c                    s   | j dd tt| j }tt| j }ttt|ttt|ksNt	ddddhdddhdddhdd	hd
dhg t
 t
|kst	t fdd|D st	d S )Nr   r   r   r   r   r   r   r   r   r    r!   c                 3   s   | ]}t | kV  qd S Nsetr   canswerr
   r   	<genexpr>   s     z-TestCliques.test_selfloops.<locals>.<genexpr>)r   Zadd_edger   r   r   r"   r,   r$   	frozensetr%   lenall)r   r   r'   r
   r/   r   test_selfloops   s     *zTestCliques.test_selfloopsc                 C   sH   t t| j}ttt|ddgddddgddgdddggksDtd S )Nr   r   r   r   r   r   )r   r   r   r   r#   r$   r%   )r   hclr
   r
   r   test_find_cliques2!   s    zTestCliques.test_find_cliques2c              	   C   sL  t t| jdg}t| jdg}ddddgdddgg}ttt|ttt|ksZtttt|ttt|ksztt t| jddg}t| jddg}ddddgg}ttt|ttt|kstttt|ttt|kstt t| jdddg}t| jdddg}dddgg}ttt|ttt|ksJtttt|ttt|ksltt t| jdddg}t| jdddg}dddgg}ttt|ttt|kstttt|ttt|kstt	t
  t t| jddddg W 5 Q R X t	t
  t t| jddddg W 5 Q R X d S )Nr   r   r   r   r   )r   r   r   r   r"   r#   r$   r%   pytestraises
ValueErrorr&   r
   r
   r   test_find_cliques3%   s0        """"$zTestCliques.test_find_cliques3c              	   C   s\   | j }t  t|dks"tW 5 Q R X t  tj|| jddksNtW 5 Q R X d S )Nr   cliques)r   r8   deprecated_callr   graph_clique_numberr%   r   r   r   r
   r
   r   test_clique_numberF   s
    

zTestCliques.test_clique_numberc              	   C   sB   t  }|dddg t  t |dks4tW 5 Q R X d S )Nr   r   r   )r   GraphZadd_nodes_fromr8   r>   r?   r%   r@   r
   r
   r   test_clique_number2M   s    
zTestCliques.test_clique_number2c              	   C   s2   t  }t  t |dks$tW 5 Q R X d S )Nr   )r   rB   r8   r>   r?   r%   r@   r
   r
   r   test_clique_number3S   s    
zTestCliques.test_clique_number3c                 C   s  | j }t  t|dks"tW 5 Q R X t  tj|| jddksNtW 5 Q R X t  t|ddksvtW 5 Q R X t & tt|dg	 dgkstW 5 Q R X t * tt|ddg	 ddgkstW 5 Q R X t & t|ddgdddkstW 5 Q R X t  t|ddks@tW 5 Q R X t 2 t|ddddddddddddkstW 5 Q R X t : tj|t|dddddddddddddkstW 5 Q R X t , tj|ddd	gddddd
kstW 5 Q R X t 8 tj|| jdddddddddddddksHtW 5 Q R X t > tj|t|| jdddddddddddddkstW 5 Q R X d S )Nr   r<   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   )Znodesr   r   )r   r   r   )
r   r8   r>   r   Zgraph_number_of_cliquesr%   r   Znumber_of_cliquesr   valuesr@   r
   r
   r   test_number_of_cliquesX   s    

"

*
.
*
 


0

z"TestCliques.test_number_of_cliquesc                 C   s0  | j }t|ddksttt|dg dgks:ttt|ddg ddgks^tt|ddgdddks|tt|ddkstt|ddddddddddddksttj|| jdddddddddddddksttj|ddg| jddddksttj|d| jddks,td S )Nr   r   r   rE   r   rF   r<   )r   r   Znode_clique_numberr%   r   rG   r   r@   r
   r
   r   test_node_clique_number   sD     $&z#TestCliques.test_node_clique_numberc              	   C   sP  | j }t $ t|dddddggks.tW 5 Q R X t 0 tt|dg ddddgggksltW 5 Q R X t P dd tt|ddg D ddddggddddgdddgggkstW 5 Q R X t  t|ddg}W 5 Q R X | D ]\}}t	|||< q |ddddggddddgdddggdksHtt & t|dddddggksrtW 5 Q R X ddddhdddhg}t  d	d t|dD }W 5 Q R X ||tt
|fkstt " d
d tj|d| jdD }W 5 Q R X ||tt
|fks tt  tt|dksBtW 5 Q R X d S )Nr   r   r   r   c                 S   s   g | ]}t |qS r
   )r#   r-   r
   r
   r   
<listcomp>   s    z<TestCliques.test_cliques_containing_node.<locals>.<listcomp>r   rE   c                 S   s   g | ]}t |qS r
   r+   r-   r
   r
   r   rJ      s     c                 S   s   g | ]}t |qS r
   r+   r-   r
   r
   r   rJ      s     r<   r!   )r   r8   r>   r   Zcliques_containing_noder%   r   rG   itemsr#   reversedr   r3   )r   r   resultkvr(   r0   r
   r
   r   test_cliques_containing_node   s6    
(
4
"
0
*
 
&
z(TestCliques.test_cliques_containing_nodec                 C   s   | j }t|}t|ddddddddd	d
ddddddgks@tt|tdd}|j|jksbtt|tdd}t|dd tddD }t|dddd	d
gkstd S )Nr   r   r   r   r   r   r   r   r   r    r!      r   c                 S   s   i | ]}| |qS r
   r
   r   rO   r
   r
   r   r      s      z:TestCliques.test_make_clique_bipartite.<locals>.<dictcomp>)	r   r   make_clique_bipartiter#   r%   projected_graphr   adjr   )r   r   Br   H1r
   r
   r   test_make_clique_bipartite   s    
0z&TestCliques.test_make_clique_bipartitec                 C   s\   | j }t|}t|tdd}t|dd tddD }t|}|j|jksXtdS )zTests that the maximal clique graph is the same as the bipartite
        clique graph after being projected onto the nodes representing the
        cliques.

        rQ   r   c                 S   s   i | ]}| |d  qS r	   r
   rW   r
   r
   r   r      s      z:TestCliques.test_make_max_clique_graph.<locals>.<dictcomp>r   r   N)	r   r   rX   rY   r   r   make_max_clique_graphrZ   r%   )r   r   r[   r\   ZH2r
   r
   r   test_make_max_clique_graph   s    

z&TestCliques.test_make_max_clique_graphc              	   C   s.   t tj ttt  W 5 Q R X d S r*   )r8   r9   r   ZNetworkXNotImplementednextr   ZDiGraph)r   r
   r
   r   test_directed   s    zTestCliques.test_directedc                 C   s8   t  }tt |g ksttt |g ks4td S r*   )r   rB   r#   r   r%   r"   r@   r
   r
   r   test_find_cliques_trivial  s    z%TestCliques.test_find_cliques_trivialc                 C   sL   t ddddg}t dddg}|d t t j|t jd|sHtd S )	NrE   )r   r   )r   r   )r   r   )r   r   )r   r   r   )Zcreate_using)r   rB   add_nodeZis_isomorphicr^   r%   )r   r   Er
   r
   r   'test_make_max_clique_graph_create_using	  s    
z3TestCliques.test_make_max_clique_graph_create_usingN)__name__
__module____qualname__r   r)   r5   r7   r;   rA   rC   rD   rH   rI   rP   r]   r_   ra   rb   re   r
   r
   r
   r   r      s    		!K$r   c                   @   s   e Zd Zdd ZdS )TestEnumerateAllCliquesc              0   C   s  t  }ddddddddd	d
dddddddg}|| tt |}ttt|}t||ksdtdgdgdgdgdgdgdgddgdddgddddgdddgddgdddgddddgdddgddgdddgddgddgdddgddddgdddgdddgddgdddgddgddgddgdddgddddgdddgddgdddgddgdddgddgddgdddgddgddgddgdddgddddgdddddgddddgg-}ttt|ttt|kstd S )N)ab)rj   r.   )rj   d)rj   e)rk   r.   )rk   rl   )rk   rm   )r.   rl   )r.   rm   )rl   rm   )frk   )rn   r.   )rn   g)ro   rn   )ro   r.   )ro   rl   )ro   rm   rj   rk   r.   rl   rm   rn   ro   )	r   rB   Zadd_edges_fromr   Zenumerate_all_cliquesr$   r3   r#   r%   )r   r   Zedges_fig_4r=   Zclique_sizesZexpected_cliquesr
   r
   r   test_paper_figure_4  s    






0z+TestEnumerateAllCliques.test_paper_figure_4N)rf   rg   rh   rp   r
   r
   r
   r   ri     s   ri   )r8   Znetworkxr   r   r   r   ri   r
   r
   r
   r   <module>   s     