Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_cmath.cpython-34.pyo

�
g f�U�@sUddlmZmZmZddlmZmZddlZddlZddl	Z	ddlm
Z
mZmZm
Z
ddlZed�Zed�Zdd�d	d	gD�Zd
d�ed	fedfeefdefd	efd	efdefeefedfed	fed	fedfeefdefd	efd	efdefeefedfed	fgD�Zdd�eefedfed	fed	fedfeefeefdefd	efd	efdefeefgD�ZGd
d�dej�Zdd�ZedkrQe�ndS)�)�run_unittest�requires_IEEE_754�cpython_only)�parse_testfile�	test_fileN)�phase�polar�rect�pi�inf�nancCs2g|](}ddgD]}t||��qqS)gg�)�complex)�.0�x�y�r�4/opt/alt/python34/lib64/python3.4/test/test_cmath.py�
<listcomp>s	rgcCs%g|]\}}t||��qSr)r
)rrrrrrrs	gffffff@cCs%g|]\}}t||��qSr)r
)rrrrrrr"s	c@s�eZdZdd�ddddddd	d
ddd
dddddgD�Zejdd��ejdd��dd�Zdd�Zdd�Zdd�Zddd d!d"�Z	d#d$�Z
d%d&�Zd'd(�Zd)d*�Z
ed+d,��Zd-d.�Zd/d0�Zed1d2��Zd3d4�Zd5d6�Zed7d8��Zd9d:�Zd;d<�Zd=d>�Zd?d@�ZdAdB�ZeejejdC�dDkdE�dFdG���Z edHdI��Z!edJdK��Z"d S)L�
CMathTestscCsg|]}tt|��qSr)�getattr�cmath)rZfnamerrrr3s	zCMathTests.<listcomp>�acosZacosh�asinZasinh�atan�atanh�cos�cosh�exp�log�log10�sin�sinh�sqrt�tan�tanhcCstj|d�S)Ng�@yy�@)rr)rrrr�<lambda>8szCMathTests.<lambda>cCstjd|�S)Ng,@y;@y,@;�)rr)rrrrr%9scCstt�|_dS)N)�openr�test_values)�selfrrr�setUp;szCMathTests.setUpcCs|jj�dS)N)r'�close)r(rrr�tearDown>szCMathTests.tearDowncCs�d}tj|�s$tj|�rItj|�r�tj|�r�dSnQ||kr�|dkredStjd|�tjd|�kr�dS|d7}n|j|j||��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 identicalNgg�?z: zeros have different signs)�math�isnan�copysign�fail�format)r(rr�msgrrr�assertFloatIdenticalAs$
zCMathTests.assertFloatIdenticalcCs0|j|j|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)r2�real�imag)r(rrrrr�assertComplexIdenticalXsz!CMathTests.assertComplexIdenticalgV瞯�<g
NcCsHtj|�rAtj|�r"dS|j|p:dj|��ntj|�r�||kr`dS|j|p{dj||��n|r�|r�tjd|�tjd|�kr�|j|p�dj||��q�nyt||�}Wntk
rYn$X|t||t|��kr%dS|j|p@dj||��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}g�?z,zero has wrong sign: expected {!r}, got {!r}z({!r} and {!r} are not sufficiently close)	r,r-r/r0�isinfr.�abs�
OverflowError�max)r(�a�bZrel_err�abs_errr1Zabsolute_errorrrr�rAssertAlmostEqualbs*$
zCMathTests.rAssertAlmostEqualc	Csld}d}|jtj|ddddjtj|��|jtj|ddddjtj|��dS)NgiW�
�@g-DT�!	@Zplaces�	r1zcmath.pi is {}; should be {}zcmath.e is {}; should be {})�assertAlmostEqualrr
r0�e)r(Z
e_expectedZpi_expectedrrr�test_constants�szCMathTests.test_constantscs�d"�d#�dddddt�tg}Gdd	�d	t�}Gd
d�d�}Gdd
�d
t��G�fdd�dt�}G�fdd�d�}Gdd�dt�}Gdd�d�}Gdd�dt�}Gdd�d�}	G��fdd�dt�}
G��fdd�d�}G�fdd�dt�}G�fd d!�d!�}
x�|jD]�}|j||���|���|j||���|���|j||
��|���|j||��|���|j||��|���|j||
��|���|jt||��|jt||��|jt||��|jt||	��x@|D]8}|jt|||��|jt|||��q�W|j�||��|j�||��qjWdS)$Ng��z�@y7Ă?�?g]�ֆ@znot complex��g@c@s(eZdZdd�Zdd�ZdS)z.CMathTests.test_user_object.<locals>.MyComplexcSs
||_dS)N)�value)r(rDrrr�__init__�sz7CMathTests.test_user_object.<locals>.MyComplex.__init__cSs|jS)N)rD)r(rrr�__complex__�sz:CMathTests.test_user_object.<locals>.MyComplex.__complex__N)�__name__�
__module__�__qualname__rErFrrrr�	MyComplex�srJc@s(eZdZdd�Zdd�ZdS)z0CMathTests.test_user_object.<locals>.MyComplexOScSs
||_dS)N)rD)r(rDrrrrE�sz9CMathTests.test_user_object.<locals>.MyComplexOS.__init__cSs|jS)N)rD)r(rrrrF�sz<CMathTests.test_user_object.<locals>.MyComplexOS.__complex__N)rGrHrIrErFrrrr�MyComplexOS�srKc@seZdZdS)z2CMathTests.test_user_object.<locals>.SomeExceptionN)rGrHrIrrrr�
SomeException�srLcs"eZdZ�fdd�ZdS)z7CMathTests.test_user_object.<locals>.MyComplexExceptioncs
��dS)Nr)r()rLrrrF�szCCMathTests.test_user_object.<locals>.MyComplexException.__complex__N)rGrHrIrFr)rLrr�MyComplexException�srMcs"eZdZ�fdd�ZdS)z9CMathTests.test_user_object.<locals>.MyComplexExceptionOScs
��dS)Nr)r()rLrrrF�szECMathTests.test_user_object.<locals>.MyComplexExceptionOS.__complex__N)rGrHrIrFr)rLrr�MyComplexExceptionOS�srNc@seZdZdS)z;CMathTests.test_user_object.<locals>.NeitherComplexNorFloatN)rGrHrIrrrr�NeitherComplexNorFloat�srOc@seZdZdS)z=CMathTests.test_user_object.<locals>.NeitherComplexNorFloatOSN)rGrHrIrrrr�NeitherComplexNorFloatOS�srPc@s(eZdZdd�Zdd�ZdS)z*CMathTests.test_user_object.<locals>.MyIntcSsdS)N�r)r(rrr�__int__�sz2CMathTests.test_user_object.<locals>.MyInt.__int__cSsdS)NrQr)r(rrr�	__index__�sz4CMathTests.test_user_object.<locals>.MyInt.__index__N)rGrHrIrRrSrrrr�MyInt�srTc@s(eZdZdd�Zdd�ZdS)z,CMathTests.test_user_object.<locals>.MyIntOScSsdS)NrQr)r(rrrrR�sz4CMathTests.test_user_object.<locals>.MyIntOS.__int__cSsdS)NrQr)r(rrrrS�sz6CMathTests.test_user_object.<locals>.MyIntOS.__index__N)rGrHrIrRrSrrrr�MyIntOS�srUcs4eZdZ�fdd�Z�fdd�ZdS)z4CMathTests.test_user_object.<locals>.FloatAndComplexcs�S)Nr)r()�flt_argrr�	__float__�sz>CMathTests.test_user_object.<locals>.FloatAndComplex.__float__cs�S)Nr)r()�cx_argrrrF�sz@CMathTests.test_user_object.<locals>.FloatAndComplex.__complex__N)rGrHrIrWrFr)rXrVrr�FloatAndComplex�srYcs4eZdZ�fdd�Z�fdd�ZdS)z6CMathTests.test_user_object.<locals>.FloatAndComplexOScs�S)Nr)r()rVrrrW�sz@CMathTests.test_user_object.<locals>.FloatAndComplexOS.__float__cs�S)Nr)r()rXrrrF�szBCMathTests.test_user_object.<locals>.FloatAndComplexOS.__complex__N)rGrHrIrWrFr)rXrVrr�FloatAndComplexOS�srZcs"eZdZ�fdd�ZdS)z.CMathTests.test_user_object.<locals>.JustFloatcs�S)Nr)r()rVrrrW�sz8CMathTests.test_user_object.<locals>.JustFloat.__float__N)rGrHrIrWr)rVrr�	JustFloat�sr[cs"eZdZ�fdd�ZdS)z0CMathTests.test_user_object.<locals>.JustFloatOScs�S)Nr)r()rVrrrW�sz:CMathTests.test_user_object.<locals>.JustFloatOS.__float__N)rGrHrIrWr)rVrr�JustFloatOS�sr\y��z�@7Ă?�?g]�ֆ�)�object�NotImplemented�	Exception�test_functions�assertEqual�assertRaises�	TypeError)r(Z
non_complexesrJrKrMrNrOrPrTrUrYrZr[r\�fZbad_complexr)rLrXrVr�test_user_object�sB""
zCMathTests.test_user_objectcCs�xJ|jD]?}x6ddgD](}|j||�||j���qWq
WxD|jD]9}x0dddddgD]}|jt||�qsWqWWdS)NrQg@r:Zlong_string�0Z1j�)r`rarWrbrc)r(rd�argrrr�test_input_type�s*zCMathTests.test_input_typecCs�ddddddg}|dd�|D�d	d
dg}|d
gdd�|D�}d	g|}d	g|dd�|D�}i
|d
6|d6|d6|d6|d6|d6|d6|d6|d6|d6|d6|d6|d6}x�|j�D]s\}}tt|�}	tt|�}
xF|D]>}|
|�}|j|	|�|j�|jd	|j�q$Wq�WxldddgD][}
xR|D]J}tj||
�}|jtj||
�|j�|jd	|j�q�WqzWdS)Ng{�G�z�?g�������?g�������?g�?g�������?g�G�z��?cSsg|]
}|�qSrr)rrrrrrs	z6CMathTests.test_cmath_matches_math.<locals>.<listcomp>gg�?cSsg|]}d|�qS)g�?r)rrrrrrs	cSsg|]
}|�qSrr)rrrrrrs	rrrrrrrrr r!r"r#r$g@g$@g�)	�itemsrr,rr=r3rar4r)r(r'Z
unit_intervalZpositiveZnonnegativeZ	real_liner`�fn�valuesZfloat_fnZ
complex_fn�v�z�baserrr�test_cmath_matches_maths@



