o
    ]Zh+                     @   sB   d dl Z e dZe d d dlZd dlmZ G dd dZdS )    NnumpyZscipy)havel_hakimi_graphc                   @   s0   e Zd Zedd Zdd Zdd Zdd Zd	S )
TestModularityc                 C   s,   g d}t || _t | _| jd d S )N)      r      r   )
)r   r   )r   r   )r   r   )r   r   )r      )   r   )r	      )r   r	   )r   r
   )r
   r	   )r   GnxZDiGraphDGZadd_edges_from)clsdeg r   T/var/www/auris/lib/python3.10/site-packages/networkx/linalg/tests/test_modularity.pysetup_class   s   

zTestModularity.setup_classc                 C   sp   t g dg dg dg dg dg}g d}t jt| j| t jtj| j|d|t ||  dS )	zModularity matrixg            ?r         ?        r               ?      пr   r   r   r   r   r   r   r   r   g      r   r   r   r   r   r   )r	   r   r   r   r   ZnodelistN)nparraytestingassert_equalr   modularity_matrixr   ix_)selfBZpermutationr   r   r   test_modularity!   s   
zTestModularity.test_modularityc                 C   s   t g dg dg dg dg dg}| j }| D ]\}}d|j||f d< qt jt|| t jtj|ddd|  d	S )
zModularity matrix with weightsr   r   r   r   r   r   weight)r(   N)	r   r    r   copyedgesr!   r"   r   r#   )r%   r&   Z
G_weightedZn1Zn2r   r   r   test_modularity_weight2   s   

z%TestModularity.test_modularity_weightc              	   C   s   t g dg dg dg dg dg dg}g d}g d}tj| jt| jd	}t j|| t jtj| j|d	|t ||  d
S )zDirected Modularity matrix)皙ɿ333333?皙?皙ٿr/   r/   )r   r   r   r   r   r   )gffffff?皙?g333333ӿ333333r0   r1   )r,   r/   r,   r/   r-   r-   )r,   r/   r,   r-   r/   r-   )皙r,   r2   r.   r,   r,   )r   r   r   r   r	   r
   )r	   r   r   r   r   r   r   N)	r   r    r   Zdirected_modularity_matrixr   sortedr!   r"   r$   )r%   r&   Znode_permutationZidx_permutationmmr   r   r   test_directed_modularityF   s   
z'TestModularity.test_directed_modularityN)__name__
__module____qualname__classmethodr   r'   r+   r5   r   r   r   r   r   
   s    
r   )ZpytestZimportorskipr   Znetworkxr   Znetworkx.generators.degree_seqr   r   r   r   r   r   <module>   s    

