B
     \yU                 @   s  d dl mZ d dlmZ d dlmZ d dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZmZ d dlmZmZ d dlmZ ddlmZmZmZmZmZ e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(d) Z*d*d+ Z+d,d- Z,d.d/ Z-d0d1 Z.d2d3 Z/d4d5 Z0d6d7 Z1d8d9 Z2d:d; Z3d<d= Z4d>d? Z5d@dA Z6dBdC Z7dDdE Z8dFdG Z9dHdI Z:dJdK Z;dLdM Z<dNdO Z=dPdQ Z>dRdS Z?dTdU Z@dVdW ZAdXdY ZBeCejDdZk d[ZEG d\d] d]eeZFG d^d_ d_eFZGG d`da daeFZHG dbdc dceIZJG ddde deeJeFZKG dfdg dgeJeFZLG dhdi dieFZMG djdk dkeFZNG dldm dmeFZOePdnkreQ  dS )o    )print_functionN)
namedtuple)compile_isolatedFlags)jittypes   )TestCaseenable_pyobj_flagsMemoryLeakMixintagcompile_functionPoint)abc             C   s*   | dd dd |D i } td| t S )NZinitializerz, c             s   s   | ]}t |V  qd S )N)repr).0arg r   4lib/python3.7/site-packages/numba/tests/test_sets.py	<genexpr>   s    z-_build_set_literal_usecase.<locals>.<genexpr>Z	build_set)joinr   globals)codeargsr   r   r   _build_set_literal_usecase   s    r   c             C   s   d}t || S )Nz@if 1:
    def build_set():
        return {%(initializer)s}
    )r   )r   r   r   r   r   set_literal_return_usecase   s    r   c             C   s   d}t || S )Nz^if 1:
    def build_set():
        my_set = {%(initializer)s}
        return list(my_set)
    )r   )r   r   r   r   r   set_literal_convert_usecase#   s    r   c              C   s   t  } | d t| S )Nr   )setaddlen)sr   r   r   empty_constructor_usecase,   s    
r"   c             C   s   t | }t|S )N)r   r    )r   r!   r   r   r   constructor_usecase1   s    r#   c             C   s(   t | }g }x|D ]}|| qW |S )N)r   append)r   r!   lvr   r   r   iterator_usecase5   s
    
r'   c             C   s,   t  }||  || || t|S )N)r   updatelist)r   r   cr!   r   r   r   update_usecase<   s
    


r+   c             C   s(   t | }x|D ]}|| qW t|S )N)r   remover)   )r   r   r!   r&   r   r   r   remove_usecaseC   s    
r-   c             C   s(   t | }x|D ]}|| qW t|S )N)r   discardr)   )r   r   r!   r&   r   r   r   discard_usecaseI   s    
r/   c             C   s6   t | }x$tdD ]}|| || qW t|S )Ni  )r   ranger   r.   r)   )r   ur&   r!   ir   r   r   add_discard_usecaseO   s
    
r3   c             C   s0   t | }g }xt|dkr*||  qW |S )Nr   )r   r    r$   pop)r   r!   r%   r   r   r   pop_usecaseV   s
    r5   c             C   s,   t | }g }x|D ]}|||k qW |S )N)r   r$   )r   r   r!   r%   r&   r   r   r   contains_usecase]   s
    
r6   c             C   s   t | }|t | t|S )N)r   difference_updater)   )r   r   r!   r   r   r   difference_update_usecased   s    r8   c             C   s   t | }|t | t|S )N)r   intersection_updater)   )r   r   r!   r   r   r   intersection_update_usecasei   s    r:   c             C   s   t | }|t | t|S )N)r   symmetric_difference_updater)   )r   r   r!   r   r   r   #symmetric_difference_update_usecasen   s    r<   c             C   s   t | t |S )N)r   
isdisjoint)r   r   r   r   r   isdisjoint_usecases   s    r>   c             C   s   t | t |S )N)r   issubset)r   r   r   r   r   issubset_usecasev   s    r@   c             C   s   t | t |S )N)r   
issuperset)r   r   r   r   r   issuperset_usecasey   s    rB   c             C   s    t | }|  t|t|fS )N)r   clearr    r)   )r   r!   r   r   r   clear_usecase|   s    rD   c             C   s(   t | }| }|  t|t|fS )N)r   copyr4   r    r)   )r   r!   ssr   r   r   copy_usecase   s    rG   c             C   s2   t | }|  | }|d t|t|fS )N*   )r   rC   rE   r   r    r)   )r   r!   rF   r   r   r   copy_usecase_empty   s
    
rI   c             C   s2   t | }|| | }|  t|t|fS )N)r   r,   rE   r4   r    r)   )r   r   r!   rF   r   r   r   copy_usecase_deleted   s
    
rJ   c             C   s   t | }|t |}t|S )N)r   
differencer)   )r   r   sar!   r   r   r   difference_usecase   s    rM   c             C   s   t | }|t |}t|S )N)r   intersectionr)   )r   r   rL   r!   r   r   r   intersection_usecase   s    rO   c             C   s   t | }|t |}t|S )N)r   symmetric_differencer)   )r   r   rL   r!   r   r   r   symmetric_difference_usecase   s    rQ   c             C   s   t | }|t |}t|S )N)r   unionr)   )r   r   rL   r!   r   r   r   union_usecase   s    rS   c             C   s   t | }|S )N)r   )r   r!   r   r   r   set_return_usecase   s    rT   c             C   s   dt | d }td|t S )Nzbif 1:
    def operator_usecase(a, b):
        s = set(a) %(op)s set(b)
        return list(s)
    )opZoperator_usecase)dictr   r   )rU   r   r   r   r   make_operator_usecase   s    rW   c             C   s   dt | d }td|t S )Nzif 1:
    def inplace_operator_usecase(a, b):
        sa = set(a)
        sb = set(b)
        sc = sa
        sc %(op)s sb
        return list(sc), list(sa)
    )rU   Zinplace_operator_usecase)rV   r   r   )rU   r   r   r   r   make_inplace_operator_usecase   s    rX   c             C   s   dt | d }td|t S )NzPif 1:
    def comparison_usecase(a, b):
        return set(a) %(op)s set(b)
    )rU   Zcomparison_usecase)rV   r   r   )rU   r   r   r   r   make_comparison_usecase   s    rY   c             C   s   d S )Nr   )xr   r   r   noop   s    r[   c             C   s   d}x| D ]}||7 }q
W |S )z!
    Expect a set of numbers
    r   r   )rZ   resr&   r   r   r   unbox_usecase   s    
r]   c             C   s"   d}x| D ]}|t |7 }q
W |S )z 
    Expect a set of tuples
    r   )r    )rZ   r\   r&   r   r   r   unbox_usecase2   s    
r^   c             C   s&   | \}}|}x|D ]}||7 }qW |S )z2
    Expect a (number, set of numbers) tuple.
    r   )rZ   r   r   r\   r&   r   r   r   unbox_usecase3   s
    
r_   c             C   s*   | \}}|}x|D ]}|t |7 }qW |S )z1
    Expect a (number, set of tuples) tuple.
    )r    )rZ   r   r   r\   r&   r   r   r   unbox_usecase4   s
    
r`   c             C   s&   |  d | | | t| t|fS )NrH   )r   r(   r    )rL   sbr   r   r   reflect_simple   s    

