a
    ze                    @   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pe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 )'    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                   @   s   e Zd ZdS )FloatSubclassN__name__
__module____qualname__ r   r   %/usr/lib/python3.9/test/test_float.pyr      s   r   c                   @   s   e Zd ZdS )OtherFloatSubclassNr   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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$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              	      s   t D ]J t fdddD s| t t  | t t dd qtD ]2  dv rbqTt fdddD sT| tt  qT| ttd | ttd	 | ttd
 | ttd | ttd | ttd d S )Nc                 3   s   | ]}| v V  qd S Nr   .0ZchZlitr   r   	<genexpr>E       z5GeneralFloatCases.test_underscores.<locals>.<genexpr>ZjJxXoObB_ )Z0_7Z09_99c                 3   s   | ]}| v V  qd S r%   r   r&   r(   r   r   r)   K   r*   Z_NaNZNa_NZIN_Fz-_INFz-INF_s   0_.9)	r   anyr   r   evalreplacer   r   r   r"   r   r(   r   test_underscoresC   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yj   Y n0 |fdd |D ]}|d}| t|X | 	t
|d | td t
|d W d    n1 s0    Y  W d    q1 s0    Y  qd S )Nc                   @   s   e Zd ZdS )zAGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomStrNr   r   r   r   r   	CustomStr[   r*   r1   c                   @   s   e Zd ZdS )zCGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomBytesNr   r   r   r   r   CustomBytes\   r*   r2   c                   @   s   e Zd ZdS )zGGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomByteArrayNr   r   r   r   r   CustomByteArray]   r*   r3   c                    s    |   S r%   )decodeb)r1   r   r   <lambda>b   r*   z@GeneralFloatCases.test_non_numeric_input_types.<locals>.<lambda>r   arrayc                    s
    d| S )NBr   r5   r8   r   r   r7   l   r*   s    3.14  r   zcould not converts   AAAAAAAAAAAAAAAA)strbytes	bytearray
memoryviewr9   ImportErrorappendZsubTesttyper   r   r!   r   )r#   r2   r3   Z	factoriesfxr   )r1   r9   r   test_non_numeric_input_typesX   s*    
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   r>   r"   r   r   r   test_float_memoryviewu   s
    z'GeneralFloatCases.test_float_memoryviewc                    s`    f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 s20    Y   t|jd| f  d S )Nz	float(%r))msgz%could not convert string to float: %r)r   r   r   r   r;   	exception)scmr"   r   r   check}   s
    &z3GeneralFloatCases.test_error_message.<locals>.check   ½u   123½z  123 456  s     123 456  u   ٣١٤!z123 z123  245z123 245s   123 s   123r   )r#   rL   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#   rX   r   r   r   test_float_with_comma   s(    
z'GeneralFloatCases.test_float_with_commac           
      C   s`  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 s0    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 s:0    Y  | t& | 
tt| t W d    n1 s|0    Y  | t" | t| d W d    n1 s0    Y  | t& | 
tt| t W d    n1 s0    Y  G dd d}| t|dd | tt|dd  G dd d}	| tt|	  d S )Nc                   @   s   e Zd Zdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo1c                 S   s   dS N      E@r   r"   r   r   r   	__float__   s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo1.__float__Nr   r   r   r]   r   r   r   r   Foo1   s   r_   c                   @   s   e Zd Zdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo2c                 S   s   dS r[   r   r"   r   r   r   r]      s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo2.__float__Nr^   r   r   r   r   Foo2   s   r`   c                   @   s   e Zd ZdddZdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo3        c                 S   s   t | d| S )N   r   __new__clsvaluer   r   r   rd      s    z<GeneralFloatCases.test_floatconversion.<locals>.Foo3.__new__c                 S   s   | S r%   r   r"   r   r   r   r]      s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo3.__float__N)ra   )r   r   r   rd   r]   r   r   r   r   Foo3   s   
rh   c                   @   s   e Zd Zdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo4c                 S   s   dS N*   r   r"   r   r   r   r]      s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo4.__float__Nr^   r   r   r   r   Foo4   s   rk   c                   @   s   e Zd Zdd ZdS )z6GeneralFloatCases.test_floatconversion.<locals>.FooStrc                 S   s   t t| d S NrE   )r   r;   r"   r   r   r   r]      s    z@GeneralFloatCases.test_floatconversion.<locals>.FooStr.__float__Nr^   r   r   r   r   FooStr   s   rm   r\      rj   8g      "@c                   @   s   e Zd Zdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo5c                 S   s   dS )Nr,   r   r"   r   r   r   r]      s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo5.__float__Nr^   r   r   r   r   Foo5   s   rp   c                   @   s   e Zd Zdd ZdS )z1GeneralFloatCases.test_floatconversion.<locals>.Fc                 S   s   t dS r[   )r   r"   r   r   r   r]      s    z;GeneralFloatCases.test_floatconversion.<locals>.F.__float__Nr^   r   r   r   r   F   s   rq   c                   @   s   e Zd Zdd Zdd ZdS )z7GeneralFloatCases.test_floatconversion.<locals>.MyIndexc                 S   s
   || _ d S r%   rg   r#   rg   r   r   r   __init__   s    z@GeneralFloatCases.test_floatconversion.<locals>.MyIndex.__init__c                 S   s   | j S r%   rr   r"   r   r   r   	__index__   s    zAGeneralFloatCases.test_floatconversion.<locals>.MyIndex.__index__N)r   r   r   rt   ru   r   r   r   r   MyIndex   s   rv   rb   i  c                   @   s   e Zd Zdd ZdS )z5GeneralFloatCases.test_floatconversion.<locals>.MyIntc                 S   s   dS ri   r   r"   r   r   r   __int__   s    z=GeneralFloatCases.test_floatconversion.<locals>.MyInt.__int__N)r   r   r   rw   r   r   r   r   MyInt   s   rx   )objectr   r;   r   ZassertWarnsDeprecationWarningr   r    timesleepassertIsrA   r   OverflowError)
