B
     7[>!                 @   s   d dl Z d dlT d dlT 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S )    N)*c              C   s  dt _tdtd  krBtd  krBtd  krBtdksHn ttdtd  krvtd	  krvtd
ks|n txBtdD ]6} x0tdD ]$}td| |f | d|  kstqW qW ttddkstttddkstttddkstttddkstttddks(tttddks>tttddksTtttddksjtttddkstttddkstttddkstttddkstttddkstttddkstttdd kstttd!d"kstttd!d#ks0tttd$d%ksFtttd&d'ks\tttd(d)ksrtttd*d+kstd,S )-z&
    Test basic string conversion
       3z3.0z0003.z0.03e2g      @Z30z30.0z00030.g      >@
   z%ie%iz25000.0z2500.0z250.0z25.0z2.5z0.25z0.025z0.0025z0.00025z0.000025z2.5e-5r   z0.0z2.5e1000000000000000000000z2.5e+1000000000000000000000z2.6e-1000000000000000000000g-:<z1.23402834e-15g-:ּz-1.23402834e-15gK<ּz-1.2344e-15zmpf('-1.2343999999999999e-15')Z2163048125Lz2163048125.0z-2163048125lz-2163048125.0z-2163048125L/1088391168z-1.98738118113799z2163048125/1088391168lz1.98738118113799N)mpdpsmpfAssertionErrorrangestrrepr)ij r   8lib/python3.7/site-packages/mpmath/tests/test_convert.pytest_basic_string   s6    B4(r   c               C   s\   dt _ttddkstttdddks0tdt _dt_ttdddksRtdt_d S )NTg      @z2.5g      @z(2.5 + 3.5j)Fz
