U
    :vf                      @   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 d dlmZmZ dZdddd	d
hZddddddh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 d0d1 Z!d2d3 Z"ejd4e#dfe$dfe%d5fe&dffd6d7 Z'ejd8d9d: e(dD e)dddgfd;d< Z*dS )=    N)copy)PythonRandomInterface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qweasd)r   r    )r!   )r"   Z19r$   resultexistingZ	existing1Z	existing2nestedc                 C   sz   |d kr$t | |}t|dksdtn@t|}t|}t | |}t|t|  kr^d| ksdn ttt|tsvtd S )Nr$   )r	   lenAssertionErrorr   
issubclasstypetuple)r)   r'   valZ_resultZ	nexisting r0   B/tmp/pip-unpacked-wheel-_lngutwb/networkx/utils/tests/test_misc.pytest_flatten.   s    

&r2   c                  C   sx   dddddg} t | | kstt | | ks.ttt | d tksFtttjt ddddg ttjt dddg d S )	Nr   r   g      @*   r   Zkermitg@)r   r+   r-   intpytestraisesnxNetworkXError)Zmylistr0   r0   r1   test_make_list_of_ints=   s    r:   c                  C   s2   t ddd} tddddddddddddgd} d S )	Nr$   g      @)exponentr   r   r   r   )distribution)r   r   )zr0   r0   r1   test_random_number_distributionF   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_classM   s    zTestNumpyArray.setup_classc                 C   s   t jdddgt jd}t dddg}t dddg}tt|tksJtt|t|ks^tt|}t|d tksztt	t
jt| d S )Nr   r   r   )Zdtypeg      ?g?r   )rB   arrayZint64r-   r   listr+   r5   r6   r7   r8   r9   )selfabcBr0   r0   r1   test_numpy_to_list_of_intsR   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   rH   rI   r   mapping)rI   rH   r   )r   rB   testingassert_allcloserE   sum)rG   drH   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   rM   r   r$   r   rN   !   )r   rB   rP   rQ   rE   rR   rG   rS   rO   rH   r0   r0   r1   test__dict_to_numpy_array2f   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 rU   )r   rB   rP   rQ   rE   r   rR   rW   r0   r0   r1   test_dict_to_numpy_array_ap   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   rM   r   rN   r   )r   rB   rP   rQ   rE   r   rR   rW   r0   r0   r1   test_dict_to_numpy_array_b~   s    

z)TestNumpyArray.test_dict_to_numpy_array_bN)
__name__
__module____qualname__classmethodrD   rL   rT   rX   rY   rZ   r0   r0   r0   r1   r?   L   s   



r?   c                  C   s   t d} dddg}|dg }tt| |ks0tttt| |ksHttt| dd|ks`ttd}tt|g ks|ttd}tt|ddg kstd S )	Nr   )r   r   )r   r   )r   r   )r   r   T)Zcyclicr0   )rangerF   r   r+   iter)ZnodesZ
node_pairsZnode_pairs_cycleZ
empty_iterr0   r0   r1   test_pairwise   s    

ra   c                  C   sV   t tddddddg} t| }ddhddhd	hd
}||ksBti ti ksRtd S )NZabcder   r   r   rH   rI   rJ   rS   e)r   r   r   )dictzipr
   r+   )Zmany_to_oneactualexpectedr0   r0   r1   test_groups   s
    rg   c                  C   s   t d} | jj}ttd|s$tttd |s6ttt| j|sJttt|d|s`t| j }tt|| jjstt 	t
td | |ddtddkstd S )Nr@   r   rH   r   )r6   rA   randomRandomState
isinstancer   r+   default_rng	Generatorr7   
ValueErrorallZrand)rB   rsrngr0   r0   r1   test_create_random_state   s    

rq   c                  C   s   t j} ttd| stttd | s*ttt| d| s@ttttd td}|j j	}|j 
d}|j |j  }t}tt|j |sttt|d|sttt||sttt||sttt |std S )Nr   rH   r@   i  )rh   Randomrj   r   r+   r6   r7   rm   rA   ri   rk   rl   ZSFC64r   )ZpyrsrB   ro   rp   Zrng_explicitZnprsr0   r0   r1   test_create_py_random_state   s    
rs   c                     sH  t d} | jj}t|d |d ddddksBt dddgdddgksft 	dd
ddkst dd	kst|  dddgdddgkst|  dddgdjdddgd
ddkst|  fddtdD fddtdD ks.t   ksDtd S )Nr@   r3   r   r   r   r   r         ?UUUUUU?r   Freplacec                    s   g | ]}  d dqS r   r   randint.0_rp   r0   r1   
<listcomp>   s     z:test_PythonRandomInterface_RandomState.<locals>.<listcomp>d   c                    s   g | ]}  d dqS r   r   rz   r|   )rs42r0   r1   r      s     )r6   rA   rh   ri   r   	randranger{   r+   choicegaussnormalexpovariateexponentialrn   shufflesampler_   Zrandom_sample)rB   ro   r0   )rp   r   r1   &test_PythonRandomInterface_RandomState   s$    
$*&
r   c                     sH  t d} | jdt| jd  ddddksBt dddgdddgksft 	dd
ddkst dd	kst|  dddgdddgkst|  dddgdjdddgd
ddkst|  fddtdD fddtdD ks.t   ksDtd S )Nr@   r3   r   r   r   r   r   rt   ru   rv   Frw   c                    s   g | ]}  d dqS ry   rz   r|   )prir0   r1   r      s     z8test_PythonRandomInterface_Generator.<locals>.<listcomp>r   c                    s   g | ]}  d dqS r   )integersr|   r   r0   r1   r      s     )r6   rA   rh   rk   r   r   r   r+   r   r   r   r   r   rn   r   r   r_   )rB   r0   )r   rp   r1   $test_PythonRandomInterface_Generator   s"    
$*&
r   )iterable_typerf   [c                 C   s"   | dddg}t ||kstd S )Nr   r   r   )r   r+   )r   rf   iterabler0   r0   r1   test_arbitrary_element   s    r   iteratorc                 c   s   | ]
}|V  qd S )Nr0   )r}   ir0   r0   r1   	<genexpr>   s     r   c              	   C   s&   t jtdd t|  W 5 Q R X dS )z0Value error is raised when input is an iterator.zfrom an iterator)matchN)r6   r7   rm   r   )r   r0   r0   r1   test_arbitrary_element_raises   s    r   )+rh   r   r6   Znetworkxr8   Znetworkx.utilsr   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?   ra   rg   rq   rs   r   r   rF   r.   strsetr   r_   r`   r   r0   r0   r0   r1   <module>   sP   4	
		= 
 