o
    ]Zh!                     @   s  d dl Z d dlmZ d dlZd dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZmZ dZh dZddd	h d
ddgfddddddddgZejddg dgddggejdeeegdd Zdd Zdd ZG d d! d!Zd"d# Zd$d% Zd&d' Z d(d) Z!d*d+ Z"d,d- Z#ejd.e$dfe%dfe&d/fe'dffd0d1 Z(ejd2d3d4 e)d	D e*g d5fd6d7 Z+dS )8    N)copy)PythonRandomInterfacePythonRandomViaNumpyBitsarbitrary_elementcreate_py_random_statecreate_random_statedict_to_numpy_arraydiscrete_sequenceflattengroupsmake_list_of_intspairwisepowerlaw_sequence)_dict_to_numpy_array1_dict_to_numpy_array2)      )      ))      )   )   )	   
      )                           >   )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   ZfoobarZbaz)r   r   )r   r   ZqweZasd)r   r!   )r"   )r#   Z19r%   resultexistingZ	existing1Z	existing2nestedc                 C   s|   |d u rt | |}t|dksJ n!t|}t|}t | |}t|t|  kr0d| ks3J  J tt|ts<J d S )Nr%   )r
   lenr   
issubclasstypetuple)r)   r'   val_resultZ	nexisting r0   M/var/www/auris/lib/python3.10/site-packages/networkx/utils/tests/test_misc.pytest_flatten/   s   

(r2   c                  C   sl   g d} t | | u sJ t | | ksJ tt | d tu s J ttjt g d ttjt g d d S )N)r   r   g      @*   r   )r   r   r   Zkermit)r   r   g@)r   r,   intpytestraisesnxNetworkXError)Zmylistr0   r0   r1   test_make_list_of_ints>   s   r:   c                  C   s    t ddd} tdg dd} d S )Nr%   g      @)exponent)r   r   r   r   r   r   r   r   r   r   r   )distribution)r   r	   )zr0   r0   r1   test_random_number_distributionG   s   r>   c                   @   s@   e Zd Zedd Zdd Zdd Zdd Zd	d
 Zdd Z	dS )TestNumpyArrayc                 C   s   t dad S )Nnumpy)r6   importorskipnp)clsr0   r0   r1   setup_classN   s   zTestNumpyArray.setup_classc                 C   s   t jg dt jd}t g d}t g d}tt|tks"J t|t|ks,J t|}t|d tks:J tt	j
t| d S )Nr   r   r   )Zdtype)g      ?r   r   )g?r   r   r   )rB   arrayZint64r,   r   listr5   r6   r7   r8   r9   )selfabcBr0   r0   r1   test_numpy_to_list_of_intsS   s   z)TestNumpyArray.test_numpy_to_list_of_intsc                 C   s|   ddd}t |dddd}tj|tddg t |dddd}tj|tddg t |}tj| d d S )Nr   r   rI   rJ   r   mapping)rJ   rI   r   )r   rB   testingassert_allcloserF   sum)rH   drI   r0   r0   r1   test__dict_to_numpy_array1]   s   
z)TestNumpyArray.test__dict_to_numpy_array1c                 C   sj   ddddddd}ddd}t ||d}tj|tddgddgg t |}tj| d d S 	Nr   r   rN   r   r%   r   rO   !   )r   rB   rQ   rR   rF   rS   rH   rT   rP   rI   r0   r0   r1   test__dict_to_numpy_array2g   s   
 z)TestNumpyArray.test__dict_to_numpy_array2c                 C   s   ddddddd}ddd}t ||d}tj|tddgddgg ddd}t ||d}tj|tddgddgg t|}tj| d d S rV   )r   rB   rQ   rR   rF   r   rS   rX   r0   r0   r1   test_dict_to_numpy_array_aq   s   
 
 z)TestNumpyArray.test_dict_to_numpy_array_ac                 C   sV   ddd}ddd}t ||d}tj|tddg t|}tj| d d S )Nr   r   rN   r   rO   r   )r   rB   rQ   rR   rF   r   rS   rX   r0   r0   r1   test_dict_to_numpy_array_b   s   