rb   c             C   sL   t |dkrtd} | d | | td}| | | t | t |fS )Nr   )g      &@g      6@g     @@g      F@g      E@)g     K@g     P@)r    r   r   r(   r;   )rL   ra   Zscr   r   r   reflect_conditional   s    


rc   c             C   s   |  d td S )NrH   )r   ZeroDivisionError)r!   r   r   r   reflect_exception  s    
re   c             C   s   |  |  | |kS )N)r   r4   )rL   ra   r   r   r   reflect_dual  s    rf   c             C   s8   t  }g }x(| D ] }||kr|| || qW |S )N)r   r   r$   )srcseenr\   r&   r   r   r   unique_usecase  s    

ri   )      z*set literals unavailable before Python 2.7c                   sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )BaseTestc                s   t t|   td| _d S )NrH   )superrl   setUprandomZRandomrnd)self)	__class__r   r   rn     s    zBaseTest.setUpc             C   s   t t|S )N)nparangeint)rq   stopr   r   r   _range   s    zBaseTest._rangec                s<    fddt |D }ttjr4tj|jdS |S dS )zD
        Choose *n* possibly duplicate items from sequence.
        c                s   g | ]} j tqS r   )rp   Zchoicer)   )r   r2   )rq   seqr   r   
<listcomp>'  s    z+BaseTest._random_choice.<locals>.<listcomp>)dtypeN)r0   
isinstancers   ZndarrayZarrayrz   )rq   rx   nr%   r   )rq   rx   r   _random_choice#  s    zBaseTest._random_choicec             C   s   |  t|}| ||S )z<
        Get a 1d array with many duplicate values.
        )rw   rs   Zsqrtr}   )rq   r|   r   r   r   r   duplicates_array-  s    zBaseTest.duplicates_arrayc             C   s   |  |d }| ||S )z;
        Get a 1d array with values spread around.
        g?)rw   r}   )rq   r|   r   r   r   r   sparse_array4  s    zBaseTest.sparse_arrayc             C   sx   t |tr<| |t x\t||D ]\}}| || q"W n8t |trh| |t | t|t| n| || d S )N)r{   tupleZassertIsInstancezip_assert_equal_unorderedr)   assertPreciseEqualsorted)rq   r   r   r1   r&   r   r   r   r   <  s    

