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: //usr/local/lib/python3.7/test/__pycache__/test_long.cpython-37.pyc
B

��g8��@s,ddlZddlmZddlZddlZddlZddlZejjZ	de	Z
e
dZdZdZ
ddde
e
d?ddgZd	Zx*ede	�D]Ze�ed�ed>Zq|W[ed
d�eD�dd�eD�7ZejjZejjZejjZejjZdedeedZd
d�Zdd�ZGdd�dej�Z e!dk�r(e�"�dS)�N)�support���F�lUU�*UU�*l�*UU�*UU
�cCsg|]
}|�qS�r)�.0�xrr�*/usr/local/lib/python3.7/test/test_long.py�
<listcomp>srcCsg|]
}|�qSrr)r	r
rrrrscCstjjd}tjj|}d|>}ddddddddg}|dkr@dS|dkrTt|�S|��|}|dkrr||>n||?t|d|>@�B}|||d@7}|||k|kr�td��|d	dkr�|d	dtjjks�t�|d|tjj	ks�t�t
�t|�|�S)
z9
    Correctly-rounded integer-to-float conversion.

    rrr������g�z%integer too large to convert to floatr)
�sys�
float_info�mant_dig�max_exp�int_to_float�
bit_length�bool�
OverflowError�AssertionError�max�math�ldexp�float)�nZ	PRECISIONZ	SHIFT_MAXZQ_MAXZROUND_HALF_TO_EVEN_CORRECTION�shift�qrrrr's ,$rcCs||Adk}t|�t|�}}|s*td��|t|kr>td��|��|��}|dkrf|d||ks�|dkr�|d||kr�|d7}t|t�t}|t|d�>|t|d�>}}t||�\}}d||ks�d||kr�|ddkr�|d7}t	�
||�}|�r|S|S)z-Correctly-rounded true division for integers.rzdivision by zeroz)int/int too large to represent as a floatrr)�abs�ZeroDivisionError�DBL_MIN_OVERFLOWrrr�DBL_MIN_EXP�DBL_MANT_DIG�divmodrr)�a�b�negative�d�expr�r�resultrrr�truedivUs 2 $r-c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zejdd ��Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�ZdWd2d3�Zejd4d5��Zd6d7�Zd8d9�Z ej!d:d;��Z"ej!ej#e$j%d<d=d>d?�d@dA���Z&dBdC�Z'ej!ej#e$j%dDdEd>d?�dFdG���Z(dHdI�Z)dJdK�Z*dLdM�Z+dNdO�Z,dPdQ�Z-dRdS�Z.dTdU�Z/dVS)X�LongTestcCs�|�|d�|t}|td}d}d}tt��td�dB}x�||kr�|d?d}t|||�}|�d|koztkn�||}||>}|d@r�|d|>dB}tt��td�}qBW|�||ko�|kn�t��dkr�|}|S)Nrrrg�?)Z
assertGreater�SHIFT�int�random�min�
assertTrue)�self�ndigitsZnbits_hiZnbits_lo�answerZnbitsr+�bitsrrr�getran{s&
zLongTest.getrancCs@d}x$t|�D]}|t>t�dt�B}qWt��dkr<|}|S)Nrg�?)�ranger/r1Zrandint�MASK)r5r6�irrr�getran2�szLongTest.getran2c
	Cs�|j}|j||d���t||�\}}||||}}||||}}	|||	d�|||d�|||d�|||||d�|dkr�|�d|ko�|knd�n |�||ko�dknd�WdQRXdS)N)r