z)TestNumpyArray.test_dict_to_numpy_array_bN)
__name__
__module____qualname__classmethodrD   rM   rU   rY   rZ   r[   r0   r0   r0   r1   r?   M   s    



r?   c                  C   s   t d} g d}|dg }tt| |ksJ ttt| |ks#J tt| dd|ks/J td}tt|g ks=J td}tt|ddg ksMJ d S )Nr   ))r   r   )r   r   )r   r   )r   r   T)Zcyclicr0   )rangerG   r   iter)nodesZ
node_pairsZnode_pairs_cycleZ
empty_iterr0   r0   r1   test_pairwise   s   
rc   c                  C   sP   t tdg d} t| }ddhddhdhd}||ksJ i ti ks&J d S )	NZabcde)r   r   r   r   r   rI   rJ   rK   rT   e)r   r   r   )dictzipr   )Zmany_to_oneactualexpectedr0   r0   r1   test_groups   s
   ri   c                  C   s   t d} | jj}ttd|sJ ttd |sJ tt| j|s%J tt|d|s0J | j }tt|| jjs@J t t	td | 
|ddtddksZJ d S )Nr@   r   rI   r   )r6   rA   randomRandomState
isinstancer   default_rng	Generatorr7   
ValueErrorallZrand)rB   rsrngr0   r0   r1   test_create_random_state   s   

*rs   c            
      C   s6  t j} ttd| sJ ttd | sJ tt| d| s J tttd td}|j j}|j 	d}|j 
|j  }t}t}tt|j |sMJ tt|d|sXJ tt||saJ tt||sjJ tt |srJ tt |szJ d}||dfD ]}t|}	|	d|d  |	d|d  qd S )Nr   rI   r@   i  l    r   r   )rj   Randomrl   r   r6   r7   ro   rA   rk   rm   rn   ZSFC64r   r   	randrangerandint)
ZpyrsrB   rq   rr   Zrng_explicitZold_nprsZnprsZint64maxrZprsr0   r0   r1   test_create_py_random_state   s.   
rx   c                     s<  t d} d}| jj}t|| || ddddks#J  g dg dks3J  dd	ddksAJ  
dd	ksMJ |  g dg dks`J |  g dd
jg ddddkswJ |  fddtdD fddtdD ksJ    ksJ d S )Nr@   r3   r   r   rE   r   r         ?UUUUUU?r   r   Freplacec                       g | ]}  d dqS r   r   rv   .0_rr   r0   r1   
<listcomp>       z:test_PythonRandomInterface_RandomState.<locals>.<listcomp>d   c                    r~   r   r   r   r   )rs42r0   r1   r      r   )r6   rA   rj   rk   r   ru   rv   choicegaussnormalexpovariateexponentialrp   shufflesampler`   Zrandom_sample)rB   seedrq   r0   )rr   r   r1   &test_PythonRandomInterface_RandomState   s&   
 &"r   c                     s<  t d} d}| j|t| j|  ddddks#J  g dg dks3J  dd	ddksAJ  
dd	ksMJ |  g dg dks`J |  g dd
jg ddddkswJ |  fddtdD fddtdD ksJ    ksJ d S )Nr@   r3   r   r   rE   r   r   ry   rz   r   r{   Fr|   c                    r~   r   r   r   )prir0   r1   r      r   z8test_PythonRandomInterface_Generator.<locals>.<listcomp>r   c                    r~   r   )integersr   r   r0   r1   r      r   )r6   rA   rj   rm   r   ru   r   r   r   r   r   r   rp   r   r   r`   )rB   r   r0   )r   rr   r1   $test_PythonRandomInterface_Generator   s$   
 &"r   )iterable_typerh   [c                 C   s    | g d}t ||ksJ d S )NrE   )r   )r   rh   iterabler0   r0   r1   test_arbitrary_element   s   r   iteratorc                 c   s    | ]}|V  qd S )Nr0   )r   ir0   r0   r1   	<genexpr>  s    r   rE   c                 C   s<   t jtdd t|  W d   dS 1 sw   Y  dS )z0Value error is raised when input is an iterator.zfrom an iterator)matchN)r6   r7   ro   r   )r   r0   r0   r1   test_arbitrary_element_raises  s   
"r   ),rj   r   r6   Znetworkxr8   Znetworkx.utilsr   r   r   r   r   r   r	   r
   r   r   r   r   Znetworkx.utils.miscr   r   Znested_depthZ
nested_setZnested_mixedmarkZparametrizer2   r:   r>   r?   rc   ri   rs   rx   r   r   rG   r-   strsetr   r`   ra   r   r0   r0   r0   r1   <module>   sF    8	
		=
