HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //proc/thread-self/root/usr/local/lib/python3.7/test/__pycache__/test_float.cpython-37.opt-1.pyc
B

��g��@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZddl
mZmZmZmZed�Zed�Zeed�Ze�ed�Ze�eed	�d
�Zej�e�p�ejZej�ed�Z Gdd
�d
e�Z!Gdd�de�Z"Gdd�dej#�Z$eGdd�dej#��Z%dZ&e'e(e&��Z)dZ*e'e(e*��Z+dZ,e'e(e,��Z-dZ.e'e(e.��Z/eGdd�dej#��Z0Gdd�dej#�Z1Gdd�dej#�Z2Gdd�dej#�Z3e	j4Gd d!�d!ej#��Z5Gd"d#�d#ej#�Z6ej7Z8ej9Z:Gd$d%�d%ej#�Z;e<d&k�r�e�=�dS)'�N)�support)�VALID_UNDERSCORE_LITERALS�INVALID_UNDERSCORE_LITERALS)�isinf�isnan�copysign�ldexp�inf�nan�
__getformat__zrequires __getformat__�
__setformat__zrequires __setformat__zformatfloat_testcases.txtc@seZdZdS)�
FloatSubclassN)�__name__�
__module__�__qualname__�rr�+/usr/local/lib/python3.7/test/test_float.pyr
sr
c@seZdZdS)�OtherFloatSubclassN)rrrrrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	ddd
�dd��Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zejdd��Zejdd��Zd S)!�GeneralFloatCasescCsT|�td�d�|�td�d�|�td�d�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd	�|�ttd
�|�ttd�|�ttd�|�ttd
�|�ttd�|�ttd�|�tti�|�tdti�|�ttd�|�ttd�|�ttd�|�td�d�|�td�d�td�td�|�ttd�dS)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.7d29z3D-14u  ٣.١٤  u
 3.14 s�.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111a�.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111uこんにちは)�assertEqual�float�assertRaises�
ValueError�	TypeError�assertRaisesRegex)�selfrrr�
test_float$s0zGeneralFloatCases.test_floatc	s�xRtD]J�t�fdd�dD��s|�t��t���|�t��t��dd���qWx:tD]2��dkrhqZt�fdd�dD��sZ|�tt��qZW|�ttd�|�ttd	�|�ttd
�|�ttd�|�ttd�|�ttd
�dS)Nc3s|]}|�kVqdS)Nr)�.0�ch)�litrr�	<genexpr>Esz5GeneralFloatCases.test_underscores.<locals>.<genexpr>ZjJxXoObB�_�)Z0_7Z09_99c3s|]}|�kVqdS)Nr)rr)r rrr!KsZ_NaNZNa_NZIN_Fz-_INFz-INF_s0_.�9)	r�anyrr�eval�replacerrr)rr)r r�test_underscoresCs
 