�yzmultiplication does not commutez(divmod returns different quotient than /z#divmod returns different mod than %zx != q*y + r after divmodrzbad mod from divmod)�assertEqual�subTestr%r3)
r4r
r=�eqrr+Zq2Zr2ZpabZpbarrr�check_division�s"zLongTest.check_divisioncCsttdtd��ttttd��}|�td�x>|D]6}|�|�}x&|D]}|�|�p\d}|�||�qLWq8W|�dd�|�dd�|�dd	�|�d
d�|�dd
�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�dS)Nr��l!Us/w��3alZW��3al+Q@{�d��B]Ol�Nl�O�Ol�Nl�t�e�o%g�q�Cgx<l�&�ghrsGlQ5��K�4+�o�-bklC�4+�o�-bkl��.#w�flD�&I-�Xl�Z��nSu9bl�c�v��
��<�Ilrd�FBu�'�pl�PhbIi|�$l1�m�{Wqi���8l�s~5^Fi�y�+l'H�
<{�Cl`<{�Cl�ED_5(�Nl�o�ybal=2zz6l�9�t�m)�listr9�	MAXDIGITS�KARATSUBA_CUTOFF�appendr8rA)r4�digits�lenxr
�lenyr=rrr�
test_division�s4


zLongTest.test_divisionc	Cs�ttdd��ttttd��}|�tdtdg�dd�|D�}x�|D]�}d|>d}xp|D]h}||krnq`|j||d��Fd|>d}||}d||>d|>d|>d}|�||�WdQRXq`WqJWdS)Nr��
�dcSsg|]}|t�qSr)r/)r	�digitrrrr�sz+LongTest.test_karatsuba.<locals>.<listcomp>)�abits�bbits)rDr9rF�extendr?r>)	r4rHr7rPr&rQr'r
r=rrr�test_karatsuba�s

zLongTest.test_karatsubac
Cs�|j}|j|d���||d@d�||dB|�||dA|�||d@|�||dBd�||dA|�|||�|||@|�|||B|�|||Ad�|||@d�|||Bd�|||Ad�||d|�|||d�WdQRXx�tdt�D]�}d|}|j|||d��n|||>|?|�|||||?�|||||>�|||@||?|>�|||@||d@�WdQRX�qWdS)N)r
rr
rr)r
r�p2)r>r?r9r/)r4r
r@rrTrrr�check_bitop_identities_1�s2z!LongTest.check_bitop_identities_1c	Cs�|j}|j||d���|||@||@�|||B||B�|||A||A�|||A|A|�|||@||B�|||B||@�|||A||B||@@�|||A||@||@B�|||A||B||B@�WdQRXdS)N)r
r=)r>r?)r4r
r=r@rrr�check_bitop_identities_2sz!LongTest.check_bitop_identities_2c	Cs�|j}|j|||d���|||@|@|||@@�|||B|B|||BB�|||A|A|||AA�||||B@||@||@B�||||@B||B||B@�WdQRXdS)N)r
r=�z)r>r?)r4r
r=rWr@rrr�check_bitop_identities_3sz!LongTest.check_bitop_identities_3c
Cs�xtD]}|�|�qWtdtd�}x`|D]X}|�|�}|�|�x>|D]6}|�|�}|�||�|�|||�||d��qJWq,WdS)Nrr)�specialrUr9rEr8rVrX)r4r
rHrIrJr=rrr�test_bitop_identitiess





zLongTest.test_bitop_identitiescCs�g}d}|dkrd|}}x$|r@t||�\}}|�t|��qW|��|pRdg}dd|�ddddd�|d�d	d
�|D��S)Nrr�-Z0bZ0o��0x)r�rM�css|]}d|VqdS)Z0123456789abcdefNr)r	r;rrr�	<genexpr>1sz'LongTest.slow_format.<locals>.<genexpr>)r%rGr0�reverse�join)r4r
�baserH�signr+rrr�slow_format%s
zLongTest.slow_formatc
Cs�x�dtfdtfdtfdtfdtffD]n\}}||�}|j||jd��|�||�}|�||�WdQRX|j|d��|�t	|d�|�WdQRXq$WdS)Nrr^rMr_)r
�mapper)�gotr)
�bin�oct�str�repr�hexr?�__name__rer>r0)r4r
rcrfrg�expectedrrr�check_format_13s,zLongTest.check_format_1cCsZxtD]}|�|�qWx<td�D]0}x*tdtd�D]}|�|�}|�|�q6Wq"WdS)NrMr)rYror9rEr8)r4r
r;rIrrr�test_format<s