z BaseTest._assert_equal_unorderedc                s"   t dd  fdd}|S )NT)nopythonc                 s    |  } |  } || d S )N)r   )r   expectedgot)cfuncpyfuncrq   r   r   checkI  s    z)BaseTest.unordered_checker.<locals>.check)r   )rq   r   r   r   )r   r   rq   r   unordered_checkerG  s    zBaseTest.unordered_checker)__name__
__module____qualname__rn   rw   r}   r~   r   r   r   __classcell__r   r   )rr   r   rl     s   
rl   c               @   s@   e Zd ZeefddZeefddZededd ZdS )	TestSetLiteralsc             C   s   t d}| j||d d S )N)r   rj      rj   )flags)r   run_nullary_func)rq   r   r   r   r   r   test_build_setR  s    zTestSetLiterals.test_build_setc             C   s   t d}| j||d t d}| j||d\}}tjd d dkrPtjd dkstjd d dkrptjd dkstjd d d	kr| t| t|  d S )
N)r   g       @y              @rj   )r   )g       @rj   rj   )rj   rk      )r      r   )r      )r   r   sysversion_infoZassertIstyper4   )rq   r   r   r   r   r   r   r   test_build_heterogeneous_setW  s      z,TestSetLiterals.test_build_heterogeneous_set	importantc             C   sH   t | d}t|}tdd|}| }| }| t|t| d S )N2   T)r   )r)   r   r   r   r   r   )rq   r   r   r   r   r   r   r   r   test_build_set_nopythong  s    z'TestSetLiterals.test_build_set_nopythonN)	r   r   r   needs_set_literalsr
   r   r   r   r   r   r   r   r   r   P  s   r   c               @   st  e Zd Zdd Zeddd Zeddd Zeddd	 Zd
d Zdd Z	eddd Z
dd Zeddd Zed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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHdI Z'dJdK Z(dLdM Z)dNdO Z*dPS )QTestSetsc                sl   t tdd     ttdd  fdd}|d |d |d d S )NT)r   c                s    |  |  d S )N)r   )r   )r   r   rq   r   r   r   |  s    z(TestSets.test_constructor.<locals>.check)r   rj   r   rj   rk      )r"   r   r   r#   r~   r   )rq   r   r   )r   r   rq   r   test_constructoru  s    zTestSets.test_constructorr   c             C   s.   t }tdd|}d}| ||t| d S )NT)r   )r   rj   r   rj   rk   )rT   r   assertEqualr   )rq   r   r   r   r   r   r   test_set_return  s    zTestSets.test_set_returnc             C   s6   t }| |}|d || d || d d S )N)r   rj   r   rj   rk   r   )r'   r   r~   r   )rq   r   r   r   r   r   test_iterator  s
    
zTestSets.test_iteratorc             C   sR   t }| |}d\}}}|||| | d}| d}| d}|||| d S )N))r   rj      	   )rj   r   r      rH   )r   r   r   rH   r   )r+   r   r   r~   )rq   r   r   r   r   r*   r   r   r   test_update  s    




zTestSets.test_updatec             C   s$   t }| |}d}d}||| d S )N)r   rj   r   r      rH   )r   rj   r   )r-   r   )rq   r   r   r   r   r   r   r   test_remove  s
    
zTestSets.test_removec          	   C   s>   |    t}tdd|}| t}|dd W d Q R X d S )NT)r   )r   rj   r   )r   )Zdisable_leak_checkr-   r   assertRaisesKeyError)rq   r   r   raisesr   r   r   test_remove_error  s
    zTestSets.test_remove_errorc             C   sB   t }| |}d}d}||| | d}| d}||| d S )N)r   rj   r   r   r   rH   )r   rj   r   r   )r/   r   r   )rq   r   r   r   r   r   r   r   test_discard  s    