z"GeneralFloatCases.test_underscorescs�Gdd�dt��Gdd�dt�}Gdd�dt�}tt�fdd�||tg}yd	d
lm�Wntk
rlYnX|��fdd��xb|D]Z}|d�}|�t|���:|�	t
|�d
�|�td��t
|d��WdQRXWdQRXq�WdS)Nc@seZdZdS)zAGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomStrN)rrrrrrr�	CustomStr[sr(c@seZdZdS)zCGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomBytesN)rrrrrrr�CustomBytes\sr)c@seZdZdS)zGGeneralFloatCases.test_non_numeric_input_types.<locals>.CustomByteArrayN)rrrrrrr�CustomByteArray]sr*cs�|���S)N)�decode)�b)r(rr�<lambda>b�z@GeneralFloatCases.test_non_numeric_input_types.<locals>.<lambda>r)�arraycs
�d|�S)N�Br)r,)r/rrr-lr.s 3.14  g��Q�	@zcould not convertsAAAAAAAAAAAAAAAA)
�str�bytes�	bytearray�
memoryviewr/�ImportError�appendZsubTest�typerrrr)rr)r*Z	factories�f�xr)r(r/r�test_non_numeric_input_typesXs(

z.GeneralFloatCases.test_non_numeric_input_typescCs�|�ttd�dd��d�|�ttd�dd��d�|�ttd�dd��d�|�ttd�dd��d�|�ttd�dd��d�dS)	Ns12.3��gffffff@s12.3s12.3 s12.3As12.34)rrr4)rrrr�test_float_memoryviewus
z'GeneralFloatCases.test_float_memoryviewcs`�fdd�}|d�|d�|d�|d�|d�|d�|d	�|d
�|d�|d�dS)
Nc	sD�jtd|fd��}t|�WdQRX��t|j�d|f�dS)Nz	float(%r))�msgz%could not convert string to float: %r)rrrrr1Z	exception)�s�cm)rrr�check}sz3GeneralFloatCases.test_error_message.<locals>.check�½u123½z  123 456  s  123 456  u٣١٤!z123z123 245z123245s123s123�r)rrAr)rr�test_error_message|sz$GeneralFloatCases.test_error_message�
LC_NUMERIC�fr_FR�de_DEcCs*ddl}|��ddks"|�d�|�td�d�|�td�d�|�td�d	�|�td
�d�|�td�d
�|�td�d�|�td�d�|�td�d�|�td�d�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�td�d�|�td�d�dS) Nr�
decimal_point�,zdecimal_point is not ","z  3.14  g��Q�	@z+3.14  z-3.14  g��Q�	�z.14  g�Q���?z3.  g@z3.e3  gp�@z3.2e3  g�@z2.5e-1  g�?z5e-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�
localeconvZskipTestrrrrZassertAlmostEqual)rrIrrr�test_float_with_comma�s(
z'GeneralFloatCases.test_float_with_commac	Cs�Gdd�dt�}Gdd�dt�}Gdd�dt�}Gdd�dt�}Gd	d
�d
t�}|�t|��d�|�t|��d�|�t��|�t|d��d�WdQRX|�tt|d
��|�t|d��d�Gdd�d�}|�ttj	|��Gdd�d�}|�t��|�t|��d�WdQRX|�t��|�
tt|���t�WdQRX|�t��|�t|��d�WdQRX|�t��|�
tt|���t�WdQRXdS)Nc@seZdZdd�ZdS)z4GeneralFloatCases.test_floatconversion.<locals>.Foo1cSsdS)NgE@r)rrrr�	__float__�sz>GeneralFloatCases.test_floatconversion.<locals>.Foo1.__float__N)rrrrLrrrr�Foo1�srMc@seZdZdd�ZdS)z4GeneralFloatCases.test_floatconversion.<locals>.Foo2cSsdS)NgE@r)rrrrrL�sz>GeneralFloatCases.test_floatconversion.<locals>.Foo2.__float__N)rrrrLrrrr�Foo2�srNc@seZdZddd�Zdd�ZdS)z4GeneralFloatCases.test_floatconversion.<locals>.Foo3�cSst�|d|�S)N�)r�__new__)�cls�valuerrrrQ�sz<GeneralFloatCases.test_floatconversion.<locals>.Foo3.__new__cSs|S)Nr)rrrrrL�sz>GeneralFloatCases.test_floatconversion.<locals>.Foo3.__float__N)rO)rrrrQrLrrrr�Foo3�s
rTc@seZdZdd�ZdS)z4GeneralFloatCases.test_floatconversion.<locals>.Foo4cSsdS)N�*r)rrrrrL�sz>GeneralFloatCases.test_floatconversion.<locals>.Foo4.__float__N)rrrrLrrrr�Foo4�srVc@seZdZdd�ZdS)z6GeneralFloatCases.test_floatconversion.<locals>.FooStrcSstt|��dS)Nr;)rr1)rrrrrL�sz@GeneralFloatCases.test_floatconversion.<locals>.FooStr.__float__N)rrrrLrrrr�FooStr�srWgE@�rU�8g"@c@seZdZdd�ZdS)z4GeneralFloatCases.test_floatconversion.<locals>.Foo5cSsdS)Nr#r)rrrrrL�sz>GeneralFloatCases.test_floatconversion.<locals>.Foo5.__float__N)rrrrLrrrr�Foo5�srZc@seZdZdd�ZdS)z1GeneralFloatCases.test_floatconversion.<locals>.FcSstd�S)NgE@)r)rrrrrL�sz;GeneralFloatCases.test_floatconversion.<locals>.F.__float__N)rrrrLrrrr�F�sr[)
�objectrr1rZassertWarns�DeprecationWarningrr�timeZsleep�assertIsr7r
)rrMrNrTrVrWrZr[rrr�test_floatconversion�s, z&GeneralFloatCases.test_floatconversionc	Cs&|�td��tdd�WdQRXdS)Nzkeyword argumentz3.14)r9)rrr)rrrr�test_keyword_args�sz#GeneralFloatCases.test_keyword_argscCsD|�d���|�d���|�td����|�td����dS)Ng�������?g�?r
r	)ZassertFalse�
is_integer�
assertTruer)rrrr�test_is_integer�sz!GeneralFloatCases.test_is_integercCsfx dD]\}}|�|��|�qWxNtd�D]B}t��}|dt�dd�9}|��\}}|�t|��|�|�q,Wtj}|�|dd�|td�����|�|d	d
�|td�����|�|dd
�|td�����|�|d
d�|td�����|�|dd�|td�����|�|dd�|td�����|�	t
td�j�|�	t
td�j�|�	ttd�j�dS)N))g�?)��)g�)i����rf)g)rr;)g'@)�rPi'�
i�����drr;g�rPg@g�?l�L�33�l@g������@l�����L�33�g�������i���gh��r	z-infr
)r�as_integer_ratio�range�randomZrandintr�__truediv__�	fractionsZFractionr�
OverflowErrorr)rr8Zratio�i�n�d�Rrrr�test_floatasratio�s.z#GeneralFloatCases.test_floatasratiocCsrttddtf}xl|D]d}|�||g�|�||f�|�||h�|�||di�|�|g�|�dd|�|�||�qWx�|D]�}|�|g|gkd||f�|�|f|fkd||f�|�|h|hkd||f�|�|di|dikd||f�|g|f|h|dif\}}}}|�||kd	|�|�||kd
|�|�||kd|�|�||kd|�q�WdS)
Ngg�?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)rZfloatsr8�l�tr?rsrrr�test_float_containment
s&