r#   r_   r`   rh   rk   rm   rp   rq   rv   rx   r   r   r   test_floatconversion   s6    22626z&GeneralFloatCases.test_floatconversionc                 C   s:   |  td tdd W d    n1 s,0    Y  d S )Nzkeyword argumentz3.14rC   )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 ]B}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   )ra   )r   rE   )g      '@)   rb   '  
   id   r   rE   ra      rb   rW   rV   l   L33 l         @ g @lL33 g ig     hr	   -infr
   )r   as_integer_ratiorangerandomrandintr   __truediv__	fractionsZFractionr   r~   r   )r#   rB   ZratioindRr   r   r   test_floatasratio   s:    z#GeneralFloatCases.test_floatasratioc                 C   sj  t t  ddtf}|D ]d}| ||g | ||f | ||h | ||d i | |g|dd|  | || q|D ]}| |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 )Nra   r   rE   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floatsrB   ltrJ   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#   ar6   r   r   r   assertEqualAndEqualSign5  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 )NrV   r   r   rE         ?                  NݯbNݯr
   r	   r   )assertIsInstancer   	__floor__intr   r   r   r~   r"   r   r   r   test_float_floor;  s    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 )NrV   rE   r   r   rb   r   r   r   r   r   r   r   r
   r	   r   )r   r   __ceil__r   r   r   r   r~   r"   r   r   r   test_float_ceilI  s    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   ra   0.+       0.++)operatormodr   )r#   r   r   r   r   test_float_modW  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   ra   rV          @r   rU   g      @}Ô%I}Ô%ITg     @g     Bg     Dg     @@g     B@g     D@)powr   r   r   r   r   r   ZeroDivisionErrorr   r   rA   complex)r#   Zpow_opr   r   r   test_float_powk  s   z GeneralFloatCases.test_float_powN)r   r   r   r$   r0   rD   rG   rN   r   Zrun_with_localerZ   r   r   r   r   r   r   r   r   requires_IEEE_754r   r   r   r   r   r   r   "   s&   
C!
r   c                   @   s,   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   setUp8  s    zFormatFunctionsTestCase.setUpc                 C   s(   t d| jd  t d| jd  d S Nr   r   r   r   r   r"   r   r   r   tearDown<  s    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   chickenrE   )r   r   r   r   r   r    r"   r   r   r   test_getformat@  s    z&FormatFunctionsTestCase.test_getformatc                 C   s   dD ]}t |d | j| dkr6| tt j|d nF| j| dkrX| 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_setformatH  s,    





