o
    1ήcW                     @   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                   @      e Zd Zdd ZdS )TestPythonFloatc                 C   &   t t}t t}tt|t| d S N)r   floatr   idselfftypeftype2 r   F/tmp/pip-target-vg8gfxp4/lib/python/numpy/core/tests/test_getlimits.pytest_singleton      zTestPythonFloat.test_singletonN__name__
__module____qualname__r   r   r   r   r   r          r   c                   @   r   )TestHalfc                 C   r   r   )r   r   r   r   r   r   r   r   r      r   zTestHalf.test_singletonNr   r   r   r   r   r       r   r    c                   @   r   )
TestSinglec                 C   r   r   )r   r   r   r   r   r   r   r   r      r   zTestSingle.test_singletonNr   r   r   r   r   r!      r   r!   c                   @   r   )
TestDoublec                 C   r   r   )r   r   r   r   r   r   r   r   r       r   zTestDouble.test_singletonNr   r   r   r   r   r"      r   r"   c                   @   r   )TestLongdoublec                 C   r   r   )r   r   r   r   r   r   r   r   r   &   r   zTestLongdouble.test_singletonNr   r   r   r   r   r#   %   r   r#   c                   @   r   )	TestFinfoc                 C   sn   t tg dtjtjtjtjtjg}|D ]\}}dD ]}tt	t
||t	t
||| qqttt
d d S )N)f2f4f8c8c16)bitsepsepsnegiexpmachepmaxmaxexpminminexpnegepnexpnmant	precision
resolutiontinysmallest_normalsmallest_subnormali4)listzipnpfloat16float32float64	complex64
complex128r   getattrr   r
   
ValueErrorr   dtsdt1dt2attrr   r   r   
test_basic,   s   
zTestFinfo.test_basicN)r   r   r   rK   r   r   r   r   r$   +   r   r$   c                   @      e Zd Zdd Zdd ZdS )	TestIinfoc                 C   sz   t tg dtjtjtjtjtjtjtj	tj
g}|D ]\}}dD ]}ttt||tt||| q!qtttd d S )N)i1i2r;   i8u1u2u4u8)r*   r1   r/   r&   )r<   r=   r>   int8int16int32int64uint8uint16uint32uint64r   rD   r   r
   rE   rF   r   r   r   rK   :   s   
zTestIinfo.test_basicc                 C   s,   t jd }|D ]}tt|j|d qd S )Nuint)r>   sctypesr   r   r/   )r   typesTr   r   r   test_unsigned_maxE   s   
zTestIinfo.test_unsigned_maxN)r   r   r   rK   rb   r   r   r   r   rM   9   s    rM   c                   @   rL   )TestReprc                 C      d}t tttj| d S )Nz)iinfo(min=-32768, max=32767, dtype=int16))r   reprr>   r   rV   r   expectedr   r   r   test_iinfo_reprK   s   zTestRepr.test_iinfo_reprc                 C   rd   )NzMfinfo(resolution=1e-06, min=-3.4028235e+38, max=3.4028235e+38, dtype=float32))r   re   r>   r   r@   rf   r   r   r   test_finfo_reprO   s   zTestRepr.test_finfo_reprN)r   r   r   rh   ri   r   r   r   r   rc   J   s    rc   c                   C   s   t d td d S )N
   g      @)r   r   r   r   r   r   test_instancesU   s   rk   c                 C   sZ   | j  D ]%\}}t|t|| t|dr*t|jt||j t|jt||j qd S )Nshape)__dict__itemsr   rD   hasattrrl   dtype)
discoveredma_likekeyvaluer   r   r   assert_ma_equalZ   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 d    n1 s6w   Y  t 	t jj
}|j|jfdkrW|dv rWt|td  d S |j|jfd	krl|dkrnt|td
  d S d S d S )N       @   ignoreall?    @     rv   P   p   r~      )r>   r?   r   r@   rA   ru   r   errstater   rp   itemsizeitr0   )r   rr   ld_mabytesr   r   r   test_known_typesc   s   r   c                  C   s  t jdd tt j} W d   n1 sw   Y  t t jj}tjddY}td | j	| j
fdkrF|dv rF| j t|d	ksEJ n#| j	| j
fd
kr^|dkr^| j t|d	ks]J n| j t|d	ksqJ W d   dS W d   dS W d   dS 1 sw   Y  dS )z<Test that the subnormal is zero warning is not being raised.ry   rz   NT)recordalwaysr|   r   r   r   rv   )r>   r   r   r   rp   r   warningscatch_warningssimplefilterr   r0   r:   len)r   r   wr   r   r   test_subnormal_warningu   s(   
	"r   c                  C   sR   t jd t jd  D ]} t | }t|jdk t|jdk  t|jdk q
d S )Nr   complex   r^   )r>   r_   r   r	   r5   r2   r0   )r   infor   r   r   test_plausible_finfo   s   
r   )__doc__r   numpyr>   
numpy.corer   r   r   r   r   r   numpy.testingr   r	   r
   numpy.core.getlimitsr   r   r   r    r!   r"   r#   r$   rM   rc   rk   ru   r   r   r   r   r   r   r   <module>   s(    	