z(GeneralFloatCases.test_float_containmentcCs$|�|td|�f|td|�f�dS)Ng�?)rr)r�ar,rrr�assertEqualAndEqualSign&sz)GeneralFloatCases.assertEqualAndEqualSigncCs�tj}|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�dS)Ng�g�?gg0��.�+�g�g0��.�++)�operator�modr~)rr�rrr�test_float_mod,sz GeneralFloatCases.test_float_modcCs�	�	x�ttjfD�	]�}|�t|tt���|�t|dt���|�t|dt���|�t|dt���|�t|dt���|�t|dt���|�t|dt���|�t|dt���|�t|tt���|�t|tt���|�t|tt���|�t|td���|�t|td���|�t|td���|�t|td���|�t|td���|�t|td���|�t|tt���|�t|dd�|�t|dd�|�t|dd�|�t|dd�|�t|dd�|�t|dd�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dt�d�|�|dt�d�|�|dt�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dt�d�|�|dt�d�|�|td�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|td�d�|�|td�d�|�|td�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|td�d�|�|td�d�|�	t
|dd��t�|�	t
|dd��t�|�	t
|dd��t�|�	t
|dd��t�|�	t
|dd��t�|�	t
|dd��t�|�|dt�t�|�|dt�t�|�|dt�t�|�|dt�t�|�|tt�d�|�|dt�d�|�|dt�d�|�|tt�d�|�|dt�d�|�|dt�d�|�|dt�d�|�|dt�d�|�|tt�t�|�|dt�t�|�|dt�t�|�|tt�t�|�|td�d�|�|td�d�|�|td�d�|�|td�t�|�|td�t�|�|td�t�|�|td�t�|�|td�t�|�|td�t�|�|td�d�|�|td�d�|�|td�d�|�|dd�d	�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d
�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d	�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d
�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd
�d�|�	t
|dd��t�|�|dd�d�|�|dd
�d�|�|dd�d�|�|dd�d�|�|dd�d�|�	t
|dd��t�|�|dd�d�|�|dd�d�|�|dd�d�|�|dd�d�qWdS)Ng�g�g�g�gg�?g@g�?g�?g@g}Ô%�I��g}Ô%�I�Tg@��gB��gD��g@�@gB�@gD�@)�powrrcrrvrwr�ZeroDivisionErrorr~rr7�complex)rZpow_oprrr�test_float_pow@sz GeneralFloatCases.test_float_powN)rrrrr'r:r=rCrZrun_with_localerKr`rardrur|r~�requires_IEEE_754r�r�rrrrr"s4!rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�FormatFunctionsTestCasecCst�d�t�d�d�|_dS)N�doubler)r�r)rr�save_formats)rrrr�setUp
szFormatFunctionsTestCase.setUpcCs(t�d|jd�t�d|jd�dS)Nr�r)rrr�)rrrr�tearDownsz FormatFunctionsTestCase.tearDowncCsT|�t�d�dddg�|�t�d�dddg�|�ttjd�|�ttjd�dS)Nr��unknownzIEEE, big-endianzIEEE, little-endianr�chickenr;)rxrrrrr)rrrr�test_getformatsz&FormatFunctionsTestCase.test_getformatcCs�x�dD]�}t�|d�|j|dkr8|�ttj|d�nF|j|dkrZ|�ttj|d�n$|�ttj|d�|�ttj|d�|�ttj|d�qW|�ttjdd�dS)N)r�rr�zIEEE, big-endianzIEEE, little-endianr�)rrr�rr)rr{rrr�test_setformats 








z&FormatFunctionsTestCase.test_setformatN)rrrr�r�r�r�rrrrr�
sr�s�s�s�s�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�UnknownFormatTestCasecCs4t�d�t�d�d�|_t�dd�t�dd�dS)Nr�r)r�rr�)rrr�r)rrrrr�?szUnknownFormatTestCase.setUpcCs(t�d|jd�t�d|jd�dS)Nr�r)rrr�)rrrrr�EszUnknownFormatTestCase.tearDowncCs@x:dtfdtfdtfdtfgD]\}}|�ttj||�qWdS)Nz>dz<d)�
BE_DOUBLE_INF�
BE_DOUBLE_NAN�
LE_DOUBLE_INF�
LE_DOUBLE_NANrr�struct�unpack)r�fmt�datarrr� test_double_specials_dont_unpackIs
z6UnknownFormatTestCase.test_double_specials_dont_unpackcCs@x:dtfdtfdtfdtfgD]\}}|�ttj||�qWdS)Nz>fz<f)�BE_FLOAT_INF�BE_FLOAT_NAN�LE_FLOAT_INF�LE_FLOAT_NANrrr�r�)rr�r�rrr�test_float_specials_dont_unpackPs
z5UnknownFormatTestCase.test_float_specials_dont_unpackN)rrrr�r�r�r�rrrrr�=sr�c@s6eZdZejdd��Zejdd��Zejdd��ZdS)�IEEEFormatTestCasecCs:x4dtfdtfdtfdtfgD]\}}t�||�qWdS)Nz>dz<d)r�r�r�r�r�r�)rr�r�rrr�test_double_specials_do_unpack_s
z1IEEEFormatTestCase.test_double_specials_do_unpackcCs:x4dtfdtfdtfdtfgD]\}}t�||�qWdS)Nz>fz<f)r�r�r�r�r�r�)rr�r�rrr�test_float_specials_do_unpackgs
z0IEEEFormatTestCase.test_float_specials_do_unpackcCsJddlm}|�t�dd�t�d|��|�t�dd�t�d|��dS)Nr)�FLT_MAXz<fgn���Ggn����)Z	_testcapir�rr��pack)rr�rrr�test_serialized_float_roundingosz1IEEEFormatTestCase.test_serialized_float_roundingN)rrrrr�r�r�r�rrrrr�]sr�c@s2eZdZdd�Zejdd��Zdd�Zdd�Zd	S)
�FormatTestCasecCsD|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�d	}|�t|d�t|��|�t|d
�t|��|�t|d�t|��|�t|d�t|��|�td
d�d�|�tdd�d�|�td
d�d�|�tdd�d�|�td
d�d�|�tdd�d�|�tdd�d�|�ttdd�x�dd�ttd�td�d�D�dd�ttd�td �d�D�D]�}|d!k�rt|�ttd|�|�ttd
|�|�ttd|�|�ttd"|�|�ttd#|�|�ttd$|�|�ttd%|��qtW|�ttd�d&�|�ttd'�d(�|�ttd�d)�|�ttd'�d*�dS)+Ngr8z0.000000r#z0.0g{�G�z�?z0.01�gg%I�$I�,@�-�>�2g�?z1.000000g�z	-1.000000z fz	 1.000000z+fz	+1.000000�%z-100.000000%g@r?cSsg|]}t|��qSr)�chr)rr9rrr�
<listcomp>�sz.FormatTestCase.test_format.<locals>.<listcomp>r}�zr;cSsg|]}t|��qSr)r�)rr9rrrr��s�A�ZzeEfFgGn%g}Ô%�I�Tg}Ô%�I��g0��.�++g0��.�+�r
r[rwr	rv)	r�formatr1rrrl�ordrwrv)rr9�format_specrrr�test_formatws> &
zFormatTestCase.test_formatc	Cs�tt��~}xv|D]n}|�d�r q|��}|s.qttj|�d��\}}|��\}}|�|t|�|�|�|t|�d|�qWWdQRXdS)Nz--z->r�)	�open�format_testfile�
startswith�strip�mapr1�splitrr)rZtestfile�lineZlhsZrhsr��argrrr�test_format_testfile�s