z&FormatFunctionsTestCase.test_setformatN)r   r   r   r   r   r   r   r   r   r   r   r   5  s   r   s         s         s     s     c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
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   j  s
    zUnknownFormatTestCase.setUpc                 C   s(   t d| jd  t d| jd  d S r   r   r"   r   r   r   r   p  s    zUnknownFormatTestCase.tearDownc                 C   s<   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_unpackt  s    z6UnknownFormatTestCase.test_double_specials_dont_unpackc                 C   s<   dt fdtfdtfdtffD ]\}}| ttj|| qd S 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{  s    z5UnknownFormatTestCase.test_float_specials_dont_unpackN)r   r   r   r   r   r   r   r   r   r   r   r   h  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   s6   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  s    z1IEEEFormatTestCase.test_double_specials_do_unpackc                 C   s6   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_float_specials_do_unpack  s    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rr| ttd| | ttd| | ttd| | ttd"| | ttd#| | ttd$| | ttd%| qr|  ttdd& |  ttd'd( |  ttdd) |  ttd'd* d S )+Nra   rB   z0.000000r,   0.0g{Gz?0.01gg%I$I,@->2r   z1.000000r   z	-1.000000z fz	 1.000000z+fz	+1.000000%z-100.000000%rT   rJ   c                 S   s   g | ]}t |qS r   chrr'   rC   r   r   r   
<listcomp>  r*   z.FormatTestCase.test_format.<locals>.<listcomp>r   zrE   c                 S   s   g | ]}t |qS r   r   r   r   r   r   r     r*   AZzeEfFgGn%r   r   r   r   r
   rq   r   r	   r   )	r   formatr;   r   r   r   ordr   r   )r#   rC   format_specr   r   r   test_format  s@    
zFormatTestCase.test_formatc                 C   s   t t}|D ]n}|drq| }|s,qttj|d\}}| \}}| |t| | | |t|  d|  qW d    n1 s0    Y  d S )Nz--z->r   )	openformat_testfile
startswithstripmapr;   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N}|D ]8}| }|r$|dr@q$t|}| 	|tt
| q$W d    n1 sr0    Y  d S )Nr   zfloating_points.txt#)r   ospathjoinr   __file__r   r   r.   r   repr)r#   Zfloats_filer   vr   r   r   	test_repr  s    zReprTestCase.test_reprfloat_repr_styler,   short.applies only when using short float repr stylec                 C   s~   g d}|D ]l}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   r;   )r#   Ztest_stringsrJ   Znegsr   r   r   test_short_repr	  s    
"zReprTestCase.test_short_reprN)	r   r   r   r  unittest
skipUnlessgetattrsysr  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 )Nra   r   zceci n'est pas un integerr   y              ?)r   r~   roundr   r   r   r    r"   r   r   r   test_inf_nan@  s    zRoundTestCase.test_inf_nanc                 C   s   dddddddd fD ]L}|  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        rb   r   r  w/^u <7~      gP.5_i,  i3  go!	i4  i5  gS    i;  gi    r   r  r#   r   r   r   r   test_large_nI  s    zRoundTestCase.test_large_nc                 C   sj   dddddddd  fD ]L}|  td	|d
 |  td|d |  td|d
 |  td|d
 qd S )Niipi  i   l    rb   r   r  ra   r  r   r  r  r  r  r   r   r   test_small_nU  s
    zRoundTestCase.test_small_nc                 C   s$   |  ttdd |  ttdd d S )Ng3t<{r   gv;w0B)r   r~   r  r"   r   r   r   test_overflow\  s    zRoundTestCase.test_overflowr  r,   r  r  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      CrE   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_bugs`  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
 qt dD ]~}t }| tt|dt|d | tt|dt|d | tt|dt|d | tt|d	t|d
 qd S )Ni  g     @@z.0fr   z.1frE   z.2frb   z.3fr#  r   i  r   )r   r   r   r   r  r   )r#   r   rC   r   r   r   test_matches_float_formatr  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 rl   r  )r   rg   expectedr"   r   r   test  s    z0RoundTestCase.test_format_specials.<locals>.test)z%ez%fz%gz%.0ez%.6fz%.20gz%#ez%#fz%#gz%#.20ez%#.15fz%#.3gz%+rE   z% r	   r   r
   +inf+nanz infz nan)r   r   )r#   r'  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 qVd S )NgGz?)ndigitsrE   g{Gz?rb   )r  r   r   r   )r#   rC   r   r   r   test_None_ndigits  s      zRoundTestCase.test_None_ndigitsN)r   r   r   r  r  r!  r"  r  r  r  r  r$  r%  r*  r,  r   r   r   r   r  =  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	   r(  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  r;   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  r;   r"   r   r   r   test_inf_as_str  s    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
   r)  -nanr   z+NAn-NaNZnanaz+nanaz-nanaZnaz+naz-naz++nanz-+NAN+-NaNz--nAn)r   r   r   r   r  r;   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      r4  r"   r   r   r   test_nan_as_str  s    zInfNanTest.test_nan_as_strc                 C   s0   |  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_signsr  r,   r  r  c                 C   s0   |  tdtdd |  tdtdd d S )Nr   r
   r6  r   r;  r"   r   r   r   test_nan_signs  s    zInfNanTest.test_nan_signsN)r   r   r   r3  r5  r9  r:  r<  r  r  r  r  r=  r   r   r   r   r-    s   -r-  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rNd S n(||krN|dksJtd|td|krNd S | d||f  d S )Nra   r   z%r not identical to %r)r   r   fail)r#   rC   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  )rA  MINr   TINYEPSMAXr"   r   r   r   	test_ends,  s    zHexFloatTestCase.test_endsc              	   C   sH   g d}|D ]6}zt |}W n ty.   Y q0 | d||f  qd S )N)3Zinfiz-Infinitz++infz-+Infz--nanr8  ZsnanZNaNsZnnaZanZnfZnfinityZinityZiinityZ0xnanr,    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   r?  )r#   Zinvalid_inputsrC   resultr   r   r   test_invalid_inputs2  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 ]8\}}|D ]*}|D ] }t|| | }| || q>q6q*d S )Nr	   z	-Infinityr
   )r  r   )z-0x.2g      )z-0.0r   )r,   rG  	