[2.5, 3.5])r   Zprettyr   r   r	   mpcZivZmpir   r   r   r   test_pretty&   s    r   c               C   s   t ddkstd S )Nz1.26 g)\(?)r   r	   r   r   r   r   test_str_whitespace/   s    r   c              C   sT   dt _y| } W n tk
r&   t} Y nX t| ddks<tt| dtksPtd S )Nr   z2.76gGz@inf)r   r   	NameErrorr   r   r	   r   )Zunicoder   r   r   test_unicode2   s    
r   c               C   sf  t tdddddkstt tddddd	ks4tt tdd
dddksNtt tdd
dddkshtt tddddd	kstt tdddddkstt tdddddkstt tdddd
d
ddkstt tdddd
d
ddkstt tdddddkstt tdddddks*tt tdddddksFtt tddddd ksbtd S )!Ng?r   F)strip_zerosz0.100000000000000g        T)Zshow_zero_exponentz0.0e+0r   z.0e+0z.0   z0.0gGz?   z1.23e+0gH?)r   Z	min_fixed	max_fixedz1.23456789000000e-2g<^@z1.23456789000000e+2g wU3Bi  )r   z212870000000000.0g `U]*@Cz2128700000000000.0g \UzRCz21287000000000000.0g~^3:Fz!2128700000000000000000000000000.0)to_str
from_floatr	   r   r   r   r   test_str_format;   s    r   c               C   s2   dt _tddttksttddttks.td S )Nr   z0.5r   )r   r   from_strZround_floorZfhalfr	   Zround_ceilingr   r   r   r   test_tight_string_conversionJ   s    r    c              C   sn   t d xXdD ]P} | t_xDtdD ]8}tt   d dt dd  }tt||ks$t	q$W qW dt_d	S )
zTest that eval(repr(x)) == x{   )r   r      2   d   i  g      ?r   ir$   r   N)
randomZseedr   r   r
   r   Zrandintevalr   r	   )r   r   ar   r   r   test_eval_repr_invariantQ   s    

 r(   c               C   s2   dt _ttddkstttddks.td S )Nr   Z1e600z1.0e+600Z1e10000z
1.0e+10000)r   r   r   r   r	   r   r   r   r   test_str_bugs[   s    r)   c               C   sr   t tdddkstt tdddks,tt tdddksBtt tddd	ksXtt td
ddksntd S )NgX9v?r   z.0e+0gV瞯<z.0e-15g  4&kCz.0e+15gV瞯Ҽz-.0e-15g  4&kz-.0e+15)r   r   r	   r   r   r   r   test_str_prec0a   s
    r*   c               C   sF   dt _tdddtdksttdddtdks2ttd	d
ksBtd S )Nr         5   )r   r   r      i   )r      r   )r   r   r   )r   r.   )r   r   Zfrom_rationalZround_nearestr	   Zto_rationalr   r   r   r   test_convert_rationalh   s    r3   c              C   s   G dd d} G dd d}t d|   dks2t|  t d dksHtt |  dksZt| td tddksvttd|  tddkstt| d	kstd S )
Nc               @   s   e Zd Zedd ZdS )z test_custom_class.<locals>.mympfc             S   s
   t djS )Ng      @)r   _mpf_)selfr   r   r   r4   p   s    z&test_custom_class.<locals>.mympf._mpf_N)__name__
__module____qualname__propertyr4   r   r   r   r   mympfo   s   r:   c               @   s   e Zd Zedd ZdS )z test_custom_class.<locals>.mympcc             S   s   t djt djfS )Ng      @g      @)r   r4   )r5   r   r   r   _mpc_t   s    z&test_custom_class.<locals>.mympc._mpc_N)r6   r7   r8   r9   r;   r   r   r   r   mympcs   s   r<   r.   g      @g      @g      @y      @      @)r   r	   r   )r:   r<   r   r   r   test_custom_classn   s    r=   c        	      C   s  G dd d} G dd d}G dd d}t d}td}|  }| }| }xdD ]}|t_|| t d	svt|| t d	st|| td	d
st|| td	d
st|| td	st|| td	st|| td	d
st|| td	d
st||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||  ||k ||k ||k ||k ||k ||k ||k ||k qTW dt_||tkszt||tkst|	|tkst|
|tkst||tkst||tkst||tkst||tkstt|dr&||tks&t||tks:t||tksNt||tksbt||tksvt||tkst||tkst||tkst||tkst||tkst||tkst||tkst||tkst||tks*t||tks>t||tksRt||tksft||tkszt||tkst||tkst||tkst||tkst||tkstd S )Nc               @   s   e Zd ZdS )z0test_conversion_methods.<locals>.SomethingRandomN)r6   r7   r8   r   r   r   r   SomethingRandom   s   r>   c               @   s   e Zd Zdd ZdS )z.test_conversion_methods.<locals>.SomethingRealc             S   s   t td||S )Nz1.3)r   Zmake_mpfr   )r5   precroundingr   r   r   _mpmath_   s    z7test_conversion_methods.<locals>.SomethingReal._mpmath_N)r6   r7   r8   rA   r   r   r   r   SomethingReal   s   rB   c               @   s   e Zd Zdd ZdS )z1test_conversion_methods.<locals>.SomethingComplexc             S   s   t td||td||fS )Nz1.3z1.7)r   Zmake_mpcr   )r5   r?   r@   r   r   r   rA      s    z:test_conversion_methods.<locals>.SomethingComplex._mpmath_N)r6   r7   r8   rA   r   r   r   r   SomethingComplex   s   rC   r   )r   -   z4.3z1.7r   __cmp__)r   r   r   r   aer	   __add__NotImplemented__radd____lt____gt____le____ge____eq____ne__hasattrrE   __sub____rsub____mul____rmul__Z__div__Z__rdiv____mod____rmod____pow____rpow__)	r>   rB   rC   xzr'   ywdr   r   r   test_conversion_methods~   s                                       r^   c               C   sT   t ddkstt dtddks&tt dtddks<tt dtd	ksPtd S )
Nz1/2g      ?z
(1.0+1.0j)r   z(1.2e-10 - 3.4e5j)z1.2e-10z-3.4e5Z1jy              ?)Z	mpmathifyr	   r   r   r   r   r   test_mpmathify   s    r_   c              C   sR  y,dd l } ddlm} ddlm} dd l}W n tk
r@   d S X x| jjj	 D ]}t
|| jrr|tdd}n*t
|| jr|d}nt
|| jr|d}y*| t| |t|| | }W n   wRY nX |dk sRtqRW tj}dt_tj| _t|dd	ttd
s tt|d|d	 ttd
sHt|t_d S )Nr   )Fraction)Decimalg      ?g      r.   g      <i  r   z2/3)ZnumpyZ	fractionsr`   decimalra   ImportErrorZcoreZnumerictypesZtypeDictvalues
issubclassZcomplexfloatingcomplexZfloatingZintegerabstypeZsqrtr	   r   r?   r   Z
getcontextrF   r   )Znpr`   ra   rb   ZnptyperY   ZdiffZoldprecr   r   r   test_compatibility   s2    
 * "(ri   )r%   ZmpmathZmpmath.libmpr   r   r   r   r   r    r(   r)   r*   r3   r=   r^   r_   ri   r   r   r   r   <module>   s     		
A