Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_cmath.cpython-39.opt-1.pyc

a

XC?hD`�@s�ddlmZmZddlmZmZddlmZddlZddlZddl	Z	ddlm
Z
mZmZm
Z
ddlZddlZed�Zed�Zdd�d	D�Zd
d�edfedfeefdefdefd
efdefeefedfedfed
fedfeefdefd
efdefdefeefedfed
ffD�Zdd�eefedfed
fedfedfeefeefdefd
efdefdefeeffD�ZGdd�dej�ZGdd�dej�Zedk�r�e��dS)�)�requires_IEEE_754�cpython_only)�parse_testfile�	test_fileN)�phase�polar�rect�pi�inf�nancCs g|]}dD]}t||��qqS)������complex��.0�x�y�r�4/opt/alt/python39/lib64/python3.9/test/test_cmath.py�
<listcomp>�rrcCsg|]\}}t||��qSrrrrrrrrr
�ffffff@r�ffffff�cCsg|]\}}t||��qSrrrrrrr%rc@seZdZdd�dD�Ze�dd��e�dd��dd�Zd	d
�Zdd�Zd
d�Zd<dd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zedd��Zd d!�Zd"d#�Zed$d%��Zd&d'�Zd(d)�Zed*d+��Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zed6d7��Zed8d9��Zed:d;��ZdS)=�
CMathTestscCsg|]}tt|��qSr)�getattr�cmath)rZfnamerrrr6rzCMathTests.<listcomp>)�acosZacosh�asinZasinh�atan�atanh�cos�cosh�exp�log�log10�sin�sinh�sqrt�tan�tanhcCst�|d�S)Ny�@�rr%�rrrr�<lambda>;rzCMathTests.<lambda>cCst�d|�S)Ny,@;�r,r-rrrr.<rcCstt�|_dS�N)�openr�test_values��selfrrr�setUp>szCMathTests.setUpcCs|j��dSr/)r1�closer2rrr�tearDownAszCMathTests.tearDowncCs�d}t�|�st�|�r2t�|�rjt�|�rjdSn8||krj|dkrFdSt�d|�t�d|�krbdS|d7}|�|�||��dS)a#Fail unless floats x and y are identical, in the sense that:
        (1) both x and y are nans, or
        (2) both x and y are infinities, with the same sign, or
        (3) both x and y are zeros, with the same sign, or
        (4) x and y are both finite and nonzero, and x == y

        z&floats {!r} and {!r} are not identicalNr
��?z: zeros have different signs)�math�isnan�copysign�fail�format)r3rr�msgrrr�assertFloatIdenticalDszCMathTests.assertFloatIdenticalcCs$|�|j|j�|�|j|j�dS)z�Fail unless complex numbers x and y have equal values and signs.

        In particular, if x and y both have real (or imaginary) part
        zero, but the zeros have different signs, this test will fail.

        N)r>�real�imag)r3rrrrr�assertComplexIdentical[sz!CMathTests.assertComplexIdentical�V瞯�<�
NcCs�t�|�r,t�|�rdS|�|p(d�|��t�|�rX||krBdS|�|pTd�||��|s�|s�t�d|�t�d|�kr�|�|p�d�||��zt||�}Wnty�Yn0|t||t|��kr�dS|�|p�d�||��dS)a�Fail if the two floating-point numbers are not almost equal.

        Determine whether floating-point values a and b are equal to within
        a (small) rounding error.  The default values for rel_err and
        abs_err are chosen to be suitable for platforms where a float is
        represented by an IEEE 754 double.  They allow an error of between
        9 and 19 ulps.
        Nz{!r} should be nanz>finite result where infinity expected: expected {!r}, got {!r}r7z,zero has wrong sign: expected {!r}, got {!r}z({!r} and {!r} are not sufficiently close)	r8r9r;r<�isinfr:�abs�
OverflowError�max)r3�a�bZrel_err�abs_errr=Zabsolute_errorrrr�rAssertAlmostEquales0


��
�zCMathTests.rAssertAlmostEqualcCsHd}d}|jtj|dd�tj|�d�|jtj|dd�tj|�d�dS)NgiW�
�@g-DT�!	@�	zcmath.pi is {}; should be {})Zplacesr=zcmath.e is {}; should be {})�assertAlmostEqualrr	r<�e)r3Z
e_expectedZpi_expectedrrr�test_constants�s��zCMathTests.test_constantscCs�|�tjjtj�|�tjjd�|�tjjd�|�tjjtj�|�t�tj	j��|�tj	jd�|�tj
jd�|�t�tj
j��|�ttj�d�|�ttj�d�|�ttj	�d�|�ttj
�d�dS)Nr
r
�infjr�nanj)�assertEqualrr
r?r8r@rP�
assertTruer9rrQ�reprr2rrr�test_infinity_and_nan_constants�sz*CMathTests.test_infinity_and_nan_constantscs2d�d�dddddt�tg}Gdd�dt�}Gd	d
�d
�}Gdd�dt��G�fd
d�dt�}G�fdd�d�}Gdd�dt�}Gdd�d�}Gdd�d�}Gdd�d�}	G��fdd�dt�}
G��fdd�d�}G�fdd�dt�}G�fdd �d �}
|jD�]*}|�||���|���|�||���|���|�||
��|���|�||��|���|�||��|���|�||
��|���|�||��|t|����|�t||��|�t||	��|�t||��|D]*}|�t|||��|�t|||���q�|��||��|��||���qdS)!Ny��z�@7Ă?�?g]�ֆ�znot complex���@c@seZdZdd�Zdd�ZdS)z.CMathTests.test_user_object.<locals>.MyComplexcSs
||_dSr/��value�r3rZrrr�__init__�sz7CMathTests.test_user_object.<locals>.MyComplex.__init__cSs|jSr/rYr2rrr�__complex__�sz:CMathTests.test_user_object.<locals>.MyComplex.__complex__N��__name__�
__module__�__qualname__r\r]rrrr�	MyComplex�srbc@seZdZdd�Zdd�ZdS)z0CMathTests.test_user_object.<locals>.MyComplexOScSs
||_dSr/rYr[rrrr\�sz9CMathTests.test_user_object.<locals>.MyComplexOS.__init__cSs|jSr/rYr2rrrr]�sz<CMathTests.test_user_object.<locals>.MyComplexOS.__complex__Nr^rrrr�MyComplexOS�srcc@seZdZdS)z2CMathTests.test_user_object.<locals>.SomeExceptionN�r_r`rarrrr�
SomeException�srecseZdZ�fdd�ZdS)z7CMathTests.test_user_object.<locals>.MyComplexExceptioncs��dSr/rr2�rerrr]�szCCMathTests.test_user_object.<locals>.MyComplexException.__complex__N�r_r`rar]rrfrr�MyComplexException�srhcseZdZ�fdd�ZdS)z9CMathTests.test_user_object.<locals>.MyComplexExceptionOScs��dSr/rr2rfrrr]�szECMathTests.test_user_object.<locals>.MyComplexExceptionOS.__complex__Nrgrrfrr�MyComplexExceptionOS�sric@seZdZdS)z;CMathTests.test_user_object.<locals>.NeitherComplexNorFloatNrdrrrr�NeitherComplexNorFloat�srjc@seZdZdS)z=CMathTests.test_user_object.<locals>.NeitherComplexNorFloatOSNrdrrrr�NeitherComplexNorFloatOS�srkc@seZdZdd�Zdd�ZdS)z*CMathTests.test_user_object.<locals>.IndexcSsdS�N�rr2rrr�__int__�rz2CMathTests.test_user_object.<locals>.Index.__int__cSsdSrlrr2rrr�	__index__�rz4CMathTests.test_user_object.<locals>.Index.__index__N)r_r`rarnrorrrr�Index�srpc@seZdZdd�ZdS)z*CMathTests.test_user_object.<locals>.MyIntcSsdSrlrr2rrrrn�rz2CMathTests.test_user_object.<locals>.MyInt.__int__N)r_r`rarnrrrr�MyInt�srqcs$eZdZ�fdd�Z�fdd�ZdS)z4CMathTests.test_user_object.<locals>.FloatAndComplexcs�Sr/rr2��flt_argrr�	__float__�sz>CMathTests.test_user_object.<locals>.FloatAndComplex.__float__cs�Sr/rr2��cx_argrrr]�sz@CMathTests.test_user_object.<locals>.FloatAndComplex.__complex__N�r_r`rartr]r�rvrsrr�FloatAndComplex�srycs$eZdZ�fdd�Z�fdd�ZdS)z6CMathTests.test_user_object.<locals>.FloatAndComplexOScs�Sr/rr2rrrrrt�sz@CMathTests.test_user_object.<locals>.FloatAndComplexOS.__float__cs�Sr/rr2rurrr]�szBCMathTests.test_user_object.<locals>.FloatAndComplexOS.__complex__Nrwrrxrr�FloatAndComplexOS�srzcseZdZ�fdd�ZdS)z.CMathTests.test_user_object.<locals>.JustFloatcs�Sr/rr2rrrrrt�sz8CMathTests.test_user_object.<locals>.JustFloat.__float__N�r_r`rartrrrrr�	JustFloat�sr|cseZdZ�fdd�ZdS)z0CMathTests.test_user_object.<locals>.JustFloatOScs�Sr/rr2rrrrrt�sz:CMathTests.test_user_object.<locals>.JustFloatOS.__float__Nr{rrrrr�JustFloatOS�sr})�object�NotImplemented�	Exception�test_functionsrR�int�assertRaises�	TypeError)r3Z
non_complexesrbrcrhrirjrkrprqryrzr|r}�fZbad_complexr)rervrsr�test_user_object�sD
�zCMathTests.test_user_objectcCsV|jD]&}dD]}|�||�||����qq|jD]}dD]}|�t||�q<q4dS)N)rmrX)rHZlong_string�0Z1j�)r�rRrtr�r�)r3r��argrrr�test_input_types

zCMathTests.test_input_typecCsgd�}|dd�|D�gd�}|dgdd�|D�}dg|}dg|dd�|D�}|||||||||||||d	�
}|��D]N\}}tt|�}	tt|�}
|D],}|
|�}|�|	|�|j�|�d|j�q�q�d
D]>}
|D]4}t�||
�}|�t�||
�|j�|�d|j�q�q�dS)N)g{�G�z�?g�������?g�������?��?g�������?g�G�z��?cSsg|]
}|�qSrr�rrrrrr&rz6CMathTests.test_cmath_matches_math.<locals>.<listcomp>)r
r7��r7cSsg|]}d|�qS)r7rr�rrrr*rr
cSsg|]
}|�qSrrr�rrrr.r)
rrr r"r#r$r%r&r'r(r)r*r+)r�rXg$@)	�itemsrr8rrKr?rRr@r%)r3r1Z
unit_intervalZpositiveZnonnegativeZ	real_liner��fn�valuesZfloat_fnZ
complex_fn�v�z�baserrr�test_cmath_matches_mathsB�
�

z"CMathTests.test_cmath_matches_mathcCs(dh}d}tjdkrLt��d}zttt|�d���}WntyJYn0dd�}dd�}tt	�D�]�\}}}}	}
}}t
||	�}
t
|
|�}|dur�|d	kr�||vr�qd|d
kr�|}n|dkr�|}n
tt|�}d|vs�d
|v�rz||
�}Wnt�yYqdYn0|�
d�||||	��d|v�r`z||
�}Wnt�yHYqdYn0|�
d�||||	��||
�}d|v�r�t
t|j�|j�}t
t|j�|j�}d|v�r�t
|jt|j��}t
|jt|j��}|dv�r�d}nd}d�||||	|j|j|j|j�}|j|j|j||d�|j|j|j|d�qddS)NZtan0064�darwinr�.cSst�|j|j�S)zaWrapped version of rect that accepts a complex number instead of
            two float arguments.)rrr?r@�r�rrr�rect_complex\sz5CMathTests.test_specific_values.<locals>.rect_complexcSstt|��S)zYWrapped version of polar that returns a complex number instead of
            two floats.)rrr�rrr�
polar_complexasz6CMathTests.test_specific_values.<locals>.polar_complex)�
rWrrzdivide-by-zeroZinvalidz9ValueError not raised in test {}: {}(complex({!r}, {!r}))Zoverflowz<OverflowError not raised in test {}: {}(complex({!r}, {!r}))zignore-real-signzignore-imag-sign)r%r&rBrCz�{}: {}(complex({!r}, {!r}))
Expected: complex({!r}, {!r})
Received: complex({!r}, {!r})
Received value insufficiently close to expected value.)rJr=)r=)�sys�platformZmac_ver�tuple�mapr��split�
ValueErrorrrrrrr;r<rFrEr?r@rK)r3Z
SKIP_ON_TIGERZosx_versionZversion_txtr�r��idr�ZarZaiZerZei�flagsr��expectedZfunctionZactualZreal_abs_errZ
error_messagerrr�test_specific_valuesNsx




�

�


����zCMathTests.test_specific_valuescs���fdd�}|dd�|dd�|ddtf�|d	dtd
f�|ddtd
f�td
�}|t|d�|df�|t|d�|tf�|td|�|td
f�|td|�|td
f�|t||�|tdf�|t||�|tdf�|t||�|dtdf�|t||�|dtdf�td�}|t|d�||f�|td|�||f�|t||�||f�|t||�||f�|t||�||f�|t||�||f�|t||�||f�dS)Ncs,�|�}t||�D]\}}��||�qdSr/)�ziprK)r�r�ZgotrN�g��funcr3rr�check�sz%CMathTests.check_polar.<locals>.checkr)r
r
rV)r7r
���r7��?rmy��g@r
r
�rW����r)r	�floatr)r3r�r�r
rrr�r�check_polar�s.

 zCMathTests.check_polarcCs|�t�dSr/)r�rr2rrr�
test_polar�szCMathTests.test_polarcs&ddlm��fdd�}|�|�dS)Nr��	set_errnocs*�d�zt|�W�d�S�d�0dS)N�r)rr�r�rr�polar_with_errno_set�s�z9CMathTests.test_polar_errno.<locals>.polar_with_errno_set)Z	_testcapir�r�)r3r�rr�r�test_polar_errno�szCMathTests.test_polar_errnocCs|�td�d�|�td�d�|�td�t�|�td�t�|�td�t�|�td�td�|�td	�td�|�ttdd��d�|�ttdd
��d
�|�ttd
d��t�|�ttd
d
��t�|�tttd
��t�|�tttd��t�|�tttt��dt�|�ttdt��td�|�ttd
t��td�|�ttdt��td�|�ttd
t��td�|�tttt��td�|�tttd��d
�|�tttd
��d
�|�tttd��d�|�tttd
��d�|�tttt��td�|�ttd
t��td�|�ttdt��td�|�ttd
t��td�|�ttdt��td�|�tttt��dt�|�tttd
��t�|�tttd��t�tD]}|�t�	t|����q�dS)Nrr
r7r�y�Y��n�y�Y��n��r�rmy��rrg�rr�g�?)
rMrr	rRr�INF�complex_nansrSr8r9�r3r�rrr�
test_phase�sBzCMathTests.test_phasecCs~tD]}|�t|�d�qtD]}|�t|�t�q|�tttt��t�|�t�	tttd����|�t�	tttd����|�t�	tttd����|�t�	tttd����|�tttt��t�|�tttt��t�|�t�	ttdt����|�t�	ttdt����|�t�	ttdt����|�t�	ttdt����|�tttt��t�|�t�	tttt����dS)Nr
rrr)
�
complex_zerosrRrE�complex_infinitiesr�r�NANrSr8r9r�rrr�test_abs�s"zCMathTests.test_abscCs|�tttdd��dS)Ng��U���)r�rFrErr2rrr�test_abs_overflowsszCMathTests.test_abs_overflowscCsBd}t|j|d�|ks0t|j|d�|kr>|�||f�dS)NgH�����z>rrV)rEr?r@r;)r3rHrIZepsrrr�assertCEquals,zCMathTests.assertCEqualcCsj|�tdd�d�|�tdd�d�|�tdt�d�|�tdtd�d�|�tdtd�d�dS)	Nr)rrrV)r7r)r�rrm)rr7)rr�)r�rr	r2rrr�	test_rects
zCMathTests.test_rectcCsbtd�ddddtd�td�g}|D]:}|D]0}t||�}|�t�|�t�|�oVt�|��q*q"dS)Nz-infrrr
rr
r)r�rrRrZisfiniter8)r3Z	real_valsrrr�rrr�
test_isfinite#s
�
�zCMathTests.test_isfinitecCs�|�t�d��|�t�d��|�t�t��|�t�t��|�t�ttd���|�t�tdt���|�t�ttt���|�t�ttt���|�t�ttt���dS�NrVr�r)�assertFalserr9r�rSr�rr2rrr�
test_isnan,szCMathTests.test_isnancCs�|�t�d��|�t�d��|�t�t��|�t�t��|�t�ttd���|�t�tdt���|�t�ttt���|�t�ttt���|�t�ttt���dSr�)r�rrDr�rSr�rr2rrr�
test_isinf7szCMathTests.test_isinfcCs tD]}|�t�|�|�qdSr/)r�rArr+r�rrr�testTanhSignBszCMathTests.testTanhSigncCs tD]}|�t�|�|�qdSr/)r�rArr r�rrr�testAtanSignKszCMathTests.testAtanSigncCs tD]}|�t�|�|�qdSr/)r�rArr!r�rrr�
testAtanhSignPszCMathTests.testAtanhSign)rBrCN) r_r`rar��appendr4r6r>rArKrOrUr�r�r�rr�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�rrrrr4sH
�
2b0
V
)
	

rc@s*eZdZejZdd�Zdd�Zdd�ZdS)�IsCloseTestscCs�|�t�� |jdddd�Wd�n1s00Y|�t�� |jdddd�Wd�n1sj0Y|�t��"|jddddd�Wd�n1s�0YdS)Nr���rel_tol��abs_tol)r�r�)r�r��iscloser2rrr�test_reject_complex_tolerancesYs..z+IsCloseTests.test_reject_complex_tolerancescCs(gd�}|j|dd�|j|dd�dS)N))��?�?y��?�?)r�y�?��?)y��?y���?)y�?�y�?������g�-���q=r�g�vIh�%<=)�assertAllClose�assertAllNotClose)r3Zcomplex_examplesrrr�test_complex_valuescsz IsCloseTests.test_complex_valuescCsHgd�}|j|dd�|j|dd�|jdddd�|jdddd�dS)	N))y����MbP?r)���MbP?r)�����MbP?����MbP?r)y����MbP�����MbP?r)�����MbP?����MbP�r)y����MbP�����MbP�rg�~j�t�X?r�g����Mb@?r�r�g����Mb`?r�)r�r�Z
assertIsCloseZassertIsNotClose)r3Znear_zero_examplesrrr�test_complex_near_zerons
z#IsCloseTests.test_complex_near_zeroN)r_r`rarr�r�r�r�rrrrr�Vs
r��__main__)Ztest.supportrrZtest.test_mathrrZ	test_mathZunittestrr8rrrr	r�r�r�r�r�r�r�r�ZTestCaserr�r_�mainrrrr�<module>sl
��&)