a ze5@sddlmZddlZddlZddlmZejZdadddZGdddej Z Gdd d ej Z Gd d d ej Z d d Z Gdddej ZedkredS))supportN cmp_to_keycCstrtd||dd}|r0|jt|dn|t|t|krtd|tdt|t|t|t|t|td7adSt|D]V\}}||}||urtd|td|||t|t|t|td7adSqdS)Nz checkingkeyzerror inzlength mismatch;zout of order at index)verboseprintsortrlennerrors enumerate)tagZexpectedrawZcompareZorigiZgoodmayberB/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_sort.pycheck s0    rc@seZdZddZdS)TestBasec sJdg}tddD]$}d|}|t|d|dq|gdGfdddtGdd d t|D]}tt|}trtd ||dd}td |||dd}|td |||dd}t |td |||dd}||dd}td||ddtr.tdtd|dd}|j t dddtd||t |dkrdd}|dd}|j t|j |dfdd|D}|dd}t |d_d}z | Wntyd}Yn0|rd_td||fddt|D}dd|D} | dd| D}td ||qldS)!Nrr )rdics,eZdZdZddZfddZddZdS) z+TestBase.testStressfully..ComplainsTcSs ||_dSNr)selfrrrr__init__6sz4TestBase.testStressfully..Complains.__init__cs2jr&tdkr&tr"td||t|j|jkS)NgMbP?z complaining at)maybe_complainrandomrr RuntimeErrorrrother Complainsrr__lt__9s  z2TestBase.testStressfully..Complains.__lt__cSs d|jS)Nz Complains(%d)rrrrr__repr__@sz4TestBase.testStressfully..Complains.__repr__N)__name__ __module__ __qualname__rrr$r&rr"rrr#3s r#c@s$eZdZddZddZddZdS)z(TestBase.testStressfully..StablecSs||_||_dSrrindex)rrrrrrrDsz1TestBase.testStressfully..Stable.__init__cSs |j|jkSrrr rrrr$Hsz/TestBase.testStressfully..Stable.__lt__cSsd|j|jfS)NzStable(%d, %d)r*r%rrrr&Ksz1TestBase.testStressfully..Stable.__repr__N)r'r(r)rr$r&rrrrStableCsr,z Testing sizeidentityreversedzrandom permutationzreversed via functioncSs||k||kSrrabrrraz*TestBase.testStressfully..z3 Checking against an insane comparison function.z? If the implementation isn't careful, this may segfault.cSsttddS)Nr)intrr/rrrr2gr3rz(an insane function left some permutationcSstdSrrxrrrbad_keyksz)TestBase.testStressfully..bad_keycsg|] }|qSrr.0rr"rr pr3z,TestBase.testStressfully..TFz+exception during sort left some permutationcsg|]}td|qS)rr randranger:)r,rrr<}r3cSsg|]}||jfqSr)r+)r;errrr<~r3cSsg|] \}}|qSrr)r;r?rrrrr<r3Z stability)rangeextendobjectlistrr rreversershuffler rr assertRaisesrr) rZsizesZpowernr8syr9Z it_complainedZ augmentedr)r#r,rtestStressfully+sd                    zTestBase.testStressfullyN)r'r(r)rJrrrrr*src@seZdZddZddZdS)TestBugscs:GfdddfddtdD|tjdS)NcseZdZfddZdS)z"TestBugs.test_bug453523..Ccs0rtdkrn dtdkS)Ng?r4g?)rpopappendr Lrrr$s  z)TestBugs.test_bug453523..C.__lt__Nr'r(r)r$rrNrrCsrQcsg|] }qSrrr:)rQrrr<r3z+TestBugs.test_bug453523..2)r@rF ValueErrorr r%r)rQrOrtest_bug453523szTestBugs.test_bug453523cshg}tdD]V}fdd}ddg|jtjt|dfdd}|jtjt|d|g}q dS)Ncs"d||k||kSNr4)rMrLr8rIrNrr mutating_cmps z7TestBugs.test_undetected_mutation..mutating_cmprrrcs$ddd=||k||kSrV)rMrWrNrrrXs  )r@rFrSr r)rZ memorywasterrrXrrNrtest_undetected_mutations   z!TestBugs.test_undetected_mutationN)r'r(r)rTrYrrrrrKsrKc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)TestDecorateSortUndecoratecCsHd}|dd}t||jtjddd}|jt|ddS)N,The quick Brown fox Jumped over The lazy DogrcSs"||}}||k||kSr)lower)r8rIZxlowerZylowerrrrmy_cmpsz9TestDecorateSortUndecorate.test_decorated..my_cmp)splitrrEr strr\r)rdatacopyr]rrrtest_decorateds   z)TestDecorateSortUndecorate.test_decoratedcCs"d}|jt|jddddS)Nr[cSsdSNrrrWrrrr2r3z>TestDecorateSortUndecorate.test_baddecorator..r)r^rF TypeErrorr rr`rrrtest_baddecoratorsz,TestDecorateSortUndecorate.test_baddecoratorcCsFddtdD}|dd}|jddd||||dS)NcSsg|]}td|fqSrr=r:rrrr<r3z=TestDecorateSortUndecorate.test_stability..cSs|dSrcr)trrrr2r3z;TestDecorateSortUndecorate.test_stability..r)r@r assertEqual)rr`rarrrtest_stabilitys  z)TestDecorateSortUndecorate.test_stabilitycCs@ttdd}|dd}|jt|jddd|||dS)NrcSsd|S)Nrrr7rrrr2r3zDTestDecorateSortUndecorate.test_key_with_exception..r)rCr@rFZeroDivisionErrorr rj)rr`duprrrtest_key_with_exceptions z2TestDecorateSortUndecorate.test_key_with_exceptioncs.ttdfdd}|jtj|ddS)Nrcsdd=tddd<|SNrUr@r7r`rrks z.kr)rCr@rFrSr )rrsrrrrtest_key_with_mutations  z1TestDecorateSortUndecorate.test_key_with_mutationcs6ttdGfdddt}|jtj|ddS)Nrcs(eZdZddZfddZddZdS)zITestDecorateSortUndecorate.test_key_with_mutating_del..SortKillercSsdSrrrr8rrrrszRTestDecorateSortUndecorate.test_key_with_mutating_del..SortKiller.__init__csdd=tddd<dSrprqr%rrrr__del__s zQTestDecorateSortUndecorate.test_key_with_mutating_del..SortKiller.__del__cSst|t|kSr)idr rrrr$szPTestDecorateSortUndecorate.test_key_with_mutating_del..SortKiller.__lt__N)r'r(r)rrvr$rrrrr SortKillers rxr)rCr@rBrFrSr rrxrrrrtest_key_with_mutating_dels z5TestDecorateSortUndecorate.test_key_with_mutating_delcs6ttdGfdddt}|jtj|ddS)Nrcs eZdZddZfddZdS)zWTestDecorateSortUndecorate.test_key_with_mutating_del_and_exception..SortKillercSs|dkr tdS)Nrr6rurrrrsz`TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception..SortKiller.__init__cs"dd=ttddd<dSrp)rCr@r%rrrrrvs z_TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception..SortKiller.__del__N)r'r(r)rrvrrrrrrxsrxr)rCr@rBrFrr ryrrrr(test_key_with_mutating_del_and_exceptions zCTestDecorateSortUndecorate.test_key_with_mutating_del_and_exceptioncCs>ttd}t||jdd||ttddddS)NrT)rDc)rCr@rrEr rjrerrr test_reverses   z'TestDecorateSortUndecorate.test_reversecCsddtdD}|dd}|dd}dd}dd}|jt|dd |jt|d ||||jd d dd |||dS) NcSsg|]}td|fqSrgr=r:rrrr<r3zETestDecorateSortUndecorate.test_reverse_stability..rhcSs"|d|d}}||k||kSrcrr8rIZx0Zy0rrrr]szATestDecorateSortUndecorate.test_reverse_stability..my_cmpcSs"|d|d}}||k||kSrcrrrrrmy_cmp_reversedszJTestDecorateSortUndecorate.test_reverse_stability..my_cmp_reversedT)rrDrcSs|dSrcrr7rrrr2r3zCTestDecorateSortUndecorate.test_reverse_stability..)r@r rrj)rr`Zcopy1copy2r]rrrrtest_reverse_stabilitys   z1TestDecorateSortUndecorate.test_reverse_stabilityN) r'r(r)rbrfrkrortrzr{r~rrrrrrZs  rZc Cstdt||dd}dd|D}dd|D}|||fD]H}t|}ddtdd|DD}t||D]\}}|||qxqFdS)NrcSsg|] }|fqSrrr;r8rrrr<r3z:check_against_PyObject_RichCompareBool..cSsg|] }|ffqSrrrrrrr<r3cSsg|] }|dqS)rr)r;rIrrrr<r3cSsg|] }d|fqS)rrrrrrr<r3)rseedrEsortedzipZassertIs) rrOZL_1ZL_2ZL_3Z optimizedZ referenceoptrefrrr&check_against_PyObject_RichCompareBools   rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)TestOptimizedComparescCsddgddgddgg}|D]B}|t|j|tdd|Dj|tdd|Djqdd gd d gd dgd d gg}|D]}t||q~dS) Nrfoog)rcSsg|] }|fqSrrrrrrr<*r3zBTestOptimizedCompares.test_safe_object_compare..cSsg|] }|ffqSrrrrrrr<+r3rg?)rFrdr r)rZheterogeneous_listsrOZfloat_int_listsrrrtest_safe_object_compare$sz.TestOptimizedCompares.test_safe_object_comparecsGfdddtGdddtGdddtfddtd D}|d |t|Wdn1s~0Yfd dtd D}|d |t"d d|DWdn1s0YGd dd}||g}|t|j|tdd|DjttddgddtdDdgddtdDddtdDg}|D]}t||qrdS)NcseZdZfddZdS)zITestOptimizedCompares.test_unsafe_object_compare..WackyComparatorcs_t||Sr) __class__r5r$r  WackyList2elemrrr$:szPTestOptimizedCompares.test_unsafe_object_compare..WackyComparator.__lt__NrPrrrrWackyComparator9src@s eZdZdS)zDTestOptimizedCompares.test_unsafe_object_compare..WackyList1N)r'r(r)rrrr WackyList1>src@seZdZddZdS)zDTestOptimizedCompares.test_unsafe_object_compare..WackyList2cSstdSr)rSr rrrr$BszKTestOptimizedCompares.test_unsafe_object_compare..WackyList2.__lt__NrPrrrrrAsrcsg|]}||gqSrrr:rrrrr<Er3zDTestOptimizedCompares.test_unsafe_object_compare..rr}csg|]}||gqSrrr:rrrr<Jr3cSsg|] }|fqSrrrrrrr<Mr3c@seZdZddZdS)zMTestOptimizedCompares.test_unsafe_object_compare..PointlessComparatorcSstSr)NotImplementedr rrrr$RszTTestOptimizedCompares.test_unsafe_object_compare..PointlessComparator.__lt__NrPrrrrPointlessComparatorQsrcSsg|] }|fqSrrrrrrr<Vr3rrcSsg|] }t|qSrr_rrrrr<[r3u￿cSsg|] }t|qSr)bytesrrrrr<\r3cSsg|]}tdd|qS)cSs||kSrrrWrrrr2]r3zMTestOptimizedCompares.test_unsafe_object_compare...rrrrrr<]r3)r5rCr@rFrSr rdr)rrOrZlistsr)rrrrrtest_unsafe_object_compare4s, & 0 z0TestOptimizedCompares.test_unsafe_object_comparecCst|ddtdDdS)NcSsg|] }t|qSrrrrrrr<bszCTestOptimizedCompares.test_unsafe_latin_compare..rrr@r%rrrtest_unsafe_latin_compareas z/TestOptimizedCompares.test_unsafe_latin_comparecCst|ddtdDdS)NcSsg|]}|qSrrrrrrr<fszBTestOptimizedCompares.test_unsafe_long_compare..rrr%rrrtest_unsafe_long_comparees z.TestOptimizedCompares.test_unsafe_long_comparecCst|ddtdDdS)NcSsg|] }t|qSrfloatrrrrr<jszCTestOptimizedCompares.test_unsafe_float_compare..rrr%rrrtest_unsafe_float_compareis z/TestOptimizedCompares.test_unsafe_float_comparecCs0t|tdgdt|ddtdDdS)NnanrcSsg|] }tdqS)rr)r;_rrrr<vszCTestOptimizedCompares.test_unsafe_tuple_compare..)rrr@r%rrrtest_unsafe_tuple_comparems z/TestOptimizedCompares.test_unsafe_tuple_comparecCs:|tgdj|tddgj|tddgjdS)N))?r)FA)r0r)rr0)rFrdr r%rrrtest_not_all_tuplesysz)TestOptimizedCompares.test_not_all_tuplesN) r'r(r)rrrrrrrrrrrr#s- r__main__)N)testrrZunittest functoolsrrr rZTestCaserrKrZrrr'mainrrrrs   [%]\