o
    ִi+                     @   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numpy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nxDiGraphDGadd_edges_from)clsdeg r   X/home/kuhnn/.local/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   nodelistN)nparraytestingassert_equalr   modularity_matrixr   ix_)selfB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*   
G_weightedn1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?皙?皙ٿr7   r7   )r   r   r   r   r   r   )gffffff?皙?g333333ӿ333333r8   r9   )r4   r7   r4   r7   r5   r5   )r4   r7   r4   r5   r7   r5   )皙r4   r:   r6   r4   r4   )r	   r   r   r   r
   r   )r
   r   r   r   r   r	   r!   N)	r#   r$   r   directed_modularity_matrixr   sortedr%   r&   r(   )r)   r*   node_permutationidx_permutationmmr   r   r   test_directed_modularityF   s   
z'TestModularity.test_directed_modularityN)__name__
__module____qualname__classmethodr   r,   r3   r@   r   r   r   r   r   
   s    
r   )pytestimportorskipr#   networkxr   networkx.generators.degree_seqr   r   r   r   r   r   <module>   s    

