o
    HXh	                    @   s   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Zd dlZd dlm	Z	 d dl
mZmZ d dlmZmZmZmZ edZedZeedZeedZeeed	d
Zejep^ejZejedZ G dd deZ!G dd deZ"G dd dej#Z$eG dd dej#Z%dZ&e'e(e&Z)dZ*e'e(e*Z+dZ,e'e(e,Z-dZ.e'e(e.Z/eG dd dej#Z0G dd dej#Z1G dd dej#Z2G dd dej#Z3e	j4G d d! d!ej#Z5G d"d# d#ej#Z6ej7Z8ej9Z:G d$d% d%ej#Z;e<d&kre=  dS dS )'    N)support)VALID_UNDERSCORE_LITERALSINVALID_UNDERSCORE_LITERALS)isinfisnancopysignldexpinfnan__getformat__zrequires __getformat____setformat__zrequires __setformat__zformatfloat_testcases.txtc                   @      e Zd ZdS )FloatSubclassN__name__
__module____qualname__ r   r   9/opt/python-3.10.19/usr/lib/python3.10/test/test_float.pyr          r   c                   @   r   )OtherFloatSubclassNr   r   r   r   r   r      r   r   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	
dd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e	jd"d# Ze	jd$d% Zd&d' Zd(d) Zd*S )+GeneralFloatCasesc                 C   sT  |  tdd |  tdd |  tdd | ttd | ttd | ttd | ttd | ttd	 | ttd
 | ttd | ttd | ttd | ttd | ttd | tti  | tdti  | ttd | ttd | ttd |  tdd |  tdd td td | ttd d S )NQ	@i:  g     s@  3.14  	  0x3.1    -0x3.p-1    +0x3.p-1  z++3.14z+-3.14z-+3.14z--3.14z.nanz+.inf.z-.z
not 'dict'u   z-1.7d29z3D-14u     ٣.١٤  u
    3.14 s  .1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111a  .1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111u   こんにちは)assertEqualfloatassertRaises
ValueError	TypeErrorassertRaisesRegexselfr   r   r   
test_float$   s0   zGeneralFloatCases.test_floatc                 C   s   |  t d d S )N        )r   r   r$   r   r   r   test_noargsC   s   zGeneralFloatCases.test_noargsc              	      s   t D ]% t fdddD s'| t t  | t t dd qtD ]  dv r1q*t fdddD sC| tt  q*| ttd | ttd	 | ttd
 | ttd | ttd | ttd d S )Nc                 3       | ]}| v V  qd S Nr   .0ZchZlitr   r   	<genexpr>H       z5GeneralFloatCases.test_underscores.<locals>.<genexpr>ZjJxXoObB_ )Z0_7Z09_99c                 3   r)   r*   r   r+   r-   r   r   r.   N   r/   Z_NaNZNa_NZIN_Fz-_INFz-INF_s   0_.9)	r   anyr   r   evalreplacer   r    r!   r$   r   r-   r   test_underscoresF   s"   z"GeneralFloatCases.test_underscoresc              
      s
  G dd dt  G dd dt}G dd dt}tt fdd||tg}zd	d