zTestSets.test_discardc             C   s   t }| |}|ddd dS )z
        Check that the insertion logic does not create an infinite lookup
        chain with deleted entries (insertion should happen at the first
        deleted entry, not at the free entry at the end of the chain).
        See issue #1913.
        )r   r   N)r3   r   )rq   r   r   r   r   r   test_add_discard  s    
zTestSets.test_add_discardc             C   s(   t }| |}|d || d d S )N)rj   r   7   r   r   rH   r   )r5   r   r   )rq   r   r   r   r   r   test_pop  s    
zTestSets.test_popc                s8   t tdd  fdd}d}d}||| d S )NT)r   c                s    | | | | d S )N)r   )r   r   )r   r   rq   r   r   r     s    z%TestSets.test_contains.<locals>.check)r   rj   r   r   rH   )r   rj   r   r   )r6   r   )rq   r   r   r   r   )r   r   rq   r   test_contains  s    zTestSets.test_containsc             C   s\   |  |}d\}}||| d}x6t||D ]&\}}| |}| |}||| q.W d S )N))r   rj   r   r   )rj   r   r   r   rH   )r   r   i  )r   	itertoolsproductr   )rq   r   r   r   r   sizesnanbr   r   r   _test_xxx_update  s    



zTestSets._test_xxx_updatec             C   s   |  t d S )N)r   r8   )rq   r   r   r   test_difference_update  s    zTestSets.test_difference_updatec             C   s   |  t d S )N)r   r:   )rq   r   r   r   test_intersection_update  s    z!TestSets.test_intersection_updatec             C   s   |  t d S )N)r   r<   )rq   r   r   r    test_symmetric_difference_update  s    z)TestSets.test_symmetric_difference_updatec                s   t dd  fdd}ttddg\}}||@ || ||B ||A g}dd |D }x"t||D ]\}}||| qhW d S )	NT)r   c                s    | | | | d S )N)r   )r   r   )r   r   rq   r   r   r     s    z(TestSets._test_comparator.<locals>.check)r   rj   r   r   )rj   r   r   r   rH   c             S   s   g | ]}t |qS r   )r   )r   rZ   r   r   r   ry     s    z-TestSets._test_comparator.<locals>.<listcomp>)r   mapr   r   r   )rq   r   r   r   r   r   r   )r   r   rq   r   _test_comparator  s    zTestSets._test_comparatorc             C   s   |  t d S )N)r   r>   )rq   r   r   r   test_isdisjoint  s    zTestSets.test_isdisjointc             C   s   |  t d S )N)r   r@   )rq   r   r   r   test_issubset  s    zTestSets.test_issubsetc             C   s   |  t d S )N)r   rB   )rq   r   r   r   test_issuperset  s    zTestSets.test_issupersetc             C   s(   t }| |}|d || d d S )N)r   rj   r   r   r   )rD   r   r   )rq   r   r   r   r   r   
test_clear  s    
zTestSets.test_clearc             C   sv   t }| |}|d || d t}| |}|d t}| |}|dd | d}|||t|d   d S )N)r   rj   r   r   r   )r   rj   )rG   r   r   rI   rJ   r    )rq   r   r   r   r   r   r   	test_copy  s    




zTestSets.test_copyc             C   s\   |  |}d\}}||| d}x6t||D ]&\}}| |}| |}||| q.W d S )N))r   rj   r   r   )rj   r   r   r   rH   )r   r   i  )r   r   r   r   )rq   r   r   r   r   r   r   r   r   r   r   _test_set_operator  s    



