<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import unittest <EOL> from bnpy . learnalg import MergeTracker <EOL> from bnpy . learnalg import MergePairSelector <EOL> class TestMergePairSelector ( unittest . TestCase ) : <EOL> def shortDescription ( self ) : <EOL> return None <EOL> def setUp ( self ) : <EOL> pass <EOL> def test_reindexAfterMerge ( self ) : <EOL> MSelector = MergePairSelector ( ) <EOL> MSelector . MScores [ <NUM_LIT:0> ] = <NUM_LIT:5> <EOL> MSelector . MScores [ <NUM_LIT:3> ] = <NUM_LIT:5> <EOL> MSelector . MScores [ <NUM_LIT:4> ] = <NUM_LIT:5> <EOL> MSelector . PairMScores [ ( <NUM_LIT:0> , <NUM_LIT:1> ) ] = <NUM_LIT:5> <EOL> MSelector . PairMScores [ ( <NUM_LIT:3> , <NUM_LIT:4> ) ] = <NUM_LIT:5> <EOL> MSelector . PairMScores [ ( <NUM_LIT:5> , <NUM_LIT:6> ) ] = <NUM_LIT:5> <EOL> MSelector . reindexAfterMerge ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert MSelector . MScores [ <NUM_LIT:0> ] == <NUM_LIT:5> <EOL> assert MSelector . MScores [ <NUM_LIT:3> ] == <NUM_LIT:5> <EOL> assert <NUM_LIT:2> not in MSelector . MScores <EOL> assert len ( MSelector . PairMScores . keys ( ) ) == <NUM_LIT:2> <EOL> assert ( <NUM_LIT:0> , <NUM_LIT:1> ) in MSelector . PairMScores <EOL> assert ( <NUM_LIT:4> , <NUM_LIT:5> ) in MSelector . PairMScores <EOL> assert ( <NUM_LIT:2> , <NUM_LIT:3> ) not in MSelector . PairMScores <EOL> def test_select_merge_components_random ( self ) : <EOL> '''<STR_LIT>''' <EOL> MT = MergeTracker ( <NUM_LIT:3> ) <EOL> MSelector = MergePairSelector ( ) <EOL> counts = np . zeros ( <NUM_LIT:3> ) <EOL> for trial in range ( <NUM_LIT:1000> ) : <EOL> kA , kB = MSelector . select_merge_components ( None , None , MT , mergename = '<STR_LIT>' ) <EOL> counts [ kA ] += <NUM_LIT:1> <EOL> counts [ kB ] += <NUM_LIT:1> <EOL> counts /= np . sum ( counts ) <EOL> minFrac = <NUM_LIT> <EOL> maxFrac = <NUM_LIT> <EOL> assert np . all ( counts > minFrac ) <EOL> assert np . all ( counts < maxFrac ) <EOL> def test_select_merge_components_random_raisesError ( self ) : <EOL> '''<STR_LIT>''' <EOL> MT = MergeTracker ( <NUM_LIT:3> ) <EOL> MSelector = MergePairSelector ( ) <EOL> MT . excludeList = set ( [ <NUM_LIT:0> ] ) <EOL> MT . _synchronize_and_verify ( ) <EOL> for trial in range ( <NUM_LIT:10> ) : <EOL> kA , kB = MSelector . select_merge_components ( None , None , MT , kA = <NUM_LIT:1> , mergename = '<STR_LIT>' ) <EOL> assert kA == <NUM_LIT:1> <EOL> assert kB == <NUM_LIT:2> <EOL> for trial in range ( <NUM_LIT:10> ) : <EOL> kA , kB = MSelector . select_merge_components ( None , None , MT , kA = <NUM_LIT:2> , mergename = '<STR_LIT>' ) <EOL> assert kA == <NUM_LIT:1> <EOL> assert kB == <NUM_LIT:2> <EOL> with self . assertRaises ( AssertionError ) : <EOL> kA , kB = MSelector . select_merge_components ( None , None , MT , mergename = '<STR_LIT>' , kA = <NUM_LIT:0> ) <EOL> def test_select_merge_components_random_raisesErrorAllButOneExcluded ( self ) : <EOL> '''<STR_LIT>''' <EOL> MT = MergeTracker ( <NUM_LIT:3> ) <EOL> MSelector = MergePairSelector ( ) <EOL> MT . excludeList = set ( [ <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> MT . _synchronize_and_verify ( ) <EOL> with self . assertRaises ( AssertionError ) : <EOL> kA , kB = MSelector . select_merge_components ( None , None , MT , mergename = '<STR_LIT>' , kA = <NUM_LIT:2> ) </s>
