B
    u9a                 @   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.7/test_float.pyr      s   r   c               @   s   e Zd ZdS )OtherFloatSubclassN)r   r   r   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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 )NgQ	@i:  g     s@z  3.14  z	  0x3.1  z  -0x3.p-1  z  +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   xRt D ]J t fdddD s| t t  | t t dd qW x:tD ]2  dkrhqZt fdddD sZ| tt  qZW | ttd | ttd	 | ttd
 | ttd | ttd | ttd d S )Nc             3   s   | ]}| kV  qd S )Nr   ).0ch)litr   r   	<genexpr>E   s    z5GeneralFloatCases.test_underscores.<locals>.<genexpr>ZjJxXoObB_ )Z0_7Z09_99c             3   s   | ]}| kV  qd S )Nr   )r   r   )r    r   r   r!   K   s    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}yd	d
lm W n tk
rl   Y nX |fdd xb|D ]Z}|d}| t|: | 	t
|d | td t
|d W d Q R X W d Q R X qW d S )Nc               @   s   e Zd ZdS )zAGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomStrN)r   r   r   r   r   r   r   	CustomStr[   s    r(   c               @   s   e Zd ZdS )zCGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomBytesN)r   r   r   r   r   r   r   CustomBytes\   s    r)   c               @   s   e Zd ZdS )zGGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomByteArrayN)r   r   r   r   r   r   r   CustomByteArray]   s    r*   c                s    |   S )N)decode)b)r(   r   r   <lambda>b       z@GeneralFloatCases.test_non_numeric_input_types.<locals>.<lambda>r   )arrayc                s
    d| S )NBr   )r,   )r/   r   r   r-   l   r.   s    3.14  gQ	@zcould not converts   AAAAAAAAAAAAAAAA)strbytes	bytearray
memoryviewr/   ImportErrorappendZsubTesttyper   r   r   r   )r   r)   r*   Z	factoriesfxr   )r(   r/   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   r4   )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          	      sD    j td| f d}t|  W d Q R X  t|jd| f  d S )Nz	float(%r))msgz%could not convert string to float: %r)r   r   r   r   r1   Z	exception)scm)r   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   rA   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 ","z  3.14  gQ	@z+3.14  z-3.14  gQ	z.14  gQ?z3.  g      @z3.e3  g     p@z3.2e3  g      @z2.5e-1  g      ?z5e-1g      ?z  3,14  z	  +3,14  z	  -3,14  z	  0x3.1  z  -0x3.p-1  z  +0x3.p-1  z
  25.e-1  g      @z
  .25e-1  g?)locale
localeconvZskipTestr   r   r   r   ZassertAlmostEqual)r   rI   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 Q R X | tt|d | t|dd G dd d}| ttj	|  G dd d}| t | t| d W d Q R X | t | 
tt| t W d Q R X | t | t| d W d Q R X | t | 
tt| t W d Q R X d S )Nc               @   s   e Zd Zdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo1c             S   s   dS )Ng      E@r   )r   r   r   r   	__float__   s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo1.__float__N)r   r   r   rL   r   r   r   r   Foo1   s   rM   c               @   s   e Zd Zdd ZdS )z4GeneralFloatCases.test_floatconversion.<locals>.Foo2c             S   s   dS )Ng      E@r   )r   r   r   r   rL      s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo2.__float__N)r   r   r   rL   r   r   r   r   Foo2   s   rN   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   rQ      s    z<GeneralFloatCases.test_floatconversion.<locals>.Foo3.__new__c             S   s   | S )Nr   )r   r   r   r   rL      s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo3.__float__N)rO   )r   r   r   rQ   rL   r   r   r   r   Foo3   s   
rT   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   rL      s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo4.__float__N)r   r   r   rL   r   r   r   r   Foo4   s   rV   c               @   s   e Zd Zdd ZdS )z6GeneralFloatCases.test_floatconversion.<locals>.FooStrc             S   s   t t| d S )Nr;   )r   r1   )r   r   r   r   rL      s    z@GeneralFloatCases.test_floatconversion.<locals>.FooStr.__float__N)r   r   r   rL   r   r   r   r   FooStr   s   rW   g      E@   rU   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   rL      s    z>GeneralFloatCases.test_floatconversion.<locals>.Foo5.__float__N)r   r   r   rL   r   r   r   r   Foo5   s   rZ   c               @   s   e Zd Zdd ZdS )z1GeneralFloatCases.test_floatconversion.<locals>.Fc             S   s   t dS )Ng      E@)r   )r   r   r   r   rL      s    z;GeneralFloatCases.test_floatconversion.<locals>.F.__float__N)r   r   r   rL   r   r   r   r   F   s   r[   )objectr   r1   r   ZassertWarnsDeprecationWarningr   r   timeZsleepassertIsr7   r   )r   rM   rN   rT   rV   rW   rZ   r[   r   r   r   test_floatconversion   s,     z&GeneralFloatCases.test_floatconversionc          	   C   s&   |  td tdd W d Q R X d S )Nzkeyword argumentz3.14)r9   )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?g      ?r
   r	   )ZassertFalse