zTestSets._test_set_operatorc             C   s   |  t d S )N)r   rM   )rq   r   r   r   test_difference*  s    zTestSets.test_differencec             C   s   |  t d S )N)r   rO   )rq   r   r   r   test_intersection-  s    zTestSets.test_intersectionc             C   s   |  t d S )N)r   rQ   )rq   r   r   r   test_symmetric_difference0  s    z"TestSets.test_symmetric_differencec             C   s   |  t d S )N)r   rS   )rq   r   r   r   
test_union3  s    zTestSets.test_unionc             C   s   |  td d S )N&)r   rW   )rq   r   r   r   test_and6  s    zTestSets.test_andc             C   s   |  td d S )N|)r   rW   )rq   r   r   r   test_or9  s    zTestSets.test_orc             C   s   |  td d S )N-)r   rW   )rq   r   r   r   test_sub<  s    zTestSets.test_subc             C   s   |  td d S )N^)r   rW   )rq   r   r   r   test_xor?  s    zTestSets.test_xorc             C   s   |  td d S )Nz==)r   rY   )rq   r   r   r   test_eqB  s    zTestSets.test_eqc             C   s   |  td d S )Nz!=)r   rY   )rq   r   r   r   test_neE  s    zTestSets.test_nec             C   s   |  td d S )Nz<=)r   rY   )rq   r   r   r   test_leH  s    zTestSets.test_lec             C   s   |  td d S )N<)r   rY   )rq   r   r   r   test_ltK  s    zTestSets.test_ltc             C   s   |  td d S )Nz>=)r   rY   )rq   r   r   r   test_geN  s    zTestSets.test_gec             C   s   |  td d S )N>)r   rY   )rq   r   r   r   test_gtQ  s    zTestSets.test_gtc             C   s   |  td d S )Nz&=)r   rX   )rq   r   r   r   	test_iandT  s    zTestSets.test_iandc             C   s   |  td d S )Nz|=)r   rX   )rq   r   r   r   test_iorW  s    zTestSets.test_iorc             C   s   |  td d S )Nz-=)r   rX   )rq   r   r   r   	test_isubZ  s    zTestSets.test_isubc             C   s   |  td d S )Nz^=)r   rX   )rq   r   r   r   	test_ixor]  s    zTestSets.test_ixorN)+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   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s  sN   		r   c               @   s,   e Zd Zdd Zdd Zeddd ZdS )	OtherTypesTestc                sd   t tdd     ttdd  fdd}|d |d d S )NT)r   c                s    |  |  d S )N)r   )r   )r   r   rq   r   r   r   j  s    z.OtherTypesTest.test_constructor.<locals>.checkr   )r"   r   r   r#   r~   r   )rq   r   r   )r   r   rq   r   r   c  s    zOtherTypesTest.test_constructorc             C   s.   t }| |}|| d || d d S )Nr   )r'   r   r~   r   )rq   r   r   r   r   r   r   p  s    
zOtherTypesTest.test_iteratorr   c             C   s<   t }| |}| d}| d}| d}|||| d S )Nr   )r+   r   r   r~   )rq   r   r   r   r   r*   r   r   r   r   w  s    



zOtherTypesTest.test_updateN)r   r   r   r   r   r   r   r   r   r   r   r   a  s   r   c               @   s   e Zd ZdZdd ZdS )TestFloatSetsz-
    Test sets with floating-point keys.
    c             C   s   t j|t jdt d S )N)rz   g?)rs   rt   Zfloat32)rq   rv   r   r   r   rw     s    zTestFloatSets._rangeN)r   r   r   __doc__rw   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdd ZdS )TestTupleSetsz$
    Test sets with tuple keys.
    c             C   sL   t j|t jd}|d@ }|d@ t j}|d? d@ t j}tt|||S )N)rz   l   UU*UU* l   *UU     r   )rs   rt   Zint64ZastypeZint32Zbool_r)   r   )rq   rv   r   r   r*   dr   r   r   rw     s
    zTestTupleSets._rangeN)r   r   r   r   rw   r   r   r   r   r     s   r   c               @   s^   e Zd ZdZejdd Zdd Zeddd Z	d	d
 Z
eddd Zdd Zdd ZdS )TestUnboxingz>
    Test unboxing of Python sets into native Numba sets.
    c          	   c   s:   |  t}d V  W d Q R X |d k	r6| t|j| d S )N)r   	TypeErrorZassertRegexpMatchesstrZ	exception)rq   msgr   r   r   r   assert_type_error  s    zTestUnboxing.assert_type_errorc                s"   t dd  fdd}|S )NT)r   c                s    | } | } || d S )N)r   )r   r   r   )r   r   rq   r   r   r     s    z'TestUnboxing.check_unary.<locals>.check)r   )rq   r   r   r   )r   r   rq   r   check_unary  s    zTestUnboxing.check_unaryr   c             C   s>   |  t}|tddg |tddg |ttd d S )Nr   rj   y              ?y              @d   )r   r]   r   r0   )rq   r   r   r   r   test_numbers  s    