zLongTest.test_formatc
Cs4ddddfg}x||D]t\}}xjdD]b}x\dD]T}|||}|}|dkrX|tk	rX|}y|�t|�|�Wq.tk
r�Yq.Xq.Wq$WqW|�ttd�|�ttd	�|�ttd
�|�ttd�|�ttdd
�|�ttdd�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�td d�d�|�ttd!d�|�ttd"d�d#d$d%d&d'd(d)d*d+d,dd,dg}x|D]}	|�ttd-|	��qW|�ttd.�dS)/N)Z100000000000000000000l F�x:^VZe10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000rMrN)r\�+r[)r\� �	z  		  r[Z123LZ123lZ0Lz-37LZ0x32Lr_Z1L���+Z000rZ0o123�SZ0x123i#Z0b100rz	 0O123   z 0X123  z 0B100 �0z+0z-0Z00Z08z-012395is���i���li�l����l����ll����l����rZ42uこんにちは)�
ValueErrorr>r0�assertRaises)
r4ZLL�s�vrd�prefix�ssZvvZ
invalid_basesrcrrr�	test_longDsP


zLongTest.test_longcCsBGdd�d�}|�tt|��Gdd�d�}|�t|��d�dS)Nc@seZdZdd�ZdS)z*LongTest.test_conversion.<locals>.JustLongcSsdS)N�*r)r4rrr�__long__�sz3LongTest.test_conversion.<locals>.JustLong.__long__N)rm�
__module__�__qualname__r�rrrr�JustLongsr�c@seZdZdd�Zdd�ZdS)z+LongTest.test_conversion.<locals>.LongTrunccSsdS)Nr�r)r4rrrr��sz4LongTest.test_conversion.<locals>.LongTrunc.__long__cSsdS)Ni�r)r4rrr�	__trunc__�sz5LongTest.test_conversion.<locals>.LongTrunc.__trunc__N)rmr�r�r�r�rrrr�	LongTrunc�sr�i�)rz�	TypeErrorr0r>)r4r�r�rrr�test_conversion}szLongTest.test_conversioncCslyt|�}Wntk
r$d}YnXyt|�}Wntk
rJd}YnXd�|||�}|�|||�dS)N�overflowzAError in conversion of integer {} to float.  Got {}, expected {}.)rrr�formatr>)r4r�actualrn�msgrrr�check_float_conversion�s


zLongTest.check_float_conversionc

Csddddddddd	d
ddg}x0|D](}|�t|�|�|�t|�|�q"WxNd
D]F\}}x<td�D]0}|�ttd|d|��d|d|�qfWqTWxNdD]F\}}x<td�D]0}|�ttd|d|��d|d|�q�Wq�Wtt�}dt}||d}|�t|�t�|�t|d�t�|�t|d�t�|�tt|�|�td|�t�|�tt|�|�tt|d�|�tt|�|�tt|d�|�ttd|d�|�ttd|�|�tt||�xntd�D]b}d|dd}d|d}|�tt|��|�d|d}d|d}|�tt|��|��q�W|d||d|d||d|d||dd|dd|||g}|�|�x@tdd�D]2}x*tdd�D]}|�	d|d|��q�W�q�Wx$|D]}	|�
|	�|�
|	��q�WdS)Nrrrl����l����l����lll����l����ll))rr)rr)rCr)rr)rLr)�r�)rr^r))rr)rr)rr)rCr)rr)rLr)r�r^)rr^)r^r^)�	r^)rMr^)��)r�r�)�
r�)rBr_)rr_rNl���r^i������5)r>rr9r0�DBL_MAX�DBL_MAX_EXPrzrrRrGr�)
r4Zexact_valuesr
r=�pZint_dbl_maxZ	top_powerZhalfwayZtest_values�valuerrr�test_float_conversion�sh
44
"