z
 	)r   r   rH  rA  )r#   Zvalue_pairs
whitespaceinpr&  ZleadtrailZgotr   r   r   test_whitespacer  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	   r/  z-INFZiNfr0  z	+INFINITYr.  z	-iNFiNitYr
   z+NaNr7  z-nAN1r   z+1z1.r  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0x0p0ra   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-1076rb   z	0x7p-1076z	0X8p-1076z	0X9p-1076z	0xap-1076z	0Xbp-1076r#  z	0xcp-1076z	0Xdp-1076z	0Xep-1076rF   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.00000000000008000000000000000001p0rE   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)
rB  rE  rC  rD  rA  rH  r   r   r   r~   )r#   rB  rE  rC  rD  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 ]`}|dd}| }|	dd	g}z|t
|| }W n ty   Y qb0 | |tt| qbd S )
Nc                 S   s   t t| S r%   )rH  toHexr   r   r   r   	roundtrip  s    z2HexFloatTestCase.test_roundtrip.<locals>.roundtripra   r   r   iPi  r   r   )r   r   rE  rB  rC  rA  r   r   	randrangechoicer   r~   rH  rY  )r#   rZ  rC   r   r   emrJ   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                   @   s   e Zd Zdd ZdS )z)HexFloatTestCase.test_subclass.<locals>.Fc                 S   s   t | |d S rl   rc   re   r   r   r   rd     s    z1HexFloatTestCase.test_subclass.<locals>.F.__new__N)r   r   r   rd   r   r   r   r   rq     s   rq   r   rW   c                   @   s   e Zd Zdd ZdS )z*HexFloatTestCase.test_subclass.<locals>.F2c                 S   s
   d| _ d S )Nbar)foors   r   r   r   rt     s    z3HexFloatTestCase.test_subclass.<locals>.F2.__init__N)r   r   r   rt   r   r   r   r   F2  s   rb  ra  Znoner`  )r   fromhexhexr}   rA   r   r  )r#   rq   rB   rb  r   r   r   test_subclass  s    zHexFloatTestCase.test_subclassN)r   r   r   rH  rE  rB  rC  rD  rA  rF  rJ  rS  rX  r_  re  r   r   r   r   r>    s   
@  -r>  __main__)>r   r   r  r   r  r   r{   r  r'  r   Ztest.test_grammarr   r   mathr   r   r   r   r   r   r   hasattrZhave_getformatr  Zrequires_getformatZrequires_setformatr  dirnamer
  curdirZtest_dirr	  r   r   r   ZTestCaser   r   r   r<   reversedr   r   r   r   r   r   r   r   r   r   r  r   r  r-  rc  rH  rd  rY  r>  r   mainr   r   r   r   <module>   sl   
    %^?vf   F