lm W n	 ty5   Y n
w |fdd |D ]A}|d}| t|, | 	t
|d | td t
|d W d    n1 snw   Y  W d    n1 s}w   Y  qAd S )Nc                   @   r   )zAGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomStrNr   r   r   r   r   	CustomStr^       r6   c                   @   r   )zCGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomBytesNr   r   r   r   r   CustomBytes_   r7   r8   c                   @   r   )zGGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomByteArrayNr   r   r   r   r   CustomByteArray`   r7   r9   c                    s    |   S r*   )decodeb)r6   r   r   <lambda>e   r7   z@GeneralFloatCases.test_non_numeric_input_types.<locals>.<lambda>r   arrayc                    s
    d| S )NBr   r;   r>   r   r   r=   o   s   
 s    3.14  r   zcould not converts   AAAAAAAAAAAAAAAA)strbytes	bytearray
memoryviewr?   ImportErrorappendZsubTesttyper   r   r#   r!   )r%   r8   r9   Z	factoriesfxr   )r6   r?   r   test_non_numeric_input_types[   s6   
z.GeneralFloatCases.test_non_numeric_input_typesc                 C   s   |  ttddd d |  ttddd d |  ttddd d |  ttddd d |  ttddd d d S )	Ns   12.3      gffffff@s   12.3 s   12.3 s   12.3As   12.34)r   r   rD   r$   r   r   r   test_float_memoryviewx   s
    z'GeneralFloatCases.test_float_memoryviewc                    sx    fdd}|d |d |d |d |d |d |d	 |d
 |d |d |d |d |d d S )Nc                    sX    j td| f d}t|  W d    n1 sw   Y   t|jd| f  d S )Nz	float(%r))msgz%could not convert string to float: %r)r    r!   r   r   rA   	exception)scmr$   r   r   check   s   
z3GeneralFloatCases.test_error_message.<locals>.check   ½u   123½z  123 456  s     123 456  r1    z	 
u   ٣١٤!z123 z123  245z123 245s   123 s   123r   )r%   rR   r   r$   r   test_error_message   s   z$GeneralFloatCases.test_error_message
LC_NUMERICfr_FRde_DEc                 C   s*  dd l }| d dks| d | tdd | tdd | tdd	 | td
d | tdd | tdd | tdd | tdd | tdd | ttd | ttd | ttd | ttd | ttd | ttd | tdd | tdd d S ) Nr   decimal_point,zdecimal_point is not ","r   r   z+3.14  z-3.14  gQ	z.14  gQ?z3.        @z3.e3  g     p@z3.2e3  g      @z2.5e-1        ?z5e-1      ?z  3,14  z	  +3,14  z	  -3,14  r   r   r   z
  25.e-1        @z
  .25e-1  g?)locale
localeconvZskipTestr   r   r    r!   ZassertAlmostEqual)r%   r_   r   r   r   test_float_with_comma   s(   
z'GeneralFloatCases.test_float_with_commac           
      C   sX  G dd dt }G dd dt}G dd dt}G dd dt}G d	d
 d
t}| t| d | t| d | t | t|dd W d    n1 sTw   Y  | tt|d | t|dd G dd d}| ttj	|  G dd d}| t | t| d W d    n1 sw   Y  | t | 
tt| t W d    n1 sw   Y  | t | t| d W d    n1 sw   Y  | t | 
tt| t W d    n1 sw   Y  G dd d}| t|dd | tt|dd  G dd d}	| tt|	  d S )Nc                   @      e Zd Zdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo1c                 S      dS N      E@r   r$   r   r   r   	__float__      z>GeneralFloatCases.test_floatconversion.<locals>.Foo1.__float__Nr   r   r   rf   r   r   r   r   Foo1       ri   c                   @   rb   )z4GeneralFloatCases.test_floatconversion.<locals>.Foo2c                 S   rc   rd   r   r$   r   r   r   rf      rg   z>GeneralFloatCases.test_floatconversion.<locals>.Foo2.__float__Nrh   r   r   r   r   Foo2   rj   rk   c                   @   s   e Zd ZdddZdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo3r'   c                 S   s   t | d| S )N   r   __new__clsvaluer   r   r   rn         z<GeneralFloatCases.test_floatconversion.<locals>.Foo3.__new__c                 S   s   | S r*   r   r$   r   r   r   rf      rg   z>GeneralFloatCases.test_floatconversion.<locals>.Foo3.__float__N)r'   )r   r   r   rn   rf   r   r   r   r   Foo3   s    
rs   c                   @   rb   )z4GeneralFloatCases.test_floatconversion.<locals>.Foo4c                 S   rc   N*   r   r$   r   r   r   rf      rg   z>GeneralFloatCases.test_floatconversion.<locals>.Foo4.__float__Nrh   r   r   r   r   Foo4   rj   rv   c                   @   rb   )z6GeneralFloatCases.test_floatconversion.<locals>.FooStrc                 S   s   t t| d S NrK   )r   rA   r$   r   r   r   rf      rr   z@GeneralFloatCases.test_floatconversion.<locals>.FooStr.__float__Nrh   r   r   r   r   FooStr   rj   rx   re      ru   8g      "@c                   @   rb   )z4GeneralFloatCases.test_floatconversion.<locals>.Foo5c                 S   rc   )Nr1   r   r$   r   r   r   rf      rg   z>GeneralFloatCases.test_floatconversion.<locals>.Foo5.__float__Nrh   r   r   r   r   Foo5   rj   r{   c                   @   rb   )z1GeneralFloatCases.test_floatconversion.<locals>.Fc                 S   s   t dS rd   )r   r$   r   r   r   rf      s   z;GeneralFloatCases.test_floatconversion.<locals>.F.__float__Nrh   r   r   r   r   F   rj   r|   c                   @   s   e Zd Zdd Zdd ZdS )z7GeneralFloatCases.test_floatconversion.<locals>.MyIndexc                 S   s
   || _ d S r*   rq   r%   rq   r   r   r   __init__      
z@GeneralFloatCases.test_floatconversion.<locals>.MyIndex.__init__c                 S   s   | j S r*   r}   r$   r   r   r   	__index__   s   zAGeneralFloatCases.test_floatconversion.<locals>.MyIndex.__index__N)r   r   r   r   r   r   r   r   r   MyIndex   s    r   rl   i  c                   @   rb   )z5GeneralFloatCases.test_floatconversion.<locals>.MyIntc                 S   rc   rt   r   r$   r   r   r   __int__   rg   z=GeneralFloatCases.test_floatconversion.<locals>.MyInt.__int__N)r   r   r   r   r   r   r   r   MyInt   rj   r   )objectr   rA   r   ZassertWarnsDeprecationWarningr    r"   timesleepassertIsrG   r   OverflowError)
r%   ri   rk   rs   rv   rx   r{   r|   r   r   r   r   r   test_floatconversion   s@   z&GeneralFloatCases.test_floatconversionc                 C   s<   |  td tdd W d    d S 1 sw   Y  d S )Nzkeyword argumentz3.14rI   )r#   r"   r   r$   r   r   r   test_keyword_args   s   "z#GeneralFloatCases.test_keyword_argsc                 C   sD   |  d  | d  |  td  |  td  d S )Ng?      ?r
   r	   )ZassertFalse
is_integer
assertTruer   r$   r   r   r   test_is_integer   s   z!GeneralFloatCases.test_is_integerc                 C   s^  dD ]\}}|  | | qtdD ]!}t }|dtdd 9 }| \}}|  t||| qtj}|  |dd|td   |  |d	d
|td   |  |dd
|td   |  |dd|td   |  |dd|td   |  |dd|td   | 	t
tdj | 	t
tdj | 	ttdj d S )N))g      ?)      )g      )ir   )r'   )r   rK   )g      '@)   rl   '  
   id   r   rK   r'      rl   r^   r]   l   L33 l         @ g @lL33 g ig     hr	   -infr
   )r   as_integer_ratiorangerandomrandintr   __truediv__	fractionsZFractionr    r   r!   )r%   rH   ZratioindRr   r   r   test_floatasratio  s:   z#GeneralFloatCases.test_floatasratioc                 C   sj  t t  ddtf}|D ]2}| ||g | ||f | ||h | ||d i | |g|dd|  | || q
|D ]s}| |g|gkd||f  | |f|fkd||f  | |h|hkd||f  | |d i|d ikd||f  |g|f|h|d if\}}}}| ||kd	|  | ||kd
|  | ||kd|  | ||kd|  q?d S )Nr'   r   rK   z[].count('%r') != 1z[%r] != [%r]z(%r,) != (%r,)z{%r} != {%r}z{%r : None} != {%r : None}z[%r] not equal to itselfz(%r,) not equal to itselfz{%r} not equal to itselfz{%r : None} not equal to itself)INFNANassertInr   countr   )r%   ZfloatsrH   ltrP   r   r   r   r   test_float_containment#  s*   z(GeneralFloatCases.test_float_containmentc                 C   s$   |  |td|f|td|f d S )Nr   )r   r   )r%   ar<   r   r   r   assertEqualAndEqualSign<  s   $z)GeneralFloatCases.assertEqualAndEqualSignc                 C   s   |  td t | td d | td d | td d | td d | td d | td	 d
 | td d | td d | ttdj | ttdj | ttdj d S )Nr]   r   r   rK         ?                  NݯbNݯr
   r	   r   )assertIsInstancer   	__floor__intr   r    r!   r   r$   r   r   r   test_float_floorB     z"GeneralFloatCases.test_float_floorc                 C   s   |  td t | td d | td d | td d | td d | td d	 | td
 d	 | td d | td d | ttdj | ttdj | ttdj d S )Nr]   rK   r   r   rl   r   r   r   r   r   r   r   r
   r	   r   )r   r   __ceil__r   r   r    r!   r   r$   r   r   r   test_float_ceilP  r   z!GeneralFloatCases.test_float_ceilc                 C   s   t j}| |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd d S )Nr   r   r'   0.+       0.++)operatormodr   )r%   r   r   r   r   test_float_mod^  s   z GeneralFloatCases.test_float_modc                 C   s	  t tj fD ]}| t|t t | t|dt | t|dt | t|dt | t|dt | t|dt | t|dt | t|dt | t|tt | t|tt | t|tt  | t|td | t|td | t|td | t|td | t|td | t|td | t|tt | t|dd | t|dd | t|dd | t|dd | t|dd | t|dd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |dt d | |dtd | |dt d | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |dtd | |dtd | |t dd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |tdd | |tdd | |t dd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |tdd | |tdd | 	t
|ddt | 	t
|ddt | 	t
|ddt | 	t
|ddt | 	t
|ddt | 	t
|ddt | |dt t | |dt t | |dt t | |dt t | |t t d | |dt d | |dt d | |tt d | |dtd | |dtd | |dtd | |dtd | |t tt | |dtt | |dtt | |ttt | |t dd | |t dd | |t dd | |t dt  | |t dt | |t dt | |tdt | |tdt | |tdt | |tdd | |tdd | |tdd | |ddd	 | |ddd | |ddd | |ddd | |ddd | |ddd
 | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd	 | |ddd | |ddd | |ddd | |ddd | |ddd
 | |ddd | |ddd | |ddd | |ddd | |ddd | 	t
|ddt | |ddd | |ddd | |ddd | |ddd | |ddd | 	t
|ddt | |ddd | |ddd | |ddd | |ddd qd S )Ng       r   r   r   r'   r]          @r   r\   g      @}Ô%I}Ô%ITg     @g     Bg     Dg     @@g     B@g     D@)powr   r   r   r   r   r    ZeroDivisionErrorr   r   rG   complex)r%   Zpow_opr   r   r   test_float_powr  s   z GeneralFloatCases.test_float_powc                 C   s   t ddD ]}| tt|t| q| tttjjtttjj | ttdtjj	 | ttdtjj	  d S )Ni   r	   r   )
r   r   hashr   sys
float_infomaxr   	hash_infor	   r%   rI   r   r   r   	test_hash;  s   zGeneralFloatCases.test_hashc                 C   s`   t d}| t|t| G dd d}G dd dt |}|d}| t|t| d S )Nr
   c                   @   rb   )z*GeneralFloatCases.test_hash_nan.<locals>.Hc                 S   rc   rt   r   r$   r   r   r   __hash__G  rg   z3GeneralFloatCases.test_hash_nan.<locals>.H.__hash__N)r   r   r   r   r   r   r   r   HF  rj   r   c                   @   r   )z*GeneralFloatCases.test_hash_nan.<locals>.FNr   r   r   r   r   r|   I  r   r|   )r   r   r   r   r   )r%   rq   r   r|   r   r   r   test_hash_nanC  s   zGeneralFloatCases.test_hash_nanN)r   r   r   r&   r(   r5   rJ   rM   rU   r   Zrun_with_localera   r   r   r   r   r   r   r   r   requires_IEEE_754r   r   r   r   r   r   r   r   r   "   s0    
C!

 Ir   c                   @   ,   e Zd Zdd Zdd Zdd Zdd Zd	S )