zLongTest.test_float_conversioncCszx dD]}|�tt|��|�qWd}dd>}|}|||td�}xdD]}|�tt||�qHW|�t|�t|�d�dS)N)g�g�gg�?g@AX123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345123451234512345ri0u)�huge�mhuge�shuger)$zfloat(huge)zfloat(mhuge)z
complex(huge)zcomplex(mhuge)zcomplex(huge, 1)zcomplex(mhuge, 1)zcomplex(1, huge)zcomplex(1, mhuge)z	1. + hugez	huge + 1.z
1. + mhugez
mhuge + 1.z	1. - hugez	huge - 1.z
1. - mhugez
mhuge - 1.z	1. * hugez	huge * 1.z
1. * mhugez
mhuge * 1.z
1. // hugez
huge // 1.z1. // mhugezmhuge // 1.z	1. / hugez	huge / 1.z
1. / mhugez
mhuge / 1.z
1. ** hugez
huge ** 1.z1. ** mhugezmhuge ** 1.zmath.sin(huge)zmath.sin(mhuge)zmath.sqrt(huge)zmath.sqrt(mhuge)z(float(shuge) should not equal int(shuge))r>rr0rrzr�evalZassertNotEqual)r4r
r�r�r��	namespace�testrrr�test_float_overflow�s

zLongTest.test_float_overflowcCs�t�tj�}xZttd��dddgD]@}d|}t�|�}|�||�||}t�|�}|�||�q$Wx8dd>ddfD]$}|�ttj|�|�ttj|�qzWdS)NrMrNi�i'rrr)	r�log10�erDr9ZassertAlmostEqual�logrzry)r4ZLOG10Er*r�r�rnr�Zbadrrr�	test_logss

zLongTest.test_logsc

s�|j}G�fdd�d��ddddddd	g}xJd
D]B}|�|d|d||d|dt|d�t|�t|d�g�q0W|�ddd
tjttj�g�td	�}|�ddd
dd>|d||dg�|�dd�|D��x�|D]�}�|�}x�|D]�}�|�}||k||k}|j|||d���||k||k}	|||	�|||k|dk�|||k|dk�|||k|dk�|||k|dk�|||k|dk�|||k|dk�WdQRXq�Wq�WdS)NcsHeZdZdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)z)LongTest.test_mixed_compares.<locals>.Ratc	Ss0t|t�r||_d|_�nt|t��r t�t|��\}}|dksZd|krTdksZnt�d}d}xb|r�t�	||�}t|�}||?dks�t�||>|B}||8}d|kr�dks�nt�||8}qdW|dkr�||>}d}n|}d|>}|dkr�|}||_||_t|�t|�|k�s,t�nt
d|��dS)Nrrg�?g�?�gzcan't deal with %r)�
isinstancer0rr)rrZfrexpr rrr�)	r4r��fr�ZCHUNK�toprOrr)rrr�__init__s6

"
z2LongTest.test_mixed_compares.<locals>.Rat.__init__cs<t|��s�|�}|j|j|j|j}}||k||kS)N)r�rr))r4�otherr
r=)�Ratrr�_cmp__Fs
z0LongTest.test_mixed_compares.<locals>.Rat._cmp__cSs|�|�dkS)Nr)r�)r4r�rrr�__eq__Ksz0LongTest.test_mixed_compares.<locals>.Rat.__eq__cSs|�|�dkS)Nr)r�)r4r�rrr�__ge__Msz0LongTest.test_mixed_compares.<locals>.Rat.__ge__cSs|�|�dkS)Nr)r�)r4r�rrr�__gt__Osz0LongTest.test_mixed_compares.<locals>.Rat.__gt__cSs|�|�dkS)Nr)r�)r4r�rrr�__le__Qsz0LongTest.test_mixed_compares.<locals>.Rat.__le__cSs|�|�dkS)Nr)r�)r4r�rrr�__lt__Ssz0LongTest.test_mixed_compares.<locals>.Rat.__lt__N)
rmr�r�r�r�r�r�r�r�r�r)r�rrr�s(r�rg����MbP?g�G�z��?g�?g�?g@��x�DgZb���ti)g�BgCg@Cg333333�?rri NcSsg|]
}|�qSrr)r	r
rrrrasz0LongTest.test_mixed_compares.<locals>.<listcomp>)r
r=�Rcmp)r>rRr0r�maxsizerr?)
r4r@Zcases�tr
ZRxr=ZRyr�Zxycmpr)r�r�test_mixed_comparess09
$$


