a ze_!@sVddlmZddlZddlZddlZddlmZGdddejZe dkrRe dS))chainN)assert_python_okc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#S)$TestTopologicalSortcspdd}t|}|t||t|t|}t||D]&}fdd|D}|t||qDdS)Ncss@||r<|}|D]}||qtt|VqdSN)prepare is_active get_readydonetuplesorted)tsnodesnoderF/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_graphlib.pystatic_order_with_groups s  zATestTopologicalSort._test_graph..static_order_with_groupscsh|] }tqSr)next).0elementitrr z2TestTopologicalSort._test_graph..)graphlibTopologicalSorter assertEquallistiter static_orderset)selfgraphZexpectedrr groupZtsgrouprrr _test_graph s   zTestTopologicalSort._test_graphc Cst}|D]\}}|j|g|Rqz |WnXtjy}z>|j\}}|dt t |dt t |dWYd}~n d}~00dS)N ) rritemsaddrZ CycleErrorargsZassertInjoinmapstr) r r!cycler r dependsonemsgseqrrr _assert_cycles  >z!TestTopologicalSort._assert_cyclec Cs(|dhddhddhddhddhdgd|diid g|d d td Dd dtd ddD|dhdhdhdhdhdhdhdhdgd|ddgdgddgdgdgdgdgdgdggd gd|ddggdggdgd|ddggdggdgdggdgddS) N )r% r2r3))r4r6r5)r3r2)r%r7r8r9cSsi|]}||dhqSr:rrxrrr 3rz9TestTopologicalSort.test_simple_cases..r8cSsg|] }|fqSrrr;rrr 3rz9TestTopologicalSort.test_simple_cases.. )r%r4r@r6r2rArBrC))r9rD)r6rC)r@rB)r4rA)r%r2r%r7) rr9r%r4r@r6rEr5r3r7))r7)r@)r4r3)r9r6r5)rEr%r)rr9r%r4))r9r4rFrG)rr9r%r4r@r6rE))r9r4rE)r%r6)rr@)r#ranger rrrtest_simple_cases*s> $$  z%TestTopologicalSort.test_simple_casescCs>|dhdhdhdddg|tttddgdS)Nr%r@rE)r9r4r6)r%r@rE)r#rrIrrrtest_no_dependenciesRsz(TestTopologicalSort.test_no_dependenciescCsh|dhdhgddddgt}|dd|dd|dd|g|ddgdS)Nr%r@)r%r@r@r@r@r@)r9r4r)r%r@)rr9r4r9)r#rrr'rrr r rrrtest_the_node_multiple_timesWs     z0TestTopologicalSort.test_the_node_multiple_timescCs<ddtdD}td|i}|t|gddS)Ncss|]}d|dVqdS)r%r9Nrr;rrr crz@TestTopologicalSort.test_graph_with_iterables..r6r)r9r4r6r5r7r)rHrrrrr)r r-r rrrtest_graph_with_iterablesbsz-TestTopologicalSort.test_graph_with_iterablescCsjt}|dd|dd|dd|ddtdhdi}|g|g|dS)Nr9r%r4r@r6>r%r4r@r6)rrr'rr)r r ts2rrr1test_add_dependencies_for_same_node_incrementallygs    zETestTopologicalSort.test_add_dependencies_for_same_node_incrementallycCs|igdSr)r#rIrrr test_emptyrszTestTopologicalSort.test_emptyc Cs|ddhiddg|dhdhdgd|dhdhdhdgd|dhdhdhdhd hd gd|dhdhdhd hd hd hd gd|dhdhddhd hdddgdS)Nr9r%)r9r%)r9r%r9r4)r9r%r4)r9r4r%r9r@rE)r9r%r4r6r@r6r5)r9r%r4r@rEr5)r9r%r4r@)r1rIrrr test_cycleus &*zTestTopologicalSort.test_cyclecCst}|td|Wdn1s20Y|td|dWdn1sh0Y|td|Wdn1s0YdS)Nz prepare\(\) must be called firstr4)rrassertRaisesRegex ValueErrorrr rrLrrrtest_calls_before_prepares&(z-TestTopologicalSort.test_calls_before_preparecCsHt}||td|Wdn1s:0YdS)Nz!cannot prepare\(\) more than once)rrrrTrUrLrrrtest_prepare_multiple_timessz/TestTopologicalSort.test_prepare_multiple_timescCst}|dddd|ddd|||td|dWdn1sb0Y|td|dWdn1s0YdS)Nr9r%r4r@znode 2 was not passed outz#node 24 was not added using add\(\))rrr'rrrTrUr rLrrrtest_invalid_nodes_in_dones(z.TestTopologicalSort.test_invalid_nodes_in_donecCst}|dddd|dd|||d||d|d||d||d|d|d||d||d|d||d||dS) Nr9r%r4r@)r4r@rrFr:) rrr'rrrr assertFalserrLrrr test_dones      zTestTopologicalSort.test_donecCst}|dd|||||d|||d||||d|||d| |dS)Nr9r%rFr:) rrr'rZ assertTruerrrr rZrLrrrtest_is_actives   z"TestTopologicalSort.test_is_activecCsJt}|t|jtd|t|jdt|t|jttdS)Nr9)rrZ assertRaises TypeErrorr'dictrLrrrtest_not_hashable_nodessz+TestTopologicalSort.test_not_hashable_nodescCsdd}t}|ddd|dd|dd|d d |dd t}|dd|ddd|dd |d d |dd|t||t||dS) Ncss2||r.|}|j|t|VqdSr)rrrr r)r r rrr get_groupss  z^TestTopologicalSort.test_order_of_insertion_does_not_matter_between_groups..get_groupsr4r%r9rr@r6rEr5)rrr'rr)r r`r rPrrr6test_order_of_insertion_does_not_matter_between_groupss        zJTestTopologicalSort.test_order_of_insertion_does_not_matter_between_groupscCs@dd}|d}|d}||d||d|||dS)NcSs8d}tj}d|d<t||d<td|fi|}|S)Naxif 1: import graphlib ts = graphlib.TopologicalSorter() ts.add('blech', 'bluch', 'hola') ts.add('abcd', 'blech', 'bluch', 'a', 'b') ts.add('a', 'a string', 'something', 'b') ts.add('bluch', 'hola', 'abcde', 'a', 'b') print(list(ts.static_order())) TZ __cleanenvZPYTHONHASHSEEDz-c)osenvironcopyr+r)seedcodeenvoutrrrcheck_order_with_hash_seeds   zlTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seed..check_order_with_hash_seediiz)ZassertNotEqualr)r riZrun1Zrun2rrr4test_static_order_does_not_change_with_the_hash_seeds   zHTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seedN)__name__ __module__ __qualname__r#r1rJrKrMrOrQrRrSrVrWrYr[r\r_rarkrrrrrs" (    r__main__) itertoolsrrrbZunittestZtest.support.script_helperrZTestCaserrlmainrrrrs  u