FormatFunctionsTestCasec                 C   s   t dt dd| _d S )Ndoubler   r   r   )r   r   save_formatsr$   r   r   r   setUpR  s   zFormatFunctionsTestCase.setUpc                 C   (   t d| jd  t d| jd  d S Nr   r   r   r   r   r$   r   r   r   tearDownV     z FormatFunctionsTestCase.tearDownc                 C   sP   |  tdg d |  tdg d | ttjd | ttjd d S )Nr   )unknownIEEE, big-endianIEEE, little-endianr   chickenrK   )r   r   r   r    r!   r"   r$   r   r   r   test_getformatZ  s   z&FormatFunctionsTestCase.test_getformatc                 C   s   dD ]E}t |d | j| dkr| tt j|d n#| j| dkr,| tt j|d n| tt j|d | tt j|d | tt j|d q| tt jdd d S )Nr   r   r   r   r   )r   r   r   r    r!   )r%   r   r   r   r   test_setformatb  s,   





z&FormatFunctionsTestCase.test_setformatN)r   r   r   r   r   r   r   r   r   r   r   r   O  s
    r   s         s         s     s     c                   @   r   )
UnknownFormatTestCasec                 C   s4   t dt dd| _t dd t dd d S )Nr   r   r   r   )r   r   r   r   r$   r   r   r   r     s
   zUnknownFormatTestCase.setUpc                 C   r   r   r   r$   r   r   r   r     r   zUnknownFormatTestCase.tearDownc                 C   <   dt fdtfdtfdtffD ]\}}| ttj|| qd S Nz>dz<d)BE_DOUBLE_INFBE_DOUBLE_NANLE_DOUBLE_INFLE_DOUBLE_NANr    r!   structunpackr%   fmtdatar   r   r    test_double_specials_dont_unpack     z6UnknownFormatTestCase.test_double_specials_dont_unpackc                 C   r   Nz>f<f)BE_FLOAT_INFBE_FLOAT_NANLE_FLOAT_INFLE_FLOAT_NANr    r!   r   r   r   r   r   r   test_float_specials_dont_unpack  r   z5UnknownFormatTestCase.test_float_specials_dont_unpackN)r   r   r   r   r   r   r   r   r   r   r   r     s
    r   c                   @   s6   e Zd Zejdd Zejdd Zejdd ZdS )IEEEFormatTestCasec                 C   6   dt fdtfdtfdtffD ]