is_integer
assertTruer   )r   r   r   r   test_is_integer   s    z!GeneralFloatCases.test_is_integerc             C   sf  x dD ]\}}|  | | qW xNtdD ]B}t }|dtdd 9 }| \}}|  t||| q,W 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      )irf   )g        )r   r;   )g      '@)   rP   i'  
   id   r   r;   g           rP   g      @g      ?l   L33 l         @ g @lL33 g ig     hr	   z-infr
   )r   as_integer_ratiorangerandomZrandintr   __truediv__	fractionsZFractionr   OverflowErrorr   )r   r8   ZratioindRr   r   r   test_floatasratio   s.    z#GeneralFloatCases.test_floatasratioc             C   sr  t t  ddtf}xl|D ]d}| ||g | ||f | ||h | ||d i | |g|dd|  | || qW x|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|  qW d S )Ng        g      ?r;   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   countrc   )r   Zfloatsr8   ltr?   rs   r   r   r   test_float_containment  s&    

z(GeneralFloatCases.test_float_containmentc             C   s$   |  |td|f|td|f d S )Ng      ?)r   r   )r   ar,   r   r   r   assertEqualAndEqualSign&  s    z)GeneralFloatCases.assertEqualAndEqualSignc             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 )Ng      g      ?g        g0.+g       g0.++)operatormodr~   )r   r   r   r   r   test_float_mod,  s    z GeneralFloatCases.test_float_modc             C   s	  	xt 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W d S )Ng       g      g      g       g        g      ?g       @g      ?g      ?g      @g}Ô%Ig}Ô%ITg     @g     Bg     Dg     @@g     B@g     D@)powr   rc   r   rv   rw   r   ZeroDivisionErrorr~   r   r7   complex)r   Zpow_opr   r   r   test_float_pow@  s   z GeneralFloatCases.test_float_powN)r   r   r   r   r'   r:   r=   rC   r   Zrun_with_localerK   r`   ra   rd   ru   r|   r~   requires_IEEE_754r   r   r   r   r   r   r   "   s   4!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_formats)r   r   r   r   setUp  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   sT   |  tddddg |  tddddg | ttjd | ttjd d S )Nr   unknownzIEEE, big-endianzIEEE, little-endianr   chickenr;   )rx   r   r   r   r   r   )r   r   r   r   test_getformat  s    z&FormatFunctionsTestCase.test_getformatc             C   s   xdD ]}t |d | j| dkr8| tt j|d nF| j| dkrZ| tt j|d n$| tt j|d | tt j|d | tt j|d qW | tt jdd d S )N)r   r   r   zIEEE, big-endianzIEEE, little-endianr   )r   r   r   r   r   )r   r{   r   r   r   test_setformat  s     








z&FormatFunctionsTestCase.test_setformatN)r   r   r   r   r   r   r   r   r   r   r   r   
  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   r   ?  s    zUnknownFormatTestCase.setUpc             C   s(   t d| jd  t d| jd  d S )Nr   r   )r   r   r   )r   r   r   r   r   E  s    zUnknownFormatTestCase.tearDownc             C   s@   x:dt fdtfdtfdtfgD ]\}}| ttj|| qW 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_unpackI  s
    z6UnknownFormatTestCase.test_double_specials_dont_unpackc             C   s@   x:dt fdtfdtfdtfgD ]\}}| ttj|| qW d S )Nz>fz<f)BE_FLOAT_INFBE_FLOAT_NANLE_FLOAT_INFLE_FLOAT_NANr   r   r   r   )r   r   r   r   r   r   test_float_specials_dont_unpackP  s
    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   s:   x4dt fdtfdtfdtfgD ]\}}t|| qW d S )Nz>dz<d)r   r   r   r   r   r   )r   r   r   r   r   r   test_double_specials_do_unpack_  s
    z1IEEEFormatTestCase.test_double_specials_do_unpackc             C   s:   x4dt fdtfdtfdtfgD ]\}}t|| qW d S )Nz>fz<f)r   r   r   r   r   r   )r   r   r   r   r   r   test_float_specials_do_unpackg  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_MAXz<fgnGgn)Z	_testcapir   r   r   pack)r   r   r   r   r   test_serialized_float_roundingo  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   sD  |  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 xdd ttdtdd D dd ttdtd d D  D ]}|d!krt| ttd| | ttd| | ttd| | ttd"| | ttd#| | ttd$| | ttd%| qtW |  ttdd& |  ttd'd( |  ttdd) |  ttd'd* d S )+Ng        r8   z0.000000r#   z0.0g{Gz?z0.01gg%I$I,@->2g      ?z1.000000g      z	-1.000000z fz	 1.000000z+fz	+1.000000%z-100.000000%g      @r?   c             S   s   g | ]}t |qS r   )chr)r   r9   r   r   r   