z#FormatTestCase.test_format_testfilecCs:|�tdd�d�|�tdd�d�|�tdd�d�dS)Ngw��/�^@z.4z123.5g
ףp=J�@z	1.235e+03g������@z	1.235e+04)rr�)rrrr�test_issue5864�szFormatTestCase.test_issue5864cCs$|�tdd�d�|�tdd�d�|�tdd�d�|�tdd	�d
�|�tdd�d�|�tdd
�d�|�tdd�d
�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd	�d�|�tdd�d�|�tdd�d�|�tdd
�d�|�tdd�d�dS)Ng�^@Z00z123.0g�(\���^@Z00fz
123.340000Z00ez1.233400e+02Z00gz123.34z00.10fz123.3400000000z00.10ez1.2334000000e+02z00.10gZ01fg�^�z-123.0g�(\���^�z-123.340000z
-1.233400e+02z-123.34z-123.3400000000z-1.2334000000e+02)rr�)rrrr�test_issue35560�s zFormatTestCase.test_issue35560N)	rrrr�rr�r�r�r�rrrrr�us5r�c@s4eZdZdd�Ze�eedd�dkd�dd��Zd	S)
�ReprTestCasecCslttj�tj�t�dd��}x@|D]8}|��}|r$|�d�r@q$t|�}|�	|tt
|���q$W|��dS)Nrzfloating_points.txt�#)r��os�path�joinr��__file__r�r�r%r�repr�close)rZfloats_filer��vrrr�	test_repr�s
zReprTestCase.test_repr�float_repr_styler#�shortz.applies only when using short float repr stylecCs�ddddddddd	d
ddd
ddddddddddddg}xt|D]l}d|}|�|tt|���|�|tt|���|�tt|��tt|���|�tt|��tt|���q<WdS)Nz0.0z1.0z0.01z0.02z0.03z0.04z0.05z
1.23456789z10.0z100.0z1000000000000000.0z9999999999999990.0z1e+16z1e+17z0.001z0.001001z0.00010000000000001z0.0001z9.999999999999e-05z1e-05z8.72293771110361e+25z7.47005307342313e+26z2.86438000439698e+28z8.89142905246179e+28z3.08578087079232e+35r�)rr�rr1)rZtest_stringsr?Znegsrrr�test_short_repr�s>