z"CMathTests.test_cmath_matches_mathcCsvdd�}dd�}xWtt�D]I\}}}}}}}	t||�}
t||�}|dkrs|}n$|dkr�|}ntt|�}d|	ks�d|	kr�y||
�}
Wntk
r�w%Yq�X|jd	j||||��nd
|	krOy||
�}
Wntk
r,w%YqOX|jdj||||��n||
�}
d|	kr�tt	|
j
�|
j�}
tt	|j
�|j�}nd
|	kr�t|
j
t	|
j��}
t|j
t	|j��}n|dkr�d}nd}dj|||||j
|j|
j
|
j�}|j|j
|
j
d|d|�|j|j|
jd|�q%WdS)NcSstj|j|j�S)zaWrapped version of rect that accepts a complex number instead of
            two float arguments.)rr	r3r4)rnrrr�rect_complex=sz5CMathTests.test_specific_values.<locals>.rect_complexcSstt|��S)zYWrapped version of polar that returns a complex number instead of
            two floats.)r
r)rnrrr�
polar_complexBsz6CMathTests.test_specific_values.<locals>.polar_complexr	rzdivide-by-zeroZinvalidz9ValueError not raised in test {}: {}(complex({!r}, {!r}))Zoverflowz<OverflowError not raised in test {}: {}(complex({!r}, {!r}))zignore-real-signzignore-imag-signrrgV瞯�<g
z�{}: {}(complex({!r}, {!r}))
Expected: complex({!r}, {!r})
Received: complex({!r}, {!r})
Received value insufficiently close to expected value.r<r1)zlogzlog10)
rrr
rr�
ValueErrorr/r0r8r7r3r4r=)r(rqrr�idrk�arZaiZerZei�flagsrh�expectedZfunctionZactualZreal_abs_errZ
error_messagerrr�test_specific_values;sV(		

	zCMathTests.test_specific_valuescs[��fdd�}|dd�|dd�|ddtf�|ddtdf�|dd
tdf�td�}|t|d�|df�|t|d�|tf�|td|�|tdf�|td
|�|tdf�|t||�|tdf�|t||�|tdf�|t||�|dtdf�|t||�|dtdf�td�}|t|d�||f�|td|�||f�|t||�||f�|t||�||f�|t||�||f�|t||�||f�|t||�||f�dS)Ncs@�|�}x-t||�D]\}}�j||�qWdS)N)�zipr=)rhrwZgotr@�g)�funcr(rr�check�sz%CMathTests.check_polar.<locals>.checkr�rB��?y�?rQy@g@r�rC�r)r}r})r~r}���y�����)r
�floatr
)r(r{r|rrr)r{r(r�check_polar�s.

 " "%&zCMathTests.check_polarcCs|jt�dS)N)r�r)r(rrr�
test_polar�szCMathTests.test_polarcs3ddlm��fdd�}|j|�dS)Nr)�	set_errnocs*�d�zt|�SWd�d�XdS)N�r)r)rn)r�rr�polar_with_errno_set�s
z9CMathTests.test_polar_errno.<locals>.polar_with_errno_set)Z	_testcapir�r�)r(r�r)r�r�test_polar_errno�szCMathTests.test_polar_errnocCs|jtd�d�|jtd�d�|jtd
�t�|jtd�t�|jtd�t�|jtd�td�|jtd�td�|jttdd��d�|jttdd��d�|jttdd��t�|jttdd��t�|jtttd��t�|jtttd��t�|jtttt��dt�|jttdt��td�|jttdt��td�|jttdt��td�|jttdt��td�|jtttt��td	�|jtttd��d�|jtttd��d�|jtttd��d�|jtttd��d�|jtttt��td	�|jttdt��td�|jttdt��td�|jttdt��td�|jttdt��td�|jtttt��dt�|jtttd��t�|jtttd��t�x*tD]"}|jtj	t|���q�WdS) Nrgg�?yY��n�y�?rQgffffff@g�?r�g�g�y�Y��n�g�y�Y��n��y��g�g�g�g�g�g�gffffff�g�gffffff�g�gffffff�g�g�g�g�gffffff�)
r?rr
rar
�INF�complex_nans�
assertTruer,r-)r(rnrrr�
test_phase�sB !!%%%%%%#####$  
zCMathTests.test_phasecCsx$tD]}|jt|�d�qWx$tD]}|jt|�t�q.W|jtttt��t�|jtj	tttd����|jtj	tttd����|jtj	tttd����|jtj	tttd����|jtttt��t�|jtttt��t�|jtj	ttdt����|jtj	ttdt����|jtj	ttdt����|jtj	ttdt����|jtttt��t�|jtj	tttt����dS)Nggffffff@gffffff�g�gffffff�g�)
�
complex_zerosrar7�complex_infinitiesr�r
�NANr�r,r-)r(rnrrr�test_abs�s"

 %%%% %%%%zCMathTests.test_abscCs |jtttdd��dS)Ng��U���)rbr8r7r
)r(rrr�test_abs_overflows�szCMathTests.test_abs_overflowscCsZd}t|j|d�|ks@t|j|d�|krV|j||f�ndS)NgH�����z>rrB)r7r3r4r/)r(r:r;Zepsrrr�assertCEqual�s:zCMathTests.assertCEqualcCs�|jtdd�d�|jtdd�d�|jtdt�d�|jtdtd�d	�|jtdtd�d�dS)NrrB��?rQ)rr)r�r��)r�r)rr���)rr�)r�r	r
)r(rrr�	test_rect�s
zCMathTests.test_rectcCs�td�ddddtd�td�g}x_|D]W}xN|D]F}t||�}|jtj|�tj|�o�tj|��qAWq4WdS)Nz-infgffffff@grrgffffff�g�)r�r
rarZisfiniter,)r(Z	real_valsrrrnrrr�
test_isfinite�s

zCMathTests.test_isfinitecCs�|jtjd��|jtjd��|jtjt��|jtjt��|jtjttd���|jtjtdt���|jtjttt���|jtjttt���|jtjttt���dS)NrBy�?r)�assertFalserr-r�r�r�r
)r(rrr�
test_isnanszCMathTests.test_isnancCs�|jtjd��|jtjd��|jtjt��|jtjt��|jtjttd���|jtjtdt���|jtjttt���|jtjttt���|jtjttt���dS)NrBy�?r)r�rr6r�r�r�r
)r(rrr�
test_isinfszCMathTests.test_isinf�TANH_PRESERVES_ZERO_SIGNrz,system tanh() function doesn't copy the signcCs.x'tD]}|jtj|�|�qWdS)N)r�r5rr$)r(rnrrr�testTanhSigns
zCMathTests.testTanhSigncCs.x'tD]}|jtj|�|�qWdS)N)r�r5rr)r(rnrrr�testAtanSign(s
zCMathTests.testAtanSigncCs.x'tD]}|jtj|�|�qWdS)N)r�r5rr)r(rnrrr�
testAtanhSign-s
zCMathTests.testAtanhSign)#rGrHrIr`�appendr)r+r2r5r=rArerirprrxr�r�rr�r�r�r�r�r�r�r�r��unittestZskipIf�	sysconfig�get_config_varr�r�r�rrrrr1sB	
1c0E)		rcCstt�dS)N)rrrrrr�	test_main3sr��__main__)Ztest.supportrrrZtest.test_mathrrr�rr,rrr	r
r�r�r�r�r�r�r�ZTestCaserr�rGrrrr�<module>s`"						








	


			


		��