a zeŀ@sddlZddlZddlmZddlmZmZddlmZddlm Z m Z m Z ddl Z e dZe dZGdd d ejZed kredS) N)support)VALID_UNDERSCORE_LITERALSINVALID_UNDERSCORE_LITERALS)random)atan2isnancopysigninfnanc@s$eZdZddZd?ddZddZd@dd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zejd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zejd,d-Zd.d/Zd0d1Zd2d3Zejd4d5Zejd6d7Zejd8d9Z ejd:d;Z!dS)A ComplexTestcCst|trdt|tr>tj||j|jtj||j|jqtj||j|tj||jdn@t|trtj|||jtj|d|jntj|||dS)N) isinstancecomplexunittestTestCaseassertAlmostEqualrealimag)selfabrE/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_complex.pyrs   zComplexTest.assertAlmostEqual& .>cCs`t|t|kr||}}|dkr.t||kS|dkrBt||kS|t||||kdSNr)abs assertTruerxyZepsrrrassertCloseAbs s   zComplexTest.assertCloseAbscCstd}t|st|r*t|r^t|r^dSn4||kr^|dkr>dStd|td|krVdS|d7}||||dS)Nz&floats {!r} and {!r} are not identicalr ?z: zeros have different signs)rrfailformat)rrrmsgrrrassertFloatsAreIdentical,sz$ComplexTest.assertFloatsAreIdenticalcCs(||j|j|||j|j|dSN)r rrrrrr assertCloseCszComplexTest.assertClosecCsp||}|dkr:||}|||||}||||dkrl||}|||||}|||dSr)r' __truediv__)rrrzqrrr check_divHs     zComplexTest.check_divcs8ddtddDfddD}|D]}|D]}|||q2q*|tddd|tdddtd D]$}|ttttttqr|ttjd d |ttd d | td d d|ttjd d dt ft dft t ffD]<\}}tddt||}| t |j | t |jqdS)NcSsg|] }t|qSr)float).0irrr Wz,ComplexTest.test_truediv..cs g|]}D]}t||q qSr)rr-rrZ simple_realrrr/Xr0gZbti?N~hd??yZbti?@y?r)ranger+rr assertRaisesZeroDivisionErrorr( OverflowErrorpowrNANrrrr)rZsimple_complexrrr.Z denom_realZ denom_imagr)rr4r test_truedivVs&  zComplexTest.test_truedivcCs(|ttjdd|ttjdddS)N@y?r9)r< TypeErrorr __floordiv__rrrr test_floordivrszComplexTest.test_floordivcCs|tddd>d|tddt|tddd|tddd|tddd|tdddtddD]p}|d}|t|d |d|t|d |d|tt|||d|tt|||dq|tddt|tddt|tddt|t ddt| t t j dd| t t jdd| t t jdd| t t jdd|t ddd|t ddd|t ddd|t ddddS) Nr8i'FTy@@r7gY@r9)assertIsr__eq____lt__NotImplemented__ne__r;__le____gt____ge__r<rCoperatorltlegtgeeqne)rr.frrrtest_richcomparevs0zComplexTest.test_richcomparecsdfdd }tddD]R}d|}d||d|tddfd d |d|tddd d t|q|d td ddd dS)Nr csR|D]H}||}t||}t||||t|||| qdSr&)rrHrIrL)nZdeltasZis_equalrdeltar.r)rErrchecks  z6ComplexTest.test_richcompare_boundaries..checkrG 4ecs |dkSrrrZ)multrrr0z9ComplexTest.test_richcompare_boundaries..cSsdS)NFrr`rrrrbr0lircSsdS)NTrr`rrrrbr0)r )r;r,)rr[r.r?r)rarrtest_richcompare_boundariess "z'ComplexTest.test_richcompare_boundariescCs4|tdjd|tdd|tdjddS)Nr8r9cSsddS)Np= ף @Q@rrrrrrrbr0z&ComplexTest.test_mod..y333333@)r<rC__mod__rErrrtest_modszComplexTest.test_modcCs$|ttdd|ttdddS)Nr8r5r9)r<rCdivmodrErrr test_divmodszComplexTest.test_divmodc Cs(|tddd|tddd|ttdd|tddd|tdd d |ttdddd }||dd ||ddd |d d |d d z d|WntyYn 0|d z ddWntyYn 0|d ||d|d||d|d||d|d|d d d}|tt||dtjtjd tjd tj tj d tj d f}|D]}|D]}|j ||d^t ||}z ||Wnt yYn0z ||Wnt yYn0Wdn1s0YqqdS)Nr8r9r!r:r ?yrGrdr5z,should fail 0.0 to negative or complex powery@iiffffff@ffffff@rrr) rr?r<r= ValueError assertEqualr"sysmaxsizesubTestrr>)rrrvaluesrrcrrrtest_powsT            zComplexTest.test_powc Cstddtddtdtttdg}gd}|D]}|D]}|j||dz ||}Wntynd }Yn0z|t|}Wntyd }Yn0z|t|}Wntyd }Yn0|t|t||t|t|Wdq81s0Yq8q0dS) Ng@g(@g\nTg;%_nTgr ) ir1rjrrGr^)valueexponentZoverflow)rINFrtr>r,rqstr)rruZ exponentsr}r~Zint_powZ float_powZ complex_powrrr%test_pow_with_small_integer_exponentss.       z1ComplexTest.test_pow_with_small_integer_exponentscCs@tdD] }|ttdtdq|tdd dS)Nr7gư>r )r;rrr)rr.rrrtest_boolcontexts zComplexTest.test_boolcontextcCs|tddddS)Ng333333@g#@y333333@#)r'r conjugaterErrrtest_conjugateszComplexTest.test_conjugatec s0Gddd}Gdddt}|t|dd|t|dd|tt|d|tt|d|tti|tt|d|tt|d|tdd|td d |td d |td d |td d |tdd d|tdd d|tdd d|tdd d|tdd d|tdd d|td d d|td d d|td d d|td d |tdd |tdd|tdd|td dd |tddd |tddd|tddd|tddd|tddd|tddd|tddd|tdd|tdd|td|tdd|tdd|tdd|tdd |td!d"|td#d$|td%d&|td'd"|td(d|td)d|td*d|td+d,|td-d|td.d|td/dGd0d1d1t}|t|d2d2|td3d4d5d6|td6d7d6|td6d4d5d8|tdd9d5d:d;d<}||td dj|d||td d=j|d=||tdd j|d||td=d j|d=d"}|t||u~|ttdd|ttdd|t td>|tt d?|tt d?|tt d?|t td@|ttd| tdAtd|t tdB|t tdC|ttddD|ttddE|ttddD|t tdF|t tdG|t tdH|t tdI|t tdJ|t tdK|t tdL|t tdM|t tdN|t tdO|t tdP|t tdQ| tdRtddSid| tdTtdddSi|t tdU|t tdV|t tdW|t tdXt|tdYd2|t tdZGd[d\d\tGfd]d^d^}|t|Gd_d`d`}|t|dadE|t|db|dcd5d6|tt|dGdddede}|t|dEdf|tdg|dEdh|tt|dSdi|ttdg|dSdiGdjdkdk} |tt| |ttdg| Gdldmdmt} Gdndodot} Gdpd1d1t}|t| ddq|t$|t| ddrWdn1s0Y|tt|ddS)sNc@seZdZddZddZdS)z(ComplexTest.test_constructor..OScSs ||_dSr&r}rr}rrr__init__ r0z1ComplexTest.test_constructor..OS.__init__cSs|jSr&rrErrr __complex__ r0z4ComplexTest.test_constructor..OS.__complex__N__name__ __module__ __qualname__rrrrrrOS src@seZdZddZddZdS)z(ComplexTest.test_constructor..NScSs ||_dSr&rrrrrrr0z1ComplexTest.test_constructor..NS.__init__cSs|jSr&rrErrrrr0z4ComplexTest.test_constructor..NS.__complex__NrrrrrNSsry?$@g?rGz1+10jr\y$@g$@r!yQ @gQ @i:ys@r9r ryQ @yQ 1r51jriz-1rjz+1z(1+2j)?@z (1.3+2.2j)y?@z3.14+1JyQ @?z ( +3.14-6J )yQ @z ( +3.14-J )yQ @z ( +3.14+j )Jz( j )z+Jz( -j)yz1e-500z-1e-500jz-1e-500+1e-500jc@s eZdZdS).ComplexTest.test_constructor..complex2Nrrrrrrrcomplex2Fr0rr8roy1@7@)ry1@G@y@@y@cSs t|dS)N)r)rrrr split_zerosPsz1ComplexTest.test_constructor..split_zerosz1+1jjy@@znot 'NoneType'z392*z1+z1+1j+1jz--z(1+2jz1+2j)z1+(2j)z (1+2j)123rz1j+2Z1e1ejz1e++1ejz)1+2j(z7first argument must be a string or a number, not 'dict'r^z,second argument must be a number, not 'dict'z1..1jz1.11.1jz1e1.1jA11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111u ( 1+1j ) uこんにちはc@s eZdZdS)z-ComplexTest.test_constructor..EvilExcNrrrrrEvilExcsrcseZdZfddZdS)z1ComplexTest.test_constructor..evilcomplexcsdSr&rrErrrrsz=ComplexTest.test_constructor..evilcomplex.__complex__Nrrrrrrrr evilcomplexsrc@seZdZddZddZdS)z,ComplexTest.test_constructor..float2cSs ||_dSr&rrrrrrsz5ComplexTest.test_constructor..float2.__init__cSs|jSr&rrErrr __float__sz6ComplexTest.test_constructor..float2.__float__N)rrrrrrrrrfloat2srgE@g1@g7@c@seZdZddZddZdS)z-ComplexTest.test_constructor..MyIndexcSs ||_dSr&rrrrrrsz6ComplexTest.test_constructor..MyIndex.__init__cSs|jSr&rrErrr __index__sz7ComplexTest.test_constructor..MyIndex.__index__N)rrrrrrrrrMyIndexsryE@{y^@E@ic@seZdZddZdS)z+ComplexTest.test_constructor..MyIntcSsdS)NrrrErrr__int__sz3ComplexTest.test_constructor..MyInt.__int__N)rrrrrrrrMyIntsrc@seZdZddZdS)z.ComplexTest.test_constructor..complex0cSsdS)NE@rrErrrrsz:ComplexTest.test_constructor..complex0.__complex__Nrrrrrcomplex0src@seZdZdddZddZdS)z.ComplexTest.test_constructor..complex1r9cSst|d|S)Nr^)r__new__rrrrrsz6ComplexTest.test_constructor..complex1.__new__cSs|Sr&rrErrrrsz:ComplexTest.test_constructor..complex1.__complex__N)r9)rrrrrrrrrcomplex1s rc@seZdZddZdS)rcSsdSr&rrErrrrsz:ComplexTest.test_constructor..complex2.__complex__Nrrrrrrsr@)objectrqrr<rCrrrrrpintr,ZassertRaisesRegextype Exceptionr>Z assertWarnsDeprecationWarning) rrrrrrvrrrrrrrrrtest_constructor s   4zComplexTest.test_constructorc CsDGdddt}ddtt tfD]}ddtt tfD]}|j||dt||}||j|||j||||}|t||||j|||j|t|||}|t|t||j|||j||t||}|t||||j|||j|Wdq61s20Yq6q dS)Nc@s eZdZdS)z>ComplexTest.test_constructor_special_numbers..complex2Nrrrrrrsrr r)rr) rrr@rtr%rrrHr)rrrrr)rrr test_constructor_special_numberss&  z,ComplexTest.test_constructor_special_numbersc stD]JtfdddDs|tt|ttddqtD]2dvrbqTtfdddDsT|ttqTdS)Nc3s|]}|vVqdSr&rr-ZchZlitrr r0z/ComplexTest.test_underscores..ZxXoObB_r)Z0_7Z09_99c3s|]}|vVqdSr&rrrrrrr0) ranyrqrevalreplacerr<rprErrrtest_underscoresszComplexTest.test_underscorescCsPtddD]@}|t|tt|d|d}|t|tt|dq dS)Nrmr@r )r;rqhashr)rrrrr test_hashszComplexTest.test_hashcCsFddtddD}|D](}||jd|jddt|qdS)NcSs.g|]&}tddD]}t|d|dqqS) rg@)r;rr3rrrr/r0z(ComplexTest.test_abs..rrr^g?)r;rrrr)rZnumsnumrrrtest_absszComplexTest.test_abscCs,|jfdd}|dd|dd|dd|jd |td td |td t d |ttd d|tt td|ttd d|td td|tttd|tdtd|tdt d|tdtd|dttd|dttd|dttd|dttddS)NcSs |t|||t||dSr&reprrvZexpectedtest_fnrrrtestsz'ComplexTest.test_repr_str..testy?@z(1+6j)y?z(1-6j)yz(-1+-0j))rr!z(1+infj)z(1-infj)rGz(inf+1j)z (-inf+infj)z(nan+1j)z(1+nanj)z (nan+nanj)rinfjz-infjnanjyy@)rqZassertNotEqualrrr@rrrrrr test_repr_strs$  zComplexTest.test_repr_strcCs|jfdd}|tddd|tddd|tddd |tddd |tddd |tddd |tddd |tddddS)NcSs |t|||t||dSr&rrrrrrsz5ComplexTest.test_negative_zero_repr_str..testr r!rrz(-0+1j)rz-1jz(-0-1j)Z0jz-0jz(-0+0j)z(-0-0j))rqrrrrrtest_negative_zero_repr_strsz'ComplexTest.test_negative_zero_repr_strcCs|dddS)Ny)rqrErrrtest_neg%szComplexTest.test_negc Csd}d}d}zlttjd}t|||d|ttjd}||d||fW|durl|jsl|ttjn$|dur|js|ttj0dS)Nrdrnw)filerz%s %s ) openrZTESTFNprintcloserqreadclosedunlink)rrrforrr test_file(s  zComplexTest.test_filecCsx|dd|dd|dd|dd|td td tf|ttd td fdS) Nr)r!@y?)r!gr)r r)r rrr )rq__getnewargs__rrrErrrtest_getnewargs8s zComplexTest.test_getnewargscCs@d\}}|t|jdtdd|t|jdtdddS)N)r9rrr r)rqrr)rz1z2rrrtest_plus_minus_0j@szComplexTest.test_plus_minus_0jcCsfd}d}d}||jd||jd||jd||jd||jd||jt dS)Nryyrg)r%rrr)rZz0rrrrrtest_negated_imaginary_literalGsz*ComplexTest.test_negated_imaginary_literalcCsJ|tdttd|tdtdt |tdtt tdS)NZ1e500r z-1e500jz-1e500+1.8e308j)rqrrrErrr test_overflowWszComplexTest.test_overflowc Csdddddddttg }|dd|D7}|D]D}|D]:}t||}tt|}||j|j||j|jq4q,td td }}td|td|}} |D]T}|D]J}t||}tt|}|d|jd|j|d|jd|jqqdS) Nr gi r6g( 0?go! @gd~QJcSsg|] }| qSrr)r-rrrrr/`r0z3ComplexTest.test_repr_roundtrip..r r ) rr@rrr%rrr,r) rZvalsrrr)Z roundtripr r rrrrrtest_repr_roundtrip]s(      zComplexTest.test_repr_roundtripcCs&|tddtd|tddtd|tddtd|tddtd|tddtd|tddtd|tddtd|tdd tdd }|t|dt||t|dt||t|d t||t|d t|td d }|t|dt||t|dt||t|d t||t|dt|tdd}|t|dt||t|dt||t|d t||t|dt||tddd|tddd|tddd|tddd|tddd|tddd|tddd|tddd|tddd |td!dd"|td#dd$|td!d%d&|td!d'd&|td!d(d)|td!d*d+|td!d,d-|td.d/d0|td1d2d3|td1d4d5|td1d6d7|td1d8d9|td1d:d;|td1d<d=|td1d>d?|td@dAdB|td1dCdD|td1dEdD|td1dFdG|tdHdFdI|tdHdJdK|tdHdLdM|tdNdLdO|tdPdQdR|tdSdTdU|tdSdVdW|tdSdXdY|tdSdZd[|td\dd]|td\d^d_|tdSd`da|tdSdbda|tdSdcdd|tdSdedd|tdfdgdh|tdfdZdi|tdfdjdk|tdfdVdl|tdfd^dm|tdfdndo|tdfdpdq|tdrjds|td1jdtduD]}|tdrj|qx|dvdwdx|ttttd%dy|ttdztd%d{|tttdzd%d||tttd}d%d~|ttttd'd|ttdztd'd|tttdzd'd|tttd}d'd|ttttd%d|ttdztd%d|tttdzd%d|tttd}d%d|ttttd'd|ttdztd'd|tttdzd'd|tttd}d'ddS)Ny?@ry? @y@y @rBy @-20gz 1.5+3jz^20gz 1.5+3j z<20z(1.5+3j) z>20z (1.5+3j)z^20z (1.5+3j) y+?Clz^20.2z (1.1-3.1j) z20.2fz 1.50+3.00jz>20.2fz<20.2fz1.50+3.00j y0)VC D@z150000000000000000000.00+3.00jz>40.2fz( 150000000000000000000.00+3.00jz^40,.2fz( 150,000,000,000,000,000,000.00+3.00j y|3*+TTD@z( 1,500,000,000,000,000,000,000.00+3.00j y|3*+TTDp@z,.2fz*1,500,000,000,000,000,000,000.00+3,000.00jr8z.0ez 1e+00+1e+00jz#.0ez1.e+00+1.e+00jz.0fz1+1jz#.0fz1.+1.jy??z1.1+1.1jz#gz1.10000+1.10000jz.1ez1.0e+00+1.0e+00jz#.1ez.1fz1.0+1.0jz#.1fy?z#fz-1.500000+0.500000jz-2.+0.jz#ez-1.500000e+00+5.000000e-01jz-2.e+00+5.e-01jz-1.50000+0.500000jz.0gz-2+0.5jz#.0gz-2.+0.5jy??Z010fz=20ZbcdoxXz *{0:.3f}*yn! @ @z*3.142+2.718j*znan+nanjrGz 1.000000+nanjz nan+1.000000jrjz nan-1.000000jzNAN+NANjz 1.000000+NANjz NAN+1.000000jz NAN-1.000000jzinf+infjz 1.000000+infjz inf+1.000000jz inf-1.000000jzINF+INFjz 1.000000+INFjz INF+1.000000jz INF-1.000000j) rqr#rrr<rp __format__r@r)rr)trrr test_formatys  zComplexTest.test_formatN)r)r)#rrrrr r%r'r+rArFrXrcrfrhrwrrrrrZrequires_IEEE_754rrrrrrrrrrrrrrrrrrr sJ  ;C       r __main__)rrrrrZtest.test_grammarrrrmathrrrrPr,rr@rr rmainrrrrs   i