zReprTestCase.test_short_reprN)	rrrr��unittest�
skipUnless�getattr�sysr�rrrrr��sr�c@s|eZdZdd�Zdd�Zdd�Zdd�Ze�e	e
d	d
�dkd�d
d��Ze�e	e
d	d
�dkd�dd��Zdd�Z
dd�ZdS)�
RoundTestCasecCsr|�ttt�|�ttt�|�ttt�|�tttd�|�tttd�|�tttd�|�ttdd�dS)Ngg�?zceci n'est pas un integerg�y�?)rrp�roundrvrrwr)rrrr�test_inf_nanszRoundTestCase.test_inf_nancCs�xfddddddddgD]L}|�td	|�d	�|�td
|�d
�|�td|�d�|�td|�d�qW|�td
d�d
�|�tdd�d�|�tdd�d�|�td
d�d
�|�tdd�d�dS)NiDiEi�i���llrPrigw��/�^@gw��/�^�g�u�<�7~g�g��P.5�_i,i3go���!	�i4i5gS��i;g�i)rr�)rrrrrr�test_large_nszRoundTestCase.test_large_ncCsnxhddddddddgD]L}|�td	|�d
�|�td|�d�|�td
|�d
�|�td|�d
�qWdS)Ni���i���ip���i�i�l����rPrigw��/�^@ggw��/�^�g�g�u�<�7~g�)rr�)rrrrrr�test_small_n+s
zRoundTestCase.test_small_ncCs$|�ttdd�|�ttdd�dS)Ng3t�<{�i���gv;w0�B�)rrpr�)rrrr�
test_overflow2szRoundTestCase.test_overflowr�r#r�z.applies only when using short float repr stylecCs�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d	�|�td
d�d	�|�tdd�d�|�td
d�d�|�tdd�d�|�tdd�d�|�tdd�d�dS)NgCr;g�������B�g9@���g4@g�A@gD@g�F@g�K@gN@g@P@g�R@gT@g@U@g�W@gY@)rr�)rrrr�test_previous_round_bugs6sz&RoundTestCase.test_previous_round_bugscCs�x�td�D]|}|d}|�tt|d��t|d��|�tt|d��t|d��|�tt|d��t|d��|�tt|d	��t|d
��q
Wx�tddd
�D]|}|d}|�tt|d��t|d��|�tt|d��t|d��|�tt|d��t|d��|�tt|d	��t|d
��q�Wx�td�D]~}t��}|�tt|d��t|d��|�tt|d��t|d��|�tt|d��t|d��|�tt|d	��t|d
���q"WdS)Ni�g@�@z.0frz.1fr;z.2frPz.3fr�rji�rh)rlrrr�r�rm)rrqr9rrr�test_matches_float_formatHs$  z'RoundTestCase.test_matches_float_formatcs��fdd�}x�dD]�}d|dd�}d|dd�}||td�||td�||td	�||td	�||td
�||td�||td�||td�||td�||td�||td
�||td
�qWdS)Ncs6��||||�|dd�}��t||�||�dS)Nr;)rr�)r�rS�expected)rrr�testds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)rvrw)rr�r�ZpfmtZsfmtr)rr�test_format_specialsas 
z"RoundTestCase.test_format_specialscCs�x<td�tdd�tddd�fD]}|�|d�|�|t�qWx<td�tdd�tddd�fD]}|�|d�|�|t�q\WdS)Ng�G�z��?)Zndigitsr;g{�G�z�?rP)r�rZassertIsInstance�int)rr9rrr�test_None_ndigitss""zRoundTestCase.test_None_ndigitsN)rrrr�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s	r�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	e
edd�d
kd�dd��ZdS)�
InfNanTestcCs�|�ttd���|�ttd���|�ttd���|�ttd���|�ttd���|�ttd���|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd	��d�|�ttd
��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd
�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�|�ttd�dS)Nr	z+infz-infZinfinityz	+infinityz	-infinityrvz+Infz-iNF�Infinityz	+iNfInItYz	-INFINITY�infoz+infoz-info�inz+inz-inZinfinitz+Infinz-INFIZ	infinitysz++Infz-+infz
+-infinityz
--Infinity)rcrrrr�r1rr)rrrr�test_inf_from_str�sLzInfNanTest.test_inf_from_strcCsD|�td�d�|�td�d�|�td�d�|�td�d�dS)Ng�r	g�z-inf)rr�r1)rrrr�test_inf_as_str�szInfNanTest.test_inf_as_strcCsz|�ttd���|�ttd���|�ttd���|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd��d�|�ttd�|�ttd�|�ttd	�|�ttd
�|�ttd�|�ttd�|�ttd
�|�ttd�|�ttd�|�ttd�dS)Nr
z+nanz-nanrwz+NAnz-NaNZnanaz+nanaz-nanaZnaz+naz-naz++nanz-+NANz+-NaNz--nAn)rcrrrr�r1rr)rrrr�test_nan_from_str�s,zInfNanTest.test_nan_from_strcCsD|�td�d�|�td�d�|�td�d�|�td�d�dS)Ng��r
g��g��g��)rr�r1)rrrr�test_nan_as_str�szInfNanTest.test_nan_as_strcCs0|�tdtd��d�|�tdtd��d�dS)Ng�?r	z-infg�)rrr)rrrr�test_inf_signs�szInfNanTest.test_inf_signsr�r#r�z.applies only when using short float repr stylecCs0|�tdtd��d�|�tdtd��d�dS)Ng�?r
z-nang�)rrr)rrrr�test_nan_signs�szInfNanTest.test_nan_signsN)
rrrr�r�r�r�r�r�r�r�r�r�rrrrr��s-r�c@sdeZdZed�Zed�Zed�Zed�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZdS)�HexFloatTestCasez0x.fffffffffffff8p+1024z	0x1p-1022z0x0.0000000000001p-1022z0x0.0000000000001p0cCsdt|�st|�r&t|�t|�krNdSn(||krN|dksJtd|�td|�krNdS|�d||f�dS)Ngg�?z%r not identical to %r)rr�fail)rr9�yrrr�	identical�s$zHexFloatTestCase.identicalcCsb|�|jtdd��|�|jtdd��|�|jtdd��|�|jdtdd�tdd��dS)Ng�?i���i���i���g@i�i�)r��MINr�TINY�EPS�MAX)rrrr�	test_endsszHexFloatTestCase.test_endsc3Cs�ddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3g3}x@|D]8}yt|�}Wntk
r�YqpX|�d4||f�qpWdS)5NZinfiz-Infinitz++infz-+Infz--nanz+-NaNZsnanZNaNsZnnaZanZnfZnfinityZinityZiinityZ0xnanr#� zx1.0p0z0xX1.0p0z	+ 0x1.0p0z	- 0x1.0p0z0 x1.0p0z0x 1.0p0z	0x1 2.0p0z	+0x1 .0p0z0x1. 0p0z
-0x1.0 1p0z	-0x1.0 p0z
+0x1.0p +0z	0x1.0p -0z0x1.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--0z0x1.0.p0z0x.p0z0x1,p0Z0x1pau0x1p0u0x1p0u0x1p0u	0x1.0p0z
0x1p0 
 0x2p0z0x1p0 0x1p0z>Expected float.fromhex(%r) to raise ValueError; got %r instead)�fromHexrr�)rZinvalid_inputsr9�resultrrr�test_invalid_inputsst