\}}t|| qd S r   )r   r   r   r   r   r   r   r   r   r   test_double_specials_do_unpack     z1IEEEFormatTestCase.test_double_specials_do_unpackc                 C   r   r   )r   r   r   r   r   r   r   r   r   r   test_float_specials_do_unpack  r   z0IEEEFormatTestCase.test_float_specials_do_unpackc                 C   sJ   ddl m} | tddtd| | tddtd|  d S )Nr   )FLT_MAXr   gnGgn)Z	_testcapir  r   r   pack)r%   r  r   r   r   test_serialized_float_rounding  s   "z1IEEEFormatTestCase.test_serialized_float_roundingN)r   r   r   r   r   r   r   r  r   r   r   r   r     s    

r   c                   @   s2   e Zd Zdd Zejdd Zdd Zdd Zd	S )
FormatTestCasec                 C   s<  |  tddd |  tddd |  tddd |  tddd d	}|  t|dt| |  t|d
t| |  t|dt| |  t|dt| |  tddd |  tddd |  tddd |  tddd |  tddd |  tddd |  tddd | ttdd dd ttdtdd D dd ttdtd d D  D ]>}|d!vr| ttd| | ttd| | ttd| | ttd"| | ttd#| | ttd$| | ttd%| q|  ttdd& |  ttd'd( |  ttdd) |  ttd'd* d S )+Nr'   rH   z0.000000r1   0.0g{Gz?0.01gg%I$I,@->2r   z1.000000r   z	-1.000000z fz	 1.000000z+fz	+1.000000%z-100.000000%r[   rP   c                 S      g | ]}t |qS r   chrr,   rI   r   r   r   
<listcomp>      z.FormatTestCase.test_format.<locals>.<listcomp>r   zrK   c                 S   r  r   r  r  r   r   r   r    r  AZzeEfFgGn%r   r   r   r   r
   r|   r   r	   r   )	r   formatrA   r    r!   r   ordr   r   )r%   rI   format_specr   r   r   test_format  sB   zFormatTestCase.test_formatc                 C   s   t tddC}|D ]7}|drq	| }|sq	ttj|d\}}| \}}| |t| | | |t|  d|  q	W d    d S 1 sLw   Y  d S )Nutf-8encodingz--z->r  )	openformat_testfile