zLongTest.test_mixed_comparescCs�|�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�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�tdd�d�|�td d�d
�|�td d�d
�|�ttd!d"�d�d!�|�ttd!d"�d�d#�|�ttd!d"�d�d$�|�ttd!d"�d�d%�|�ttd&d'�|�td&d(�d)�|�td&d*�d+�|�tdd,�d�|�td d,�d
�|�tdd,�d-�|�tdd,�d.�|�tdd/�d-�|�tdd/�d.�|�tdd0�d1�|�tdd0�d.�|�tdd2�d3�|�tdd2�d.�|�ttd&d4�|�td&d5�d6�|�tdd7�d8�|�td d7�d9�|�tdd7�d:�|�tdd7�d;�|�tdd<�d:�|�tdd<�d;�|�tdd=�d>�|�tdd=�d;�|�tdd?�d@�|�tdd?�d;�|�ttd&dA�|�tdBdC�dD�|�ttddE�|�ttddF�|�ttddG�|�ttddH�|�tdItddJ�|�tdItddK�|�tdItddL�|�tdItddM�|�tdNtddO�|�tdPtddQ�x�dRdS�ttdT�tdU�d�D�dVdS�ttdW�tdX�d�D�D]j}|dYk�r�|�ttdZ|�|�ttd|�|�ttd|�|�ttd[d\|�|�ttd[d\|��q�Wx:d]D]2}x*d^D]"}|�t||�tt|�|���q`W�qVWdS)_Ni�[r)Z	123456789�,z123,456,789�_Z123_456_789rr[�1r
z-1z-3z  1z -1z+3z +1z 3rrz 1rCr
�3�Xi�Z4d2i.���z-4d2Z8xz     4d2z    -4d2����ber_ZBEz-bez-BEi��Iz,xZ_xZ	4996_02d2Z_XZ	4996_02D2�oZ2322z-2322z-oz oz 2322z+oz+2322z,oZ_oZ
111_4540_1322r'Z11z-11Z10011010010z-10011010010z-bz bz 10011010010z+bz+10011010010z,bi90Z_bZ11_0000_0011_1001z1.3Z_cz,cz+czCannot specify bothz_,z,_z_,dz,_dzCannot specify ',' with 's'z,szCannot specify '_' with 's'Z_scSsg|]}t|��qSr)�chr)r	r
rrrr�sz+LongTest.test__format__.<locals>.<listcomp>r&rWcSsg|]}t|��qSr)r�)r	r
rrrr�s�A�ZzbcdoxXeEfFgGn%rrrNzeEfFgG%)rrr
rNi����i��Ii.�i�)	r>r�r0rzryZassertRaisesRegexr9�ordr)r4�format_specr�rrr�test__format__qs� &


zLongTest.test__format__cCs:|�tttd��|�tttd��|�tttd��dS)N�infz-inf�nan)rzrr0rry)r4rrr�test_nan_inf�szLongTest.test_nan_infc	Cs�|�t��dd}WdQRX|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�dS)NrrrCri����r�)rzr!r>)r4r�rrr�test_mod_division�szLongTest.test_mod_divisioncCs�dd>}|}|�||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�}xdD]}|�tt||��q6Wx*d
D]"}t||�}|�|dd|��qVWxdD]}|�tt||��q�WdS)Nri@�g�?g�gi�gԄ@gԄ�g�?i@B)r�r�)zfloat(huge)zfloat(mhuge)zhuge / 1zhuge / 2z	huge / -1z	huge / -2zmhuge / 100zmhuge / 200)z1 / hugez2 / hugez	-1 / hugez	-2 / hugez100 / mhugez200 / mhugezexpected underflow to 0 from %r)zhuge / 0z	mhuge / 0)r>rzrr�r!)r4r�r�r�r�Z	underflowr,Zzerorrr�test_true_division�s2