z$HexFloatTestCase.test_invalid_inputscCs�dtfdtfdtfdddg}ddd	d
ddd
dg}xH|D]@\}}x6|D].}x(|D] }t|||�}|�||�qPWqFWq8WdS)Nr	z	-Infinityr
)z1.0g�?)z-0x.2g��)z-0.0g�r#r��	�
z
 	���
)rvrwr�r�)rZvalue_pairsZ
whitespaceZinpr�Zlead�trailZgotrrr�test_whitespaceHs&

z HexFloatTestCase.test_whitespacecCs�|j}|j}|j}|j}|�td�t�|�td�t�|�td�t�|�td�t�|�td�t�|�td�t�|�td�t�|�td�t�|�td	�t�|�td
�t�|�td�t�|�td�t�|�td
�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td �d�|�td!�d�|�td"�d�|�td#�d�|�td$�d�|�td%�d�|�td&�d�|�td'�d�|�td(�d�|�td)�d�|�td*�d+�|�td,�d+�|�td-�d+�|�td.�d+�|�td/�d0�|�td1�d0�|�td2�d0�|�td3�d0�|�td4�d0�|�td5�d0�|�td6�d0�|�td7�d0�td8�}|�td9�|�|�td:�|�|�td;�|�|�td<�|�|�td=�|�|�td>�|�|�td?�|�|�td@�|�|�tdA�|�|�tdB�|�|�td8�|�|�tdC�|�|�tdD�|�|�tdE�|�|�tdF�|�|�tdG�|�|�tdH�|�|�tdI�|�|�tdJ�|�|�tdK�|�|�tdL�|�|�tdM�|�|�tdN�|�|�tdO�|�|�tdP�|�|�tdQ�|�|�tdR�|�|�tdS�|�|�tdT�|�|�tdU�|�|�tdV�|�|�tdW�|�|�t	tdX�|�t	tdY�|�t	tdZ�|�t	td[�|�t	td\�|�t	td]�|�t	td^�|�t	td_�|�t	td`�|�t	tda�|�t	tdb�|�t	tdc�|�t	tdd�|�t	tde�|�t	tdf�|�t	tdg�|�t	tdh�|�t	tdi�|�t	tdj�|�tdk�|�|�tdl�|�|�tdm�|�|�tdn�do�|�tdp�do�|�tdq�dr�|�tds�do�|�tdt�dr�|�tdu�do�|�tdv�do�|�tdw�dr�|�tdx�dr�|�tdy�do�|�tdz�dr�|�td{�dr�|�td|�dr�|�td}�do�|�td~�dr�|�td�do�|�td��do�|�td��dr�|�td��dr�|�td��do�|�td��dr�|�td��dr�|�td��|�|�td��|�|�td��|�|�td��do�|�td��do�|�td��|�|�td��|�|�td��|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��dr�|�td��dr�|�td��|�|�td��|�|�td��|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��d�|�|�td��|d�|�|�td��|d�|�|�td��|d�|�|�td��|d�|�|�td��|d�|�|�td��|d�|�|�td��|d�|�|�td��|d�|�|�td��|d�|�|�td��|d�|�|�td��||�|�td��||�|�td��||�|�td��||�|�td��||�|�td��||�|�td��||�|�td��|�|�td��|�|�tdƒ|�|�tdÃ|�|�tdă|�|�tdŃ|�|�tdƃ|�|�tdǃ|�|�tdȃ|�|�tdɃ||�|�tdʃ||�|�td˃||�|�td̃||�|�td̓||�|�td΃||�|�tdσ||�|�tdЃ|d�|�|�tdуd|�|�td҃d|�|�tdӃd|�|�tdԃd|�|�tdՃd|�|�tdփd|d��|�td׃d|d��|�td؃d|d��|�tdكd|d��|�tdڃd|d��|�tdۃd|d��|�td܃d|d��|�td݃d�|�tdރd�|�td߃d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�|�|�td�d|�|�td�d|�|�td�d|�|�td�d|�|�td�d|�|�td�d|�|�td�d|�|�td�d|�|�td��d|�|�td��d|�|�td��d|�|�td��d|�|�td��d|�|�td��d|�|�td��d|�|�td��d|�|�td��dd�|�|�td��dd�|�|�td��dd�|�|�t�d�dd�|�|�t�d�dd�|�|�t�d�dd�|�|�t�d�dd�|�|�t�d�dd�|�|�t�d�dd�|�|�t�d�dd�|�dS(Nr	z+Infz-INFZiNfr�z	+INFINITYz	-infinityz	-iNFiNitYr
z+NaNz-NaNz-nAN�1g�?z+1z1.z1.0z1.0p0Z01z01.Z0x1z0x1.z0x1.0z+0x1.0Z0x1p0Z0X1p0Z0X1P0Z0x1P0z0x1.p0z0x1.0p0z0x.1p4z0x.1p04z0x.1p004z0x1p+0z0x1P-0z+0x1p0Z0x01p0Z0x1p00z 0x1p0 z
 0x1p0z0x1p0 	Z0xap0g$@Z0xAp0Z0xaP0Z0xAP0Z0xbep0g�g@Z0xBep0Z0xbEp0z0XBE0P-4Z0xBEp0z0xB.Ep4z0x.BEp8z	0x.0BEp12z0x1.921fb54442d18p1z0x.006487ed5110b46p11z0x.00c90fdaa22168cp10z0x.01921fb54442d18p9z0x.03243f6a8885a3p8z0x.06487ed5110b46p7z0x.0c90fdaa22168cp6z0x.1921fb54442d18p5z0x.3243f6a8885a3p4z0x.6487ed5110b46p3z0x.c90fdaa22168cp2z0x3.243f6a8885a3p0z0x6.487ed5110b46p-1z0xc.90fdaa22168cp-2z0x19.21fb54442d18p-3z0x32.43f6a8885a3p-4z0x64.87ed5110b46p-5z0xc9.0fdaa22168cp-6z0x192.1fb54442d18p-7z0x324.3f6a8885a3p-8z0x648.7ed5110b46p-9z0xc90.fdaa22168cp-10z0x1921.fb54442d18p-11z0x1921fb54442d1.8p-47z0x3243f6a8885a3p-48z0x6487ed5110b46p-49z0xc90fdaa22168cp-50z0x1921fb54442d18p-51z0x3243f6a8885a30p-52z0x6487ed5110b460p-53z0xc90fdaa22168c0p-54z0x1921fb54442d180p-55z	-0x1p1024z	0x1p+1025z	+0X1p1030z