zTestUnboxing.test_numbersc             C   s.   |  t}|tddg |tddg d S )N)r   rj   )r   r   )r   y               @)r   y              @)r   r^   r   )rq   r   r   r   r   test_tuples  s    
zTestUnboxing.test_tuplesc             C   s$   |  t}|dtdddgf d S )Nr   rj   r   r   )r   r_   r   )rq   r   r   r   r   test_set_inside_tuple  s    
z"TestUnboxing.test_set_inside_tuplec             C   s"   |  t}|dtddgf d S )Nr   )rj   )r   )r   r`   r   )rq   r   r   r   r   test_set_of_tuples_inside_tuple  s    
z,TestUnboxing.test_set_of_tuples_inside_tuplec          	   C   s  d}t }tdd|}tddg}| | || W d Q R X | |tddg | | |tddg W d Q R X | | |dtddgf W d Q R X | | |tdtddg W d Q R X tddg}| ttf}|| W d Q R X d S )	Nzcan't unbox heterogeneous setT)r   r   g      @y               @)r   )rj   r   )	r[   r   r   r   r   r   r   
IndexError
ValueError)rq   r   r   r   valZlstr   r   r   r   test_errors  s      zTestUnboxing.test_errorsN)r   r   r   r   
contextlibcontextmanagerr   r   r   r   r   r   r   r   r   r   r   r   r     s   r   c               @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zed
dd Z	dd Z
dS )TestSetReflectionzE
    Test reflection of native Numba sets on Python set objects.
    c       
   
   C   s   t dd|}tddddgtdgftddddgtdd	d
ddgfg}x|D ]|\}}t|}t|}|||}| ||H |||}	| |	| | || | |d |k|	d |k ~~	W d Q R X qPW d S )NT)r   g      ?g       @g      @g      @g        g      @g      @g      @g       @g      "@r   )r   r   assertRefCountr   r   )
rq   r   r   Zsamplesdestrg   r   r   ZpyresZcresr   r   r   check_reflection  s    $

z"TestSetReflection.check_reflectionc             C   s   |  t d S )N)r   rb   )rq   r   r   r   test_reflect_simple  s    z%TestSetReflection.test_reflect_simplec             C   s   |  t d S )N)r   rc   )rq   r   r   r   test_reflect_conditional  s    z*TestSetReflection.test_reflect_conditionalc          
   C   sp   t }tdd|}tdddg}| |< | t || W dQ R X | |tddddg W dQ R X dS )zd
        When the function exits with an exception, sets should still be
        reflected.
        T)r   r   rj   r   NrH   )re   r   r   r   r   rd   r   )rq   r   r   r!   r   r   r   test_reflect_exception  s    z(TestSetReflection.test_reflect_exceptionr   c             C   sp   t }tdd|}tdddg}| }|||}|||}| || | || | t|t| dS )zf
        When the same set object is reflected twice, behaviour should
        be consistent.
        T)r   r   rj   r   N)rf   r   r   rE   r   r   getrefcount)rq   r   r   ZpysetZcsetr   r   r   r   r   test_reflect_same_set  s    

z'TestSetReflection.test_reflect_same_setc             C   sH   t ddt}tdg}dd |D }|| | dd |D | dS )zO
        When the set wasn't mutated, no reflection should take place.
        T)r   y              )@c             S   s   g | ]}t |qS r   )id)r   rZ   r   r   r   ry     s    z8TestSetReflection.test_reflect_clean.<locals>.<listcomp>c             S   s   g | ]}t |qS r   )r   )r   rZ   r   r   r   ry     s    N)r   r[   r   r   )rq   r   r!   Zidsr   r   r   test_reflect_clean  s
    
z$TestSetReflection.test_reflect_cleanN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s   r   c               @   s    e Zd ZdZeddd ZdS )TestExamplesz!
    Examples of using sets.
    r   c             C   s.   t }| |}|| d || d d S )Nr   )ri   r   r~   r   )rq   r   r   r   r   r   test_unique&  s    
zTestExamples.test_uniqueN)r   r   r   r   r   r  r   r   r   r   r   !  s   r   __main__)RZ
__future__r   Znumba.unittest_supportZunittest_supportZunittestcollectionsr   r   r   Zmathro   r   Znumpyrs   Znumba.compilerr   r   Znumbar   r   Zsupportr	   r
   r   r   r   r   r   r   r   r"   r#   r'   r+   r-   r/   r3   r5   r6   r8   r:   r<   r>   r@   rB   rD   rG   rI   rJ   rM   rO   rQ   rS   rT   rW   rX   rY   r[   r]   r^   r_   r`   rb   rc   re   rf   ri   ZskipIfr   r   rl   r   r   objectr   r   r   r   r   r   r   mainr   r   r   r   <module>   s   
			

6# o!DD