startswithstripmaprA   splitr   r   )r%   ZtestfilelineZlhsZrhsr   argr   r   r   test_format_testfile  s   
"z#FormatTestCase.test_format_testfilec                 C   s:   |  tddd |  tddd |  tddd d S )Nw/^@z.4z123.5g
ףp=J@z	1.235e+03g@z	1.235e+04r   r  r$   r   r   r   test_issue5864   s   zFormatTestCase.test_issue5864c                 C   s$  |  tddd |  tddd |  tddd |  tdd	d
 |  tddd |  tddd |  tddd
 |  tddd |  tddd |  tddd |  tddd |  tdd	d |  tddd |  tddd |  tddd |  tddd d S )Ng     ^@Z00z123.0g(\^@Z00fz
123.340000Z00ez1.233400e+02Z00gz123.34z00.10fz123.3400000000z00.10ez1.2334000000e+02z00.10gZ01fg     ^z-123.0g(\^z-123.340000z-1.233400e+02z-123.34z-123.3400000000z-1.2334000000e+02r&  r$   r   r   r   test_issue35560  s    zFormatTestCase.test_issue35560N)	r   r   r   r  r   r   r$  r'  r(  r   r   r   r   r    s    5
r  c                   @   s4   e Zd Zdd Zeeedddkddd Zd	S )
ReprTestCasec                 C   s   t tjtjtd ddd(}|D ]}| }|r!|dr"qt|}| 	|tt
| qW d    d S 1 s<w   Y  d S )Nr   zfloating_points.txtr  r  #)r  ospathjoinr!  __file__r  r  r3   r   repr)r%   Zfloats_filer"  vr   r   r   	test_repr  s   "zReprTestCase.test_reprfloat_repr_styler1   short.applies only when using short float repr stylec                 C   s~   g d}|D ]6}d| }|  |tt| |  |tt| |  tt|tt| |  tt|tt| qd S )N)r  1.0r  z0.02z0.03z0.04z0.05z
1.23456789z10.0z100.0z1000000000000000.0z9999999999999990.0z1e+16z1e+17z0.001z0.001001z0.00010000000000001z0.0001z9.999999999999e-05z1e-05z8.72293771110361e+25z7.47005307342313e+26z2.86438000439698e+28z8.89142905246179e+28z3.08578087079232e+35r  )r   r/  r   rA   )r%   Ztest_stringsrP   Znegsr   r   r   test_short_repr#  s   
"zReprTestCase.test_short_reprN)	r   r   r   r1  unittest
skipUnlessgetattrr   r6  r   r   r   r   r)    s    
r)  c                   @   s|   e Zd Zdd Zdd Zdd Zdd Zee	e
d	d
dkddd Zee	e
d	d
dkddd Zdd Zdd ZdS )RoundTestCasec                 C   sr   |  ttt |  ttt  |  ttt |  tttd |  ttt d |  tttd |  ttdd d S )Nr'   r   zceci n'est pas un integerr   y              ?)r    r   roundr   r!   r   r"   r$   r   r   r   test_inf_nanZ  s   zRoundTestCase.test_inf_nanc                 C   s   dddddddd fD ]&}|  td	|d	 |  td
|d
 |  td|d |  td|d q|  tddd |  tddd |  tddd |  tddd |  tddd d S )NiD  iE  i  il        l        rl   r   r%  w/^u <7~      gP.5_i,  i3  go!	i4  i5  gS    i;  gi    r   r;  r%   r   r   r   r   test_large_nc  s   zRoundTestCase.test_large_nc                 C   sj   dddddddd  fD ]&}|  td	|d
 |  td|d |  td|d
 |  td|d
 qd S )Niipi  i   l    rl   r   r%  r'   r=  r   r>  r?  r@  rA  r   r   r   test_small_no  s   zRoundTestCase.test_small_nc                 C   s$   |  ttdd |  ttdd d S )Ng3t<{rC  gv;w0B)r    r   r;  r$   r   r   r   test_overflowv  s   zRoundTestCase.test_overflowr2  r1   r3  r4  c                 C   s   |  tddd |  tddd |  tddd |  tddd	 |  td
dd	 |  tddd |  tddd |  tddd |  tddd |  tddd d S )Ng      CrK   gB   g      9@r   g      4@g     A@g      D@g     F@g     K@g      N@g     @P@g     R@g      T@g     @U@g     W@g      Y@r@  r$   r   r   r   test_previous_round_bugsz  s   z&RoundTestCase.test_previous_round_bugsc                 C   s  t dD ]>}|d }| tt|dt|d | tt|dt|d | tt|dt|d | tt|d	t|d
 qt dddD ]>}|d }| tt|dt|d | tt|dt|d | tt|dt|d | tt|d	t|d
 qIt dD ]>}t }| tt|dt|d | tt|dt|d | tt|dt|d | tt|d	t|d
 qd S )Ni  g     @@z.0fr   z.1frK   z.2frl   z.3frF  r   i  r   )r   r   r   r  r;  r   )r%   r   rI   r   r   r   test_matches_float_format  s&   z'RoundTestCase.test_matches_float_formatc                    s    fdd}dD ]`}d|dd   }d|dd   }||t d ||t  d ||td	 ||t d	 ||t d
 ||t  d ||td ||t d ||t d ||t  d ||td ||t d qd S )Nc                    s6     | | ||  | dd  }   t|| ||  d S rw   r&  )r   rq   expectedr$   r   r   test  s   z0RoundTestCase.test_format_specials.<locals>.test)z%ez%fz%gz%.0ez%.6fz%.20gz%#ez%#fz%#gz%#.20ez%#.15fz%#.3gz%+rK   z% r	   r   r
   +inf+nanz infz nan)r   r   )r%   rJ  r   ZpfmtZsfmtr   r$   r   test_format_specials  s"   z"RoundTestCase.test_format_specialsc                 C   sx   t dt dd t dd dfD ]}| |d | |t qt dt dd t dd dfD ]}| |d | |t q+d S )NgGz?)ZndigitsrK   g{Gz?rl   )r;  r   r   r   r   r   r   r   test_None_ndigits  s     zRoundTestCase.test_None_ndigitsN)r   r   r   r<  rB  rD  rE  r7  r8  r9  r   rG  rH  rM  rN  r   r   r   r   r:  W  s    	