-0x1p+1100Z0X1p123456789123456789z+0X.8p+1025z+0x0.8p1025z-0x0.4p1026z	0X2p+1023z	0x2.p1023z-0x2.0p+1023z
+0X4p+1022z0x1.ffffffffffffffp+1023z-0X1.fffffffffffff9p1023z0X1.fffffffffffff8p1023z+0x3.fffffffffffffp1022z0x3fffffffffffffp+970Z0x10000000000000000p960z-0Xffffffffffffffffp960z+0x1.fffffffffffffp+1023z-0X1.fffffffffffff7p1023z$0X1.fffffffffffff7fffffffffffffp1023Z0x0p0gZ0x0p1000z	-0x0p1023g�Z0X0p1024z	-0x0p1025Z0X0p2000Z0x0p123456789123456789z-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-123456789123456789z0x1.00000000000000001p-1075z-0x1.1p-1075z0x1.fffffffffffffffffp-1075z	0x1p-1076z	0X2p-1076z	0X3p-1076z	0x4p-1076z	0X5p-1076z	0X6p-1076rPz	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-1076���z
-0X7p-1076z
-0X8p-1076z
-0X9p-1076z
-0Xap-1076z
-0xbp-1076���z
-0xcp-1076z
-0Xdp-1076z
-0xep-1076���z
-0Xfp-1076z-0X10p-1076z0x0.ffffffffffffd6p-1022z0x0.ffffffffffffd8p-1022z0x0.ffffffffffffdap-1022z0x0.ffffffffffffdcp-1022z0x0.ffffffffffffdep-1022z0x0.ffffffffffffe0p-1022z0x0.ffffffffffffe2p-1022z0x0.ffffffffffffe4p-1022z0x0.ffffffffffffe6p-1022z0x0.ffffffffffffe8p-1022z0x0.ffffffffffffeap-1022z0x0.ffffffffffffecp-1022z0x0.ffffffffffffeep-1022z0x0.fffffffffffff0p-1022z0x0.fffffffffffff2p-1022z0x0.fffffffffffff4p-1022z0x0.fffffffffffff6p-1022z0x0.fffffffffffff8p-1022z0x0.fffffffffffffap-1022z0x0.fffffffffffffcp-1022z0x0.fffffffffffffep-1022z0x1.00000000000000p-1022z0x1.00000000000002p-1022z0x1.00000000000004p-1022z0x1.00000000000006p-1022z0x1.00000000000008p-1022z0x1.0000000000000ap-1022z0x1.0000000000000cp-1022z0x1.0000000000000ep-1022z0x1.00000000000010p-1022z0x1.00000000000012p-1022z0x1.00000000000014p-1022z0x1.00000000000016p-1022z0x1.00000000000018p-1022z0x0.fffffffffffff0p0z0x0.fffffffffffff1p0z0X0.fffffffffffff2p0z0x0.fffffffffffff3p0z0X0.fffffffffffff4p0z0X0.fffffffffffff5p0z0X0.fffffffffffff6p0z0x0.fffffffffffff7p0z0x0.fffffffffffff8p0z0X0.fffffffffffff9p0z0X0.fffffffffffffap0z0x0.fffffffffffffbp0z0X0.fffffffffffffcp0z0x0.fffffffffffffdp0z0X0.fffffffffffffep0z0x0.ffffffffffffffp0z0X1.00000000000000p0z0X1.00000000000001p0z0x1.00000000000002p0z0X1.00000000000003p0z0x1.00000000000004p0z0X1.00000000000005p0z0X1.00000000000006p0z0X1.00000000000007p0z(0x1.00000000000007ffffffffffffffffffffp0z0x1.00000000000008p0z&0x1.00000000000008000000000000000001p0r;z0X1.00000000000009p0z0x1.0000000000000ap0z0x1.0000000000000bp0z0X1.0000000000000cp0z0x1.0000000000000dp0z0x1.0000000000000ep0z0X1.0000000000000fp0z0x1.00000000000010p0z0X1.00000000000011p0z0x1.00000000000012p0z0X1.00000000000013p0z0X1.00000000000014p0z0x1.00000000000015p0z0x1.00000000000016p0z0X1.00000000000017p0z(0x1.00000000000017ffffffffffffffffffffp0z0x1.00000000000018p0z&0X1.00000000000018000000000000000001p0z0x1.00000000000019p0z0X1.0000000000001ap0z0X1.0000000000001bp0z0x1.0000000000001cp0z0x1.0000000000001dp0z0x1.0000000000001ep0z0X1.0000000000001fp0z0x1.00000000000020p0)
r�r�r�r�r�r�rvrwrrp)rr�r�r�r�Zpirrr�
test_from_hexbs