<listcomp>  s    z.FormatTestCase.test_format.<locals>.<listcomp>r}   zr;   c             S   s   g | ]}t |qS r   )r   )r   r9   r   r   r   r     s    AZzeEfFgGn%g}Ô%ITg}Ô%Ig0.++g0.+r
   r[   rw   r	   rv   )	r   formatr1   r   r   rl   ordrw   rv   )r   r9   format_specr   r   r   test_formatw  s>     &
zFormatTestCase.test_formatc          	   C   s   t t~}xv|D ]n}|dr q| }|s.qttj|d\}}| \}}| |t| | | |t|  d|  qW W d Q R X d S )Nz--z->r   )	openformat_testfile
startswithstripmapr1   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 )Ngw/^@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+02)r   r   )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   u  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   sl   t tjtjtd d}x@|D ]8}| }|r$|dr@q$t|}| 	|tt
| q$W |  d S )Nr   zfloating_points.txt#)r   ospathjoinr   __file__r   r   r%   r   reprclose)r   Zfloats_filer   vr   r   r   	test_repr  s    
zReprTestCase.test_reprfloat_repr_styler#   shortz.applies only when using short float repr stylec             C   s   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g}xt|D ]l}d| }|  |tt| |  |tt| |  tt|tt| |  tt|tt| q<W d S )Nz0.0z1.0z0.01z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   r1   )r   Ztest_stringsr?   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 )Ng        g      ?zceci n'est pas un integerg       y              ?)r   rp   roundrv   r   rw   r   )r   r   r   r   test_inf_nan  s    zRoundTestCase.test_inf_nanc             C   s   xfdddddddd gD ]L}|  td	|d	 |  td
|d
 |  td|d |  td|d qW |  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        rP   ri   gw/^@gw/^gu <7~g      gP.5_i,  i3  go!	i4  i5  gS    i;  gi    )r   r   )r   rr   r   r   r   test_large_n  s    zRoundTestCase.test_large_nc             C   sn   xhdddddddd  gD ]L}|  td	|d
 |  td|d |  td|d
 |  td|d
 qW d S )Niiipi  i   l    rP   ri   gw/^@g        gw/^g       gu <7~g      )r   r   )r   rr   r   r   r   test_small_n+  s
    zRoundTestCase.test_small_nc             C   s$   |  ttdd |  ttdd d S )Ng3t<{igv;w0B)r   rp   r   )r   r   r   r   test_overflow2  s    zRoundTestCase.test_overflowr   r#   r   z.applies only when using short float repr stylec             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      Cr;   gB   g      9@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   r   test_previous_round_bugs6  s    z&RoundTestCase.test_previous_round_bugsc             C   s  xt dD ]|}|d }| tt|dt|d | tt|dt|d | tt|dt|d | tt|d	t|d
 q
W xt 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
 qW xt dD ]~}t }| tt|dt|d | tt|dt|d | tt|dt|d | tt|d	t|d
 q"W d S )Ni  g     @@z.0fr   z.1fr;   z.2frP   z.3fr   rj   i  rh   )rl   r   r   r   r   rm   )r   rq   r9   r   r   r   test_matches_float_formatH  s$      z'RoundTestCase.test_matches_float_formatc                s    fdd}xd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W d S )Nc                s6     | | ||  | dd  }   t|| ||  d S )Nr;   )r   r   )r   rS   expected)r   r   r   testd  s    z0RoundTestCase.test_format_specials.<locals>.test)z%ez%fz%gz%.0ez%.6fz%.20gz%#ez%#fz%#gz%#.20ez%#.15fz%#.3gz%+r;   z% r	   z-infr
   z+infz+nanz infz nan)rv   rw   )r   r   r   ZpfmtZsfmtr   )r   r   test_format_specialsa  s     
