a zeD`@sddlmZmZddlmZmZddlmZddlZddlZddl Z ddlm Z m Z m Z m Z ddlZddlZedZedZddd DZd ded fed feefd efd efd efdefe efe d fe d fe d fe dfe e fde fd e fd e fd e fee fedfed ffDZddee fedfed fed fed feefe efdefd efd efd efeeff DZGdddejZGdddejZedkredS))requires_IEEE_754 cpython_only)parse_testfile test_fileN)phasepolarrectpiinfnancCs g|]}dD]}t||q qS)complex.0xyrC/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_cmath.py rr cCsg|]\}}t||qSrrrrrrrrr ffffff@rffffffcCsg|]\}}t||qSrrrrrrr%rc@seZdZdddDZeddeddddZd d Zd d Zd dZd)acosacoshasinasinhatanatanhcoscoshexploglog10sinsinhsqrttantanhcCs t|dS)Ny@rr'rrrr;rzCMathTests.cCs td|S)Ny,@;r.r/rrrr0<rcCstt|_dSN)openr test_valuesselfrrrsetUp>szCMathTests.setUpcCs|jdSr1)r3closer4rrrtearDownAszCMathTests.tearDowncCsd}t|st|r2t|rjt|rjdSn8||krj|dkrFdStd|td|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)mathisnancopysignfailformat)r5rrmsgrrrassertFloatIdenticalDszCMathTests.assertFloatIdenticalcCs$||j|j||j|jdS)zFail 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@realimag)r5rrrrrassertComplexIdentical[sz!CMathTests.assertComplexIdenticalV瞯< NcCst|r,t|rdS||p(d|t|rX||krBdS||pTd|||s|std|td|kr||pd||zt||}WntyYn0|t||t|krdS||pd||dS)aFail 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}r9z,zero has wrong sign: expected {!r}, got {!r}z({!r} and {!r} are not sufficiently close) r:r;r=r>isinfr<abs OverflowErrormax)r5abZrel_errabs_errr?Zabsolute_errorrrrrAssertAlmostEquales0       zCMathTests.rAssertAlmostEqualcCsHd}d}|jtj|ddtj|d|jtj|ddtj|ddS)NgiW @g-DT! @ zcmath.pi is {}; should be {})Zplacesr?zcmath.e is {}; should be {})assertAlmostEqualrr r>e)r5Z e_expectedZ pi_expectedrrrtest_constantss    zCMathTests.test_constantscCs|tjjtj|tjjd|tjjd|tjjtj|ttj j|tj jd|tj jd|ttj j|t tjd|t tjd|t tj d|t tj ddS)Nr r infjr nanj) assertEqualrr rAr:rBrR assertTruer;r rSreprr4rrrtest_infinity_and_nan_constantssz*CMathTests.test_infinity_and_nan_constantscs2dddddddttg}Gdddt}Gd d d }Gd d d tGfd ddt}Gfddd}Gdddt}Gddd}Gddd}Gddd} Gfdddt} Gfddd} Gfdddt} Gfdd d } |jD]*}||||||||||| |||| |||| |||| |||||t||t|||t|| |t|||D]*}|t||||t|||q||||||qdS)!Nyz@7Ă??g]ֆz not complex@c@seZdZddZddZdS)z.CMathTests.test_user_object..MyComplexcSs ||_dSr1valuer5r\rrr__init__sz7CMathTests.test_user_object..MyComplex.__init__cSs|jSr1r[r4rrr __complex__sz:CMathTests.test_user_object..MyComplex.__complex__N__name__ __module__ __qualname__r^r_rrrr MyComplexsrdc@seZdZddZddZdS)z0CMathTests.test_user_object..MyComplexOScSs ||_dSr1r[r]rrrr^sz9CMathTests.test_user_object..MyComplexOS.__init__cSs|jSr1r[r4rrrr_sz.MyComplexOS.__complex__Nr`rrrr MyComplexOSsrec@s eZdZdS)z2CMathTests.test_user_object..SomeExceptionNrarbrcrrrr SomeExceptionsrgcseZdZfddZdS)z7CMathTests.test_user_object..MyComplexExceptioncsdSr1rr4rgrrr_szCCMathTests.test_user_object..MyComplexException.__complex__Nrarbrcr_rrhrrMyComplexExceptionsrjcseZdZfddZdS)z9CMathTests.test_user_object..MyComplexExceptionOScsdSr1rr4rhrrr_szECMathTests.test_user_object..MyComplexExceptionOS.__complex__NrirrhrrMyComplexExceptionOSsrkc@s eZdZdS)z;CMathTests.test_user_object..NeitherComplexNorFloatNrfrrrrNeitherComplexNorFloatsrlc@s eZdZdS)z=CMathTests.test_user_object..NeitherComplexNorFloatOSNrfrrrrNeitherComplexNorFloatOSsrmc@seZdZddZddZdS)z*CMathTests.test_user_object..IndexcSsdSNrr4rrr__int__rz2CMathTests.test_user_object..Index.__int__cSsdSrnrr4rrr __index__rz4CMathTests.test_user_object..Index.__index__N)rarbrcrprqrrrrIndexsrrc@seZdZddZdS)z*CMathTests.test_user_object..MyIntcSsdSrnrr4rrrrprz2CMathTests.test_user_object..MyInt.__int__N)rarbrcrprrrrMyIntsrscs$eZdZfddZfddZdS)z4CMathTests.test_user_object..FloatAndComplexcsSr1rr4flt_argrr __float__sz>CMathTests.test_user_object..FloatAndComplex.__float__csSr1rr4cx_argrrr_sz@CMathTests.test_user_object..FloatAndComplex.__complex__Nrarbrcrvr_rrxrurrFloatAndComplexs r{cs$eZdZfddZfddZdS)z6CMathTests.test_user_object..FloatAndComplexOScsSr1rr4rtrrrvsz@CMathTests.test_user_object..FloatAndComplexOS.__float__csSr1rr4rwrrr_szBCMathTests.test_user_object..FloatAndComplexOS.__complex__NryrrzrrFloatAndComplexOSs r|cseZdZfddZdS)z.CMathTests.test_user_object..JustFloatcsSr1rr4rtrrrvsz8CMathTests.test_user_object..JustFloat.__float__Nrarbrcrvrrtrr JustFloatsr~cseZdZfddZdS)z0CMathTests.test_user_object..JustFloatOScsSr1rr4rtrrrvsz:CMathTests.test_user_object..JustFloatOS.__float__Nr}rrtrr JustFloatOSsr)objectNotImplemented Exceptiontest_functionsrTint assertRaises TypeError)r5Z non_complexesrdrerjrkrlrmrrrsr{r|r~rfZ bad_complexr)rgrxrurtest_user_objectsD  zCMathTests.test_user_objectcCsV|jD]&}dD]}|||||qq|jD]}dD]}|t||q} |D]4} t| | } |t| | | j|d| jqqdS) N)g{Gz?g?g??g?gGz?cSsg|] }| qSrrrrrrrr&rz6CMathTests.test_cmath_matches_math..)r r9r9cSsg|] }d|qS)r9rrrrrr*rr cSsg|] }| qSrrrrrrr.r) rr r"r$r%r&r'r(r)r*r+r,r-)rrZg$@) itemsrr:rrMrArTrBr')r5r3Z unit_intervalZpositiveZ nonnegativeZ real_linerfnvaluesZfloat_fnZ complex_fnvzbaserrrtest_cmath_matches_mathsB    z"CMathTests.test_cmath_matches_mathc Cs(dh}d}tjdkrLtd}zttt|d}WntyJYn0dd}dd}tt D]\}}}} } } } t || } t | | }|dur|d kr||vrqd|d kr|}n|d kr|}n t t |}d | vsd | vrz || }WntyYqdYn0| d|||| d| vr`z || }WntyHYqdYn0| d|||| || }d| vrt t|j|j}t t|j|j}d| vrt |jt|j}t |jt|j}|dvrd}nd}d|||| |j|j|j|j}|j|j|j||d|j|j|j|dqddS)NZtan0064darwinr.cSst|j|jS)zaWrapped version of rect that accepts a complex number instead of two float arguments.)rrrArBrrrr rect_complex\sz5CMathTests.test_specific_values..rect_complexcSs tt|S)zYWrapped version of polar that returns a complex number instead of two floats.)rrrrrr polar_complexasz6CMathTests.test_specific_values..polar_complex) rYrrzdivide-by-zeroinvalidz9ValueError not raised in test {}: {}(complex({!r}, {!r}))ZoverflowzrHrGrArBrM)r5Z SKIP_ON_TIGERZ osx_versionZ version_txtrridrarZaiZereiflagsrexpectedfunctionactualZ real_abs_errZ error_messagerrrtest_specific_valuesNsx                zCMathTests.test_specific_valuescsfdd}|dd|dd|ddtf|d dtd f|d d t d ftd }|t|d|df|t| d|tf|td||td f|td| |t d f|t|||tdf|t|| |t df|t| ||dtdf|t| | |dtdftd}|t|d||f|td|||f|t||||f|t||||f|t| |||f|t||||f|t|| ||fdS)Ncs,|}t||D]\}}||qdSr1)ziprM)rrZgotrPgfuncr5rrchecksz%CMathTests.check_polar..checkr)r r rX)r9r r9?royg@r r rYr )r floatr)r5rrr r rrr check_polars.   zCMathTests.check_polarcCs|tdSr1)rrr4rrr test_polarszCMathTests.test_polarcs&ddlmfdd}||dS)Nr set_errnocs*dzt|WdSd0dS)N r)rrrrrpolar_with_errno_sets z9CMathTests.test_polar_errno..polar_with_errno_set)Z _testcapirr)r5rrrrtest_polar_errnos  zCMathTests.test_polar_errnocCs|tdd|tdd|tdt|tdt|tdt |tdtd|td t d|ttddd|ttdd d |ttd dt|ttd d t |ttt d t |ttt d t |ttt t d t|ttd t t d|ttd t t d|ttdt t d|ttd t t d|tttt t d|tttd d |tttd d |tttdd|tttd d|tttttd|ttd ttd|ttdttd|ttd ttd|ttd ttd|ttt tdt|ttt d t|ttt dttD]}|t t|qdS)Nrr r9ryYnyYnrroyrrgrrg?) rOrr rTrINF complex_nansrUr:r;r5rrrr test_phasesBzCMathTests.test_phasecCs~tD]}|t|dqtD]}|t|tq|tttt t|t tttd|t tttd|t tttd|t tttd|ttttt|ttt tt|t ttdt|t ttdt|t ttdt|t ttdt|ttttt|t ttttdS)Nr rrr) complex_zerosrTrGcomplex_infinitiesrrNANrUr:r;rrrrtest_abss"zCMathTests.test_abscCs|tttdddS)NgU)rrHrGrr4rrrtest_abs_overflowsszCMathTests.test_abs_overflowscCsBd}t|j|d|ks0t|j|d|kr>|||fdS)NgHz>rrX)rGrArBr=)r5rJrKZepsrrr assertCEquals,zCMathTests.assertCEqualcCsj|tddd|tddd|tdt d|tdtdd|tdt dddS) Nr)rrrX)r9r)rrro)rr9)rr)rrr r4rrr test_rects zCMathTests.test_rectcCsbtdddddtdtdg}|D]:}|D]0}t||}|t|t|oVt|q*q"dS)Nz-infrrr rr r )rrrTrisfiniter:)r5Z real_valsrrrrrr test_isfinite#s   zCMathTests.test_isfinitecCs|td|td|tt|tt|tttd|ttdt|tttt|tttt|ttttdSNrXrr) assertFalserr;rrUrrr4rrr test_isnan,szCMathTests.test_isnancCs|td|td|tt|tt|tttd|ttdt|tttt|tttt|ttttdSr)rrrFrrUrrr4rrr test_isinf7szCMathTests.test_isinfcCs tD]}|t||qdSr1)rrCrr-rrrr testTanhSignBszCMathTests.testTanhSigncCs tD]}|t||qdSr1)rrCrr"rrrr testAtanSignKszCMathTests.testAtanSigncCs tD]}|t||qdSr1)rrCrr#rrrr testAtanhSignPszCMathTests.testAtanhSign)rDrEN) rarbrcrappendr6r8r@rCrMrQrWrrrrrrrrrrrrrrrrrrrrrrrrr4sH  2b 0 V )      rc@s*eZdZejZddZddZddZdS) IsCloseTestscCs|t |jddddWdn1s00Y|t |jddddWdn1sj0Y|t"|jdddddWdn1s0YdS)Nrrel_tolabs_tol)rr)rriscloser4rrrtest_reject_complex_tolerancesYs  . . z+IsCloseTests.test_reject_complex_tolerancescCs(gd}|j|dd|j|dddS)N))??y??)ry??)y?y?)y?y?g-q=rgvIh%<=)assertAllCloseassertAllNotClose)r5Zcomplex_examplesrrrtest_complex_valuescsz IsCloseTests.test_complex_valuescCsHgd}|j|dd|j|dd|jdddd|jdddddS) N))yMbP?r)MbP?r)MbP?MbP?r)yMbPMbP?r)MbP?MbPr)yMbPMbPrg~jtX?rgMb@?rrgMb`?r)rrZ assertIsCloseZassertIsNotClose)r5Znear_zero_examplesrrrtest_complex_near_zerons z#IsCloseTests.test_complex_near_zeroN)rarbrcrrrrrrrrrrVs  r__main__)Z test.supportrrZtest.test_mathrrZ test_mathZunittestrr:rrrr rrrrrrrrZTestCaserrramainrrrrsl  &)