zHexFloatTestCase.test_from_hexc	Cs�dd�}xLtt|j|j|j|j|jdgD](}|�|||��|�|||��q*Wddl}xntd�D]b}|�dd�}|��}|�	dd	g�}y|t
||�}Wntk
r�YqhX|�|tt
|���qhWdS)
NcSstt|��S)N)r��toHex)r9rrr�	roundtrip�sz2HexFloatTestCase.test_roundtrip.<locals>.roundtripgri'iP���i�g�?g�)rwrvr�r�r�r�rmrlZ	randrange�choicerrpr�r)rrr9rmrq�e�mr?rrr�test_roundtrips&zHexFloatTestCase.test_roundtripcCs�Gdd�dt�}|�d���}|�t|�|�|�|d�Gdd�dt�}|�d���}|�t|�|�|�|d�|�t|dd�d	�dS)
Nc@seZdZdd�ZdS)z)HexFloatTestCase.test_subclass.<locals>.FcSst�||d�S)Nr;)rrQ)rRrSrrrrQ�sz1HexFloatTestCase.test_subclass.<locals>.F.__new__N)rrrrQrrrrr[�sr[g�?g@c@seZdZdd�ZdS)z*HexFloatTestCase.test_subclass.<locals>.F2cSs
d|_dS)N�bar)�foo)rrSrrr�__init__�sz3HexFloatTestCase.test_subclass.<locals>.F2.__init__N)rrrr
rrrr�F2�srr	Znoner)r�fromhex�hexr_r7rr�)rr[r8rrrr�
test_subclass�szHexFloatTestCase.test_subclassN)rrrr�r�r�r�r�r�r�r�r�rrrrrrrr��s
@r��__main__)>rorr�rmr�r�r^r�r�rZtest.test_grammarrrZmathrrrrrrvrw�hasattrZhave_getformatr�Zrequires_getformatZrequires_setformatr��dirnamer��curdirZtest_dirr�r�r
rZTestCaserr�r�r2�reversedr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r
rr�r�mainrrrr�<module>sf
k
%
^@
vf8