r:  c                   @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Ze	e
edddkddd ZdS )
InfNanTestc                 C   s  |  ttd |  ttd |  ttd |  ttd |  ttd |  ttd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttd	d | ttd
d | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttd | ttd | ttd | ttd | ttd | ttd | ttd | ttd | ttd | ttd | ttd | ttd | ttd | ttd d S )Nr	   rK  r   Zinfinityz	+infinity	-infinityr   +Infz-iNFInfinityz	+iNfInItYz	-INFINITYinfoz+infoz-infoinz+inz-inZinfinitz+Infinz-INFIZ	infinitysz++Infz-+infz
+-infinityz
--Infinity)r   r   r   r   r/  rA   r    r!   r$   r   r   r   test_inf_from_str  sL   zInfNanTest.test_inf_from_strc                 C   sD   |  tdd |  tdd |  tdd |  tdd d S )Ng      r	   g      r   r   r/  rA   r$   r   r   r   test_inf_as_str     zInfNanTest.test_inf_as_strc                 C   sz  |  ttd |  ttd |  ttd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttdd | ttd | ttd | ttd	 | ttd
 | ttd | ttd | ttd | ttd | ttd | ttd d S )Nr
   rL  -nanr   z+NAn-NaNZnanaz+nanaz-nanaZnaz+naz-naz++nanz-+NAN+-NaNz--nAn)r   r   r   r   r/  rA   r    r!   r$   r   r   r   test_nan_from_str  s,   zInfNanTest.test_nan_from_strc                 C   sD   |  tdd |  tdd |  tdd |  tdd d S )Ng      r
   g      g      g      rV  r$   r   r   r   test_nan_as_str   rX  zInfNanTest.test_nan_as_strc                 C   0   |  tdtdd |  tdtdd d S )Nr   r	   r   r   r   r   r   r$   r   r   r   test_inf_signs'  s   zInfNanTest.test_inf_signsr2  r1   r3  r4  c                 C   r^  )Nr   r
   rY  r   r_  r$   r   r   r   test_nan_signs+  s   zInfNanTest.test_nan_signsN)r   r   r   rU  rW  r\  r]  r`  r7  r8  r9  r   ra  r   r   r   r   rO    s    -rO  c                   @   sd   e Zd ZedZedZedZe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 )HexFloatTestCasez0x.fffffffffffff8p+1024z	0x1p-1022z0x0.0000000000001p-1022z0x0.0000000000001p0c                 C   sd   t |st |rt |t |krd S n||kr'|dks%td|td|kr'd S | d||f  d S )Nr'   r   z%r not identical to %r)r   r   fail)r%   rI   yr   r   r   	identical<  s   $zHexFloatTestCase.identicalc                 C   sb   |  | jtdd |  | jtdd |  | jtdd |  | jdtddtdd   d S )Nr   iiir   i  i  )re  MINr   TINYEPSMAXr$   r   r   r   	test_endsF  s   &zHexFloatTestCase.test_endsc              	   C   sH   g d}|D ]}zt |}W n	 ty   Y qw | d||f  qd S )N)3Zinfiz-Infinitz++infz-+Infz--nanr[  ZsnanZNaNsZnnaZanZnfZnfinityZinityZiinityZ0xnanr1   rT   zx1.0p0z0xX1.0p0z	+ 0x1.0p0z	- 0x1.0p0z0 x1.0p0z0x 1.0p0z	0x1 2.0p0z	+0x1 .0p0z0x1. 0p0z
-0x1.0 1p0z	-0x1.0 p0z
+0x1.0p +0z	0x1.0p -0z0x1.0p 0z
+0x1.0p+ 0z
-0x1.0p- 0z
++0x1.0p-0z	--0x1.0p0z
+-0x1.0p+0z	-+0x1.0p0z	0x1.0p++0z
+0x1.0p+-0z
-0x1.0p-+0z	0x1.0p--0z0x1.0.p0z0x.p0z0x1,p0Z0x1pau   0x1p０u   ０x1p0u   0x１p0u	   0x1.０p0z0x1p0 
 0x2p0z0x1p0  0x1p0z>Expected float.fromhex(%r) to raise ValueError; got %r instead)fromHexr!   rc  )r%   Zinvalid_inputsrI   resultr   r   r   test_invalid_inputsL  s   5z$HexFloatTestCase.test_invalid_inputsc                 C   sh   dt fdt  fdtfdddg}g d}|D ]\}}|D ]}|D ]}t|| | }| || qqqd S )Nr	   z	-Infinityr
   )r5  r   )z-0x.2g      )z-0.0r   )r1   rT   	
z
 	)r   r   rk  re  )r%   Zvalue_pairs
whitespaceinprI  ZleadtrailZgotr   r   r   test_whitespace  s    
z HexFloatTestCase.test_whitespacec                 C   s\  | j }| j}| j}| j}| tdt | tdt | tdt  | tdt | tdt | tdt | tdt  | tdt  | td	t | td
t | tdt | tdt | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | td d | td!d | td"d | td#d | td$d | td%d | td&d | td'd | td(d | td)d | td*d+ | td,d+ | td-d+ | td.d+ | td/d0 | td1d0 | td2d0 | td3d0 | td4d0 | td5d0 | td6d0 | td7d0 td8}| td9| | td:| | td;| | td<| | td=| | td>| | td?| | td@| | tdA| | tdB| | td8| | tdC| | tdD| | tdE| | tdF| | tdG| | tdH| | tdI| | tdJ| | tdK| | tdL| | tdM| | tdN| | tdO| | tdP| | tdQ| | tdR| | tdS| | tdT| | tdU| | tdV| | tdW| | t	tdX | t	tdY | t	tdZ | t	td[ | t	td\ | t	td] | t	td^ | t	td_ | t	td` | t	tda | t	tdb | t	tdc | t	tdd | t	tde | t	tdf | t	tdg | t	tdh | t	tdi | t	tdj | tdk| | tdl|  | tdm| | tdndo | tdpdo | tdqdr | tdsdo | tdtdr | tdudo | tdvdo | tdwdr | tdxdr | tdydo | tdzdr | td{dr | td|dr | td}do | td~dr | tddo | tddo | tddr | tddr | tddo | tddr | tddr | td| | td|  | td| | tddo | tddo | td| | td| | td| | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tddr | tddr | td|  | td|  | td|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | td|d|   | td|d|   | td|d|   | td|d|   | td|d|   | td|d|   | td|d|   | td|d|   | td|d|   | td|d|   | td||  | td||  | td||  | td||  | td||  | td||  | td||  | td| | td| | td| | tdÃ| | tdă| | tdŃ| | tdƃ| | tdǃ| | tdȃ| | tdɃ||  | tdʃ||  | td˃||  | td̃||  | td̓||  | td΃||  | tdσ||  | tdЃ|d|   | tdуd|  | td҃d|  | tdӃd|  | tdԃd|  | tdՃd|  | tdփd|d   | td׃d|d   | td؃d|d   | tdكd|d   | tdڃd|d   | tdۃd|d   | td܃d|d   | td݃d | tdރd | td߃d | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tdd|  | tddd|   | tddd|   | tddd|   | td dd|   | tddd|   | tddd|   | tddd|   | tddd|   | tddd|   | tddd|   | tddo | tddo | td	| | td
do | tddo | td| | tddo | td| | tddo | tddo | tddr | tddo d S (  Nr	   rQ  z-INFZiNfrR  z	+INFINITYrP  z	-iNFiNitYr
   z+NaNrZ  z-nAN1r   z+1z1.r5  z1.0p0Z01z01.Z0x1z0x1.z0x1.0z+0x1.0Z0x1p0Z0X1p0Z0X1P0Z0x1P0z0x1.p0z0x1.0p0z0x.1p4z0x.1p04z0x.1p004z0x1p+0z0x1P-0z+0x1p0Z0x01p0Z0x1p00z 0x1p0 z
 0x1p0z0x1p0 	Z0xap0g      $@Z0xAp0Z0xaP0Z0xAP0Z0xbep0g     g@Z0xBep0Z0xbEp0z0XBE0P-4Z0xBEp0z0xB.Ep4z0x.BEp8z	0x.0BEp12z0x1.921fb54442d18p1z0x.006487ed5110b46p11z0x.00c90fdaa22168cp10z0x.01921fb54442d18p9z0x.03243f6a8885a3p8z0x.06487ed5110b46p7z0x.0c90fdaa22168cp6z0x.1921fb54442d18p5z0x.3243f6a8885a3p4z0x.6487ed5110b46p3z0x.c90fdaa22168cp2z0x3.243f6a8885a3p0z0x6.487ed5110b46p-1z0xc.90fdaa22168cp-2z0x19.21fb54442d18p-3z0x32.43f6a8885a3p-4z0x64.87ed5110b46p-5z0xc9.0fdaa22168cp-6z0x192.1fb54442d18p-7z0x324.3f6a8885a3p-8z0x648.7ed5110b46p-9z0xc90.fdaa22168cp-10z0x1921.fb54442d18p-11z0x1921fb54442d1.8p-47z0x3243f6a8885a3p-48z0x6487ed5110b46p-49z0xc90fdaa22168cp-50z0x1921fb54442d18p-51z0x3243f6a8885a30p-52z0x6487ed5110b460p-53z0xc90fdaa22168c0p-54z0x1921fb54442d180p-55z	-0x1p1024z	0x1p+1025z	+0X1p1030z
-0x1p+1100Z0X1p123456789123456789z+0X.8p+1025z+0x0.8p1025z-0x0.4p1026z	0X2p+1023z	0x2.p1023z-0x2.0p+1023z
+0X4p+1022z0x1.ffffffffffffffp+1023z-0X1.fffffffffffff9p1023z0X1.fffffffffffff8p1023z+0x3.fffffffffffffp1022z0x3fffffffffffffp+970Z0x10000000000000000p960z-0Xffffffffffffffffp960z+0x1.fffffffffffffp+1023z-0X1.fffffffffffff7p1023z$0X1.fffffffffffff7fffffffffffffp1023Z0x0p0r'   Z0x0p1000z	-0x0p1023r   Z0X0p1024z	-0x0p1025Z0X0p2000Z0x0p123456789123456789z-0X0p-0z
-0X0p-1000z	0x0p-1023z
-0X0p-1024z
-0x0p-1025z
-0x0p-1072z	0X0p-1073z
-0x0p-1074z	0x0p-1075z	0X0p-1076z
-0X0p-2000z-0x0p-123456789123456789z	0X1p-1075z
-0X1p-1075z-0x1p-123456789123456789z0x1.00000000000000001p-1075z-0x1.1p-1075z0x1.fffffffffffffffffp-1075z	0x1p-1076z	0X2p-1076z	0X3p-1076z	0x4p-1076z	0X5p-1076z	0X6p-1076rl   z	0x7p-1076z	0X8p-1076z	0X9p-1076z	0xap-1076z	0Xbp-1076rF  z	0xcp-1076z	0Xdp-1076z	0Xep-1076rL   z	0xfp-1076z
0x10p-1076z
-0x1p-1076z
-0X2p-1076z
-0x3p-1076z
-0X4p-1076z
-0x5p-1076z
-0x6p-1076r   z
-0X7p-1076z
-0X8p-1076z
-0X9p-1076z
-0Xap-1076z
-0xbp-1076z
-0xcp-1076z
-0Xdp-1076z
-0xep-1076z
-0Xfp-1076z-0X10p-1076z0x0.ffffffffffffd6p-1022z0x0.ffffffffffffd8p-1022z0x0.ffffffffffffdap-1022z0x0.ffffffffffffdcp-1022z0x0.ffffffffffffdep-1022z0x0.ffffffffffffe0p-1022z0x0.ffffffffffffe2p-1022z0x0.ffffffffffffe4p-1022z0x0.ffffffffffffe6p-1022z0x0.ffffffffffffe8p-1022z0x0.ffffffffffffeap-1022z0x0.ffffffffffffecp-1022z0x0.ffffffffffffeep-1022z0x0.fffffffffffff0p-1022z0x0.fffffffffffff2p-1022z0x0.fffffffffffff4p-1022z0x0.fffffffffffff6p-1022z0x0.fffffffffffff8p-1022z0x0.fffffffffffffap-1022z0x0.fffffffffffffcp-1022z0x0.fffffffffffffep-1022z0x1.00000000000000p-1022z0x1.00000000000002p-1022z0x1.00000000000004p-1022z0x1.00000000000006p-1022z0x1.00000000000008p-1022z0x1.0000000000000ap-1022z0x1.0000000000000cp-1022z0x1.0000000000000ep-1022z0x1.00000000000010p-1022z0x1.00000000000012p-1022z0x1.00000000000014p-1022z0x1.00000000000016p-1022z0x1.00000000000018p-1022z0x0.fffffffffffff0p0z0x0.fffffffffffff1p0z0X0.fffffffffffff2p0z0x0.fffffffffffff3p0z0X0.fffffffffffff4p0z0X0.fffffffffffff5p0z0X0.fffffffffffff6p0z0x0.fffffffffffff7p0z0x0.fffffffffffff8p0z0X0.fffffffffffff9p0z0X0.fffffffffffffap0z0x0.fffffffffffffbp0z0X0.fffffffffffffcp0z0x0.fffffffffffffdp0z0X0.fffffffffffffep0z0x0.ffffffffffffffp0z0X1.00000000000000p0z0X1.00000000000001p0z0x1.00000000000002p0z0X1.00000000000003p0z0x1.00000000000004p0z0X1.00000000000005p0z0X1.00000000000006p0z0X1.00000000000007p0z(0x1.00000000000007ffffffffffffffffffffp0z0x1.00000000000008p0z&0x1.00000000000008000000000000000001p0rK   z0X1.00000000000009p0z0x1.0000000000000ap0z0x1.0000000000000bp0z0X1.0000000000000cp0z0x1.0000000000000dp0z0x1.0000000000000ep0z0X1.0000000000000fp0z0x1.00000000000010p0z0X1.00000000000011p0z0x1.00000000000012p0z0X1.00000000000013p0z0X1.00000000000014p0z0x1.00000000000015p0z0x1.00000000000016p0z0X1.00000000000017p0z(0x1.00000000000017ffffffffffffffffffffp0z0x1.00000000000018p0z&0X1.00000000000018000000000000000001p0z0x1.00000000000019p0z0X1.0000000000001ap0z0X1.0000000000001bp0z0x1.0000000000001cp0z0x1.0000000000001dp0z0x1.0000000000001ep0z0X1.0000000000001fp0z0x1.00000000000020p0z
0x.8p-1074z0x.80p-1074z0x.81p-1074z	0x8p-1078z0x8.0p-1078z0x8.1p-1078z
0x80p-1082z
0x81p-1082z.8p-1074z8p-1078z	-.8p-1074z+8p-1078)
rf  ri  rg  rh  re  rk  r   r   r    r   )r%   rf  ri  rg  rh  pir   r   r   test_from_hex  s&  




zHexFloatTestCase.test_from_hexc              	   C   s   dd }t t| j| j| j| j | jdfD ]}| ||| | | ||  qdd l}tdD ]0}|dd}| }|	dd	g}z	|t
|| }W n	 tyV   Y q1w | |tt| q1d S )
Nc                 S   s   t t| S r*   )rk  toHexr   r   r   r   	roundtrip  s   z2HexFloatTestCase.test_roundtrip.<locals>.roundtripr'   r   r   iPi  r   r   )r   r   ri  rf  rg  re  r   r   	randrangechoicer   r   rk  r|  )r%   r}  rI   r   r   emrP   r   r   r   test_roundtrip  s    $zHexFloatTestCase.test_roundtripc                 C   s   G dd dt }|d }| t|| | |d G dd dt }|d }| t|| | |d | t|ddd	 d S )
Nc                   @   rb   )z)HexFloatTestCase.test_subclass.<locals>.Fc                 S   s   t | |d S rw   rm   ro   r   r   r   rn     rr   z1HexFloatTestCase.test_subclass.<locals>.F.__new__N)r   r   r   rn   r   r   r   r   r|     rj   r|   r   r^   c                   @   rb   )z*HexFloatTestCase.test_subclass.<locals>.F2c                 S   s
   d| _ d S )Nbar)foor~   r   r   r   r     r   z3HexFloatTestCase.test_subclass.<locals>.F2.__init__N)r   r   r   r   r   r   r   r   F2  rj   r  r  Znoner  )r   fromhexhexr   rG   r   r9  )r%   r|   rH   r  r   r   r   test_subclass  s   zHexFloatTestCase.test_subclassN)r   r   r   rk  ri  rf  rg  rh  re  rj  rm  rv  r{  r  r  r   r   r   r   rb  6  s    
@  -rb  __main__)>r   r   r+  r   r   r   r   r7  rJ  r   Ztest.test_grammarr   r   mathr   r   r   r   r   r   r   hasattrZhave_getformatr8  Zrequires_getformatZrequires_setformatr,  dirnamer.  curdirZtest_dirr-  r  r   r   ZTestCaser   r   r   rB   reversedr   r   r   r   r   r   r   r   r   r  r)  r   r:  rO  r  rk  r  r|  rb  r   mainr   r   r   r   <module>   sp    
    1%^?vf   F