zLongTest.test_true_divisionc	Cs�|�t��dd}WdQRX|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�|�dd�dS)Nrrr
rCr�r)rzr!r>)r4r�rrr�
test_floordivszLongTest.test_floordivTc
Cs�|r"tt|�t|��dtkr"dSytt||��}Wn.tk
rLd}Yntk
rbd}YnXyt||�}Wn.tk
r�d}Yntk
r�d}YnX|�||d�||||��dS)z�Verify that the result of a/b is correctly rounded, by
        comparing it with a pure Python implementation of correctly
        rounded division.  b should be nonzero.rNr�Zzerodivisionz7Incorrectly rounded division {}/{}: expected {}, got {})	rr r$rkr-rr!r>r�)r4r&r'Z
skip_smallrnrgrrr�
check_truedivs 	

zLongTest.check_truedivcCs�|�dd�|�dd�|�dd�|�dd�|�dd�|�ddtd�|�dd	dtt�|�ddd
d�|�ddd
d�dtttttf}x||D]t}xnt|d|d�D]X}|�ddt|d�ddt|d��|�ddt|d�ddt|d��q�Wq�Wxpddd
ddd
d
dddddddgD]F}x>tdd�D]0}|�|t||�|�|t||��qXW�qHWxBtd�D]6}|�dtddddd|dtd��q�W|�dd�|�d d!�xBtd"�D]6}|�d|dd|�|�d|d|d��q�Wxfddd#d
d$d%dd&dd
d
dddddddgD]4}x,tdd�D]}|�dt|||��qrW�qbWx$td'd(�D]}|�|dd)��q�Wx�d*dd
dd"gD]r}xjtd"�D]^}t�d|�}t�|d|d�}	|�||	�|�||	�|�||	�|�||	��q�W�q�Wx~td+�D]r}
t�d"�}t�dd"�}t�d|�}
t�dd|�}|�|
|�|�|
|�|�|
|�|�|
|��qTWdS),N�{ri8���rCr�ige~ri90iNFrNíl90r�Qri0&iCr�r
r���i��i����)�2i����rM���i�
l�E,J_l�J�bi�rr^r_� i���i4ld(	i')	r�r�r$r#r9rr"r1�	randrange)r4�basesrcr*�mrr;�Mr&r'r�Za_bitsZb_bitsr
r=rrr�$test_correctly_rounded_true_division8sf
*2""$
z-LongTest.test_correctly_rounded_true_divisionc	Cs�|�t��dd>WdQRX|�t��ddd>>WdQRX|�t��dd?WdQRX|�t��ddd>?WdQRXdS)Nr�r�ri�)rzry)r4rrr�test_negative_shift_count�sz"LongTest.test_negative_shift_countc	Csr|�dd�|�dd�|�t��dd>WdQRX|�ddd>>d�|�t��ddd>>WdQRXdS)Nrr
ri�)r>rzry)r4rrr�test_lshift_of_zero�szLongTest.test_lshift_of_zerocCs,|�dtj>d�|�dtjd>d�dS)Nrr)r>rr�)r4rrr�test_huge_lshift_of_zero�sz!LongTest.test_huge_lshift_of_zeroi�g�?F)ZmemuseZdry_runcCs$|�dtjd>dd>tj>�dS)Nri�)r>rr�)r4�sizerrr�test_huge_lshift�szLongTest.test_huge_lshiftcCs,|�ddd>?d�|�ddd>?d�dS)Nr�ri�ri���r
)r>)r4rrr�test_huge_rshift�szLongTest.test_huge_rshifti�g�?cCsJdd>dtj>}|�|tjd?dd>d�|�|tjd?d�dS)Nri�r�i�rLi�r)rr�r>)r4r�r�rrr�test_huge_rshift_of_huge�sz!LongTest.test_huge_rshift_of_hugecCs�x�tdd�D]�}|�||d�|�||d�|�||d�|�||d�|�||d@�|�||dB�|�||dA�|�||�|�||d�|�|tt|���|�||d>d?t|��qWd}|�||d�|�d|d�dS)Nr�irrr
rl)r9�assertIsr0rj)r4r;rrr�test_small_ints�szLongTest.test_small_intscCs�d}x�tdd�D]�}|��}|�|tt|��d���|dkrn|�d|dt|�kodd|kn�n|�|d�|dkr|�|dt�	t�
t|��t�
d�|��qW|�d��d�|�d��d�|�d��d�|�d��d�|�d	��d�x�d
D]�}d|}|�|d��|�|�d|��|�|�|��|d�|�|��|d�|�|d��|d�|�|d��|d��q
WdS)Ng�����|�=i��i�z-0brrrr
r)rrCrr_r��r��!�?�@��)r9rr>�lenrh�lstripr3r rZfloorr�)r4Ztinyr
�kr;r&rrr�test_bit_length�s.0&
zLongTest.test_bit_lengthcCs�ddddddddddddddddddddd�}x\tddd�D]L}xF|��D]:\}}t||d�}||}|�||�|�t|�t�qJWq<W|�tdd	�d
�|�tdd	�d�|�td
d	�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�|�td d�d!�|�td d	�d"�|�td d�d#�|�td d$�d%�|�td d&�d'�|�td d(�d)�|�td d*�d+�|�td d,�d-�|�td d.�d/�|�td d0�d1�|�td d2�d�|�td d3�d�|�td d4�d�xNtdd�D]@}td|d5d�}d|d6}|�||�|�t|�t��q�WxXtd7�D]L}xDtd�D]8}	t�d8d9�}
t|
|�}|�||
�|�t|�t��qW�qWx4d:d;d<d=d>dddfD]}|�td?|�d?��qlWxBtd�D]6}	t�d8d9�}
t|
�}|�||
�|�t|�t��q�Wd@}x|D]}
|�	t
tdA|
��q�WdS)BNrrMr�)rrrrCrrLr�rr^r�rMr�r�r�rBrr_r���i����ir
ij���ri8���ik���i����i���i���i���r�1r��3rN��r�r��i,iԡr�i�i��i��l!l!l�~!l�!r�l�!r�l`!i����l!i����l'�!i����lz+i����lv|oi����l,Gxi����i�i���iF�i��rLi���i'i���ll����lri{�)Zbriang@yrC)r9�items�roundr>r��typer0r1r�rzr�)r4Z	test_dict�offsetr�r|rgrn�expectrr;r
Zhuge_nZ
bad_exponentsr�rrr�
test_round�sx

zLongTest.test_roundcs�d0�fdd�	}dddddd	d
ddd
dddddddd�}||ddd�ddddddd
dddd
dd	ddddd�}||d dd�ddd
ddddd!d"d#d$�
}||ddd�ddd
dddd	dd"d%d$�
}||d dd��jtd&jd'ddd��jtd&jd'ddd��jtd&jd'd dd��jtd&jd'd dd��jtd(jd)ddd��jtd(jd)d dd���d*�d*d�d+���d'�d,d�d-���d*�d,d�d.���d(jd,ddd�d/���td'jd*d�dS)1NFcsrxl|��D]`\}}y ��|jt|�||d�|�Wq
tk
rh}ztd�|||��|�Wdd}~XYq
Xq
WdS)N)�signedz7failed to convert {0} with byteorder={1} and signed={2})r�r>�to_bytesr��	Exceptionrr�)�tests�	byteorderr�r�rn�err)r4rr�check>s
z%LongTest.test_to_bytes.<locals>.check��������s��s�s�s�s�ss�s��s��s�s�)rrr
i����i����i�����i���i�����i�i���i��i��i���bigT)r�s�s�ss�s��s�s��littles�s��s)
rrrr�r	r
i�i�i��isr
rr
rr�rLsss�����)F)rzrr�r>)r4r�tests1�tests2�tests3�tests4r)r4r�
test_to_bytes=s�
zLongTest.test_to_bytesc
s�d3�fdd�	}dddddddddd	d
ddd
dddddddd�}||ddd�dddddddddd	d
ddd
dddddddd�}||ddd�dddd
dddddddd�}||ddd�dddd
dddddddd�}||ddd�Gd d!�d!t�}��t|�d"d��|���|�d#d�d���t|jd"ddd��|���|jd#ddd�d���t|�d"d��|���|�d#d�d���t|jd"ddd��|���|jd#ddd�d���tjdddgddd�d���tjd$ddd�d���tjtd%�ddd�d���tjtd%�ddd�d���tjt�d&d%�ddd�d���tjtd%�ddd�d���t	tjdgd���t	tjdgd'���t	tjdgd(���t
tjd)d���t
tjd*d���t
tjdd���t
tjddd���t
|jd)d���t
|jd*d���t
|jdd���t
tjddd�Gd+d,�d,t�}|�d#d�}��t|�|���|d-�Gd.d/�d/t�}	|	�d#d�}��t|�|	���|d���t|d0d1�d2�dS)4NFcsnxh|��D]\\}}y��tj|||d�|�Wq
tk
rd}ztd�|||��|�Wdd}~XYq
Xq
WdS)N)r�z9failed to convert {0} with byteorder={1!r} and signed={2})r�r>r0�
from_bytesr�rr�)r�r�r�r�rnr�)r4rrr�s
z'LongTest.test_from_bytes.<locals>.checkrrr
i����i����i���rri���i���r	r
i�i���i��i��i��)r
rsrsrs��rrs�rs�s�s�s�ss�s�s��s�s�rT)r�)r
rsrsrs��rrs�rs�s�s�s�ss�s�s��s�s�rr�i�i)r
rrrrrss�s�s��s)r
rrrrrss�s�s��sc@seZdZdS)z'LongTest.test_from_bytes.<locals>.myintN)rmr�r�rrrr�myintsrrr)r	rrs��Bzbigzlittler\�c@seZdZdd�ZdS)z(LongTest.test_from_bytes.<locals>.myint2cSst�||d�S)Nr)r0�__new__)�clsr�rrrr&sz0LongTest.test_from_bytes.<locals>.myint2.__new__N)rmr�r�rrrrr�myint2%srrc@seZdZdd�ZdS)z(LongTest.test_from_bytes.<locals>.myint3cSs
d|_dS)N�bar)�foo)r4r�rrrr�.sz1LongTest.test_from_bytes.<locals>.myint3.__init__N)rmr�r�r�rrrr�myint3-srrZnoner)F)r0r�r�rr>�	bytearray�array�
memoryviewrzryr��getattr)
r4rrrrrrrr;rr)r4r�test_from_bytes�s�

zLongTest.test_from_bytescsJGdd�dt���fdd�td�D�}xtt|�D]}|�|d�q2WdS)Nc@seZdZddd�ZdS)z<LongTest.test_access_to_nonexistent_digit_0.<locals>.IntegerrcSst�||�}d|_|S)Nr)r0rr)rr�r4rrrr;szDLongTest.test_access_to_nonexistent_digit_0.<locals>.Integer.__new__N)r)rmr�r�rrrrr�Integer:sr"csg|]}�d��qS)rr)r	r;)r"rrr@sz?LongTest.test_access_to_nonexistent_digit_0.<locals>.<listcomp>i�r)r0r9�mapr>)r4Zintegersrr)r"r�"test_access_to_nonexistent_digit_06sz+LongTest.test_access_to_nonexistent_digit_0cCsHxBdD]:}x4dD],}|�t||>�t�|�t||?�t�qWqWdS)N)TF)rr)r>r�r0)r4r�rrrr�test_shift_boolDs

zLongTest.test_shift_boolN)T)0rmr�r�r8r<rArKrSrUrVrXrZrerorprr�r�rZrequires_IEEE_754r�r�r�r�r�r�r�r�r�r�r�r�r�Zcpython_onlyr�Z
bigmemtestrr�r�r�r�r�r�r�rr!r$r%rrrrr.ssT'
		9F\a"
\
	  "Jcr.�__main__)#Zunittestr�rrr1rr�int_info�bits_per_digitr/ZBASEr:rFrErYrTr9r;rGrrr�rr��min_expr#rr$r"rr-ZTestCaser.rm�mainrrrr�<module>sH .b