z"RoundTestCase.test_format_specialsc             C   s   x<t dt dd t dd dfD ]}| |d | |t qW x<t dt dd t dd dfD ]}| |d | |t q\W d S )NgGz?)Zndigitsr;   g{Gz?rP   )r   r   ZassertIsInstanceint)r   r9   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	   z+infz-infZinfinityz	+infinityz	-infinityrv   z+Infz-iNFInfinityz	+iNfInItYz	-INFINITYinfoz+infoz-infoinz+inz-inZinfinitz+Infinz-INFIZ	infinitysz++Infz-+infz
+-infinityz
--Infinity)rc   r   r   r   r   r1   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      z-inf)r   r   r1   )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
   z+nanz-nanrw   z+NAnz-NaNZnanaz+nanaz-nanaZnaz+naz-naz++nanz-+NANz+-NaNz--nAn)rc   r   r   r   r   r1   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      )r   r   r1   )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 )Ng      ?r	   z-infg      )r   r   r   )r   r   r   r   test_inf_signs  s    zInfNanTest.test_inf_signsr   r#   r   z.applies only when using short float repr stylec             C   s0   |  tdtdd |  tdtdd d S )Ng      ?r
   z-nang      )r   r   r   )r   r   r   r   test_nan_signs  s    zInfNanTest.test_nan_signsN)r   r   r   r   r   r   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 )Ng        g      ?z%r not identical to %r)r   r   fail)r   r9   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 )Ng      ?iiig       @i  i  )r   MINr   TINYEPSMAX)r   r   r   r   	test_ends  s    zHexFloatTestCase.test_endsc          3   C   s   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/d0d1d2d3g3}x@|D ]8}yt |}W n tk
r   Y qpX | d4||f  qpW d S )5NZinfiz-Infinitz++infz-+Infz--nanz+-NaNZ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_inputsr9   resultr   r   r   test_invalid_inputs  st    
z$HexFloatTestCase.test_invalid_inputsc             C   s   dt fdt  fdtfdddg}ddd	d
ddddg}xH|D ]@\}}x6|D ].}x(|D ] }t|| | }| || qPW qFW q8W d S )Nr	   z	-Infinityr
   )z1.0g      ?)z-0x.2g      )z-0.0g       r#   r   	
z
 	)rv   rw   r   r   )r   Zvalue_pairsZ
whitespaceZinpr   ZleadtrailZgotr   r   r   test_whitespaceH  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|   d S (  Nr	   z+Infz-INFZiNfr   z	+INFINITYz	-infinityz	-iNFiNitYr
   z+NaNz-NaNz-nAN1g      ?z+1z1.z1.0z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0x0p0g        Z0x0p1000z	-0x0p1023g       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-1076rP   z	0x7p-1076z	0X8p-1076z	0X9p-1076z	0xap-1076z	0Xbp-1076r   z	0xcp-1076z	0Xdp-1076z	0Xep-1076r<   z	0xfp-1076z
0x10p-1076z
-0x1p-1076z
-0X2p-1076z
-0x3p-1076z
-0X4p-1076z
-0x5p-1076z
-0x6p-1076z
-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.00000000000008000000000000000001p0r;   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.00000000000020p0)
r   r   r   r   r   r   rv   rw   r   rp   )r   r   r   r   r   Zpir   r   r   test_from_hexb  s   





zHexFloatTestCase.test_from_hexc          	   C   s   dd }xLt t| j| j| j| j | jdgD ](}| ||| | | ||  q*W dd l}xntdD ]b}|dd}| }|	dd	g}y|t
|| }W n tk
r   Y qhX | |tt| qhW d S )
Nc             S   s   t t| S )N)r   toHex)r9   r   r   r   	roundtrip  s    z2HexFloatTestCase.test_roundtrip.<locals>.roundtripg        r   i'  iPi  g      ?g      )rw   rv   r   r   r   r   rm   rl   Z	randrangechoicer   rp   r   r  )r   r  r9   rm   rq   emr?   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 )Nr;   )r   rQ   )rR   rS   r   r   r   rQ     s    z1HexFloatTestCase.test_subclass.<locals>.F.__new__N)r   r   r   rQ   r   r   r   r   r[     s   r[   g      ?g      @c               @   s   e Zd Zdd ZdS )z*HexFloatTestCase.test_subclass.<locals>.F2c             S   s
   d| _ d S )Nbar)foo)r   rS   r   r   r   __init__  s    z3HexFloatTestCase.test_subclass.<locals>.F2.__init__N)r   r   r   r
  r   r   r   r   F2  s   r  r	  Znoner  )r   fromhexhexr_   r7   r   r   )r   r[   r8   r  r   r   r   test_subclass  s    zHexFloatTestCase.test_subclassN)r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r   r   r   r     s   
@  r   __main__)>ro   r   r   rm   r   r   r^   r   r   r   Ztest.test_grammarr   r   Zmathr   r   r   r   r   rv   rw   hasattrZhave_getformatr   Zrequires_getformatZrequires_setformatr   dirnamer   curdirZtest_dirr   r   r   r   ZTestCaser   r   r   r2   reversedr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r  r   r   mainr   r   r   r   <module>   sf   
   k
%
^@
vf   8
