U
    #c                     @   s   d Z ddlZddlZddlmZmZ ddlmZmZm	Z	m
Z
 ddlmZmZmZ ddlmZmZ G dd dZG d	d
 d
ZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZdd Zdd Zdd Zdd Zdd  ZdS )!z$ Test functions for limits module.

    N)finfoiinfo)halfsingledouble
longdouble)assert_equalassert_assert_raises)_discovered_machar	_float_mac                   @   s   e Zd Zdd ZdS )TestPythonFloatc                 C   s&   t t}t t}tt|t| d S N)r   floatr   idselfftypeZftype2 r   C/tmp/pip-unpacked-wheel-b2rbor69/numpy/core/tests/test_getlimits.pytest_singleton   s    zTestPythonFloat.test_singletonN__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )TestHalfc                 C   s&   t t}t t}tt|t| d S r   )r   r   r   r   r   r   r   r   r      s    zTestHalf.test_singletonNr   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )
TestSinglec                 C   s&   t t}t t}tt|t| d S r   )r   r   r   r   r   r   r   r   r      s    zTestSingle.test_singletonNr   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )
TestDoublec                 C   s&   t t}t t}tt|t| d S r   )r   r   r   r   r   r   r   r   r       s    zTestDouble.test_singletonNr   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )TestLongdoublec                 C   s&   t t}t t}tt|t| d S r   )r   r   r   r   r   r   r   r   r   &   s    zTestLongdouble.test_singletonNr   r   r   r   r   r   %   s   r   c                   @   s   e Zd Zdd ZdS )	TestFinfoc                 C   st   t tdddddgtjtjtjtjtjg}|D ]2\}}dD ]$}tt	t
||t	t
||| q<q0ttt
d d S )Nf2f4Zf8Zc8Zc16)bitsZepsZepsnegZiexpZmachepmaxmaxexpminminexpZnegepZnexpnmantZ	precision
resolutionZtinyZsmallest_normalsmallest_subnormali4)listzipnpfloat16float32float64Z	complex64Z
complex128r   getattrr   r
   
ValueErrorr   ZdtsZdt1Zdt2attrr   r   r   
test_basic,   s     zTestFinfo.test_basicN)r   r   r   r5   r   r   r   r   r   +   s   r   c                   @   s   e Zd Zdd Zdd ZdS )	TestIinfoc                 C   s   t tddddddddgtjtjtjtjtjtjtj	tj
g}|D ]2\}}d	D ]$}ttt||tt||| qNqBtttd
 d S )Ni1i2r*   i8u1u2Zu4u8)r"   r%   r#   r!   )r+   r,   r-   Zint8int16Zint32Zint64Zuint8Zuint16Zuint32Zuint64r   r1   r   r
   r2   r3   r   r   r   r5   :   s(           zTestIinfo.test_basicc              
   C   sP   t jd }|D ]<}t jdd |d|d }W 5 Q R X tt|j| qd S )NZuintignore)Zoverr      )r-   sctypeserrstater   r   r#   )r   typesTZmax_calculatedr   r   r   test_unsigned_maxE   s
    
zTestIinfo.test_unsigned_maxN)r   r   r   r5   rD   r   r   r   r   r6   9   s   r6   c                   @   s   e Zd Zdd Zdd ZdS )TestReprc                 C   s   d}t tttj| d S )Nz)iinfo(min=-32768, max=32767, dtype=int16))r   reprr-   r   r=   r   expectedr   r   r   test_iinfo_reprM   s    zTestRepr.test_iinfo_reprc                 C   s   d}t tttj| d S )NzMfinfo(resolution=1e-06, min=-3.4028235e+38, max=3.4028235e+38, dtype=float32))r   rF   r-   r   r/   rG   r   r   r   test_finfo_reprQ   s    zTestRepr.test_finfo_reprN)r   r   r   rI   rJ   r   r   r   r   rE   L   s   rE   c                   C   s   t d td d S )N
   g      @)r   r   r   r   r   r   test_instancesW   s    rL   c                 C   sZ   | j  D ]J\}}t|t|| t|dr
t|jt||j t|jt||j q
d S )Nshape)__dict__itemsr   r1   hasattrrM   dtype)Z
discoveredma_likekeyvaluer   r   r   assert_ma_equal\   s
    
rU   c               	   C   s   t jtd ft jtd ft jtd ffD ]\} }tt| | q(t jdd tt j}W 5 Q R X t 	t jj
}|j|jfdkr|dkrt|td  n&|j|jfd	kr|dkrt|td
  d S )N       @   r>   all?    @     rV   P   p   r]      )r-   r.   r   r/   r0   rU   r   rA   r   rQ   itemsizeitr$   )r   rR   ld_mabytesr   r   r   test_known_typese   s    rh   c               	   C   s   t jdd tt j} W 5 Q R X t t jj}tjdd}td | j	| j
fdkrx|dkrx| j t|dkstnF| j	| j
fd	kr|d
kr| j t|dkstn| j t|dkstW 5 Q R X dS )z<Test that the subnormal is zero warning is not being raised.r>   rY   T)recordalwaysr[   r^   r   ra   rV   N)r-   rA   r   r   rQ   rd   warningscatch_warningssimplefilterre   r$   r)   lenAssertionError)rf   rg   wr   r   r   test_subnormal_warningw   s    
rq   c                  C   sR   t jd t jd  D ]8} t | }t|jdk t|jdk  t|jdk qd S )Nr   complexr?   )r-   r@   r   r	   r'   r&   r$   )r   infor   r   r   test_plausible_finfo   s
    
ru   )__doc__rk   Znumpyr-   Z
numpy.corer   r   r   r   r   r   Znumpy.testingr   r	   r
   Znumpy.core.getlimitsr   r   r   r   r   r   r   r   r6   rE   rL   rU   rh   rq   ru   r   r   r   r   <module>   s&   	