Ejemplo n.º 1
0
    def test_select_merge_components_random_raisesError(self):
        ''' Verify that when comp 0 is excluded with K=3
          we cannot provide comp 0 as kA, [error is raised]
          AND
          in free choice, we only choose kA=1, kB=2
    '''
        MT = MergeTracker(3)
        MSelector = MergePairSelector()

        MT.excludeList = set([0])
        MT._synchronize_and_verify()
        for trial in range(10):
            kA, kB = MSelector.select_merge_components(None,
                                                       None,
                                                       MT,
                                                       kA=1,
                                                       mergename='random')
            assert kA == 1
            assert kB == 2
        for trial in range(10):
            kA, kB = MSelector.select_merge_components(None,
                                                       None,
                                                       MT,
                                                       kA=2,
                                                       mergename='random')
            assert kA == 1
            assert kB == 2
        with self.assertRaises(AssertionError):
            kA, kB = MSelector.select_merge_components(None,
                                                       None,
                                                       MT,
                                                       mergename='random',
                                                       kA=0)
Ejemplo n.º 2
0
 def test_recordMergeResult_assertRaisesOnRepeatPair2(self):
     MT = MergeTracker(6)
     MT.recordResult(0, 1, False)
     MT.recordResult(0, 2, False)
     MT.recordResult(0, 3, False)
     MT.recordResult(0, 4, True)
     MT.recordResult(1, 2, True)
     assert len(MT.excludePairs[1]) == MT.K
     with self.assertRaises(AssertionError):
         MT.recordResult(1, 2, False)
  def test_select_merge_components_random_raisesErrorAllButOneExcluded(self):
    ''' Verify that when comps 0,1 are excluded with K=3
          we cannot provide comp 2 as kA, [error is raised]
    '''
    MT = MergeTracker(3)
    MSelector = MergePairSelector()

    MT.excludeList = set([1, 0])
    MT._synchronize_and_verify()
    with self.assertRaises(AssertionError):
      kA, kB = MSelector.select_merge_components(None, None, MT, mergename='random', kA=2)
Ejemplo n.º 4
0
 def test_recordMergeResult_assertRaisesOnRepeatPair2(self):
   MT = MergeTracker(6)
   MT.recordResult(0, 1, False)
   MT.recordResult(0, 2, False)
   MT.recordResult(0, 3, False)
   MT.recordResult(0, 4, True)
   MT.recordResult(1, 2, True)
   assert len(MT.excludePairs[1]) == MT.K
   with self.assertRaises(AssertionError):
     MT.recordResult(1, 2, False)
Ejemplo n.º 5
0
 def test_recordMergeResult_assertRaisesWhenCompAlreadyPartOfMerge(self):
     MT = MergeTracker(4)
     print MT.excludeList
     MT.recordResult(2, 3, True)
     with self.assertRaises(AssertionError):
         MT.recordResult(0, 2, False)
     with self.assertRaises(AssertionError):
         MT.recordResult(1, 2, False)
Ejemplo n.º 6
0
    def test_select_merge_components_random_raisesErrorAllButOneExcluded(self):
        ''' Verify that when comps 0,1 are excluded with K=3
          we cannot provide comp 2 as kA, [error is raised]
    '''
        MT = MergeTracker(3)
        MSelector = MergePairSelector()

        MT.excludeList = set([1, 0])
        MT._synchronize_and_verify()
        with self.assertRaises(AssertionError):
            kA, kB = MSelector.select_merge_components(None,
                                                       None,
                                                       MT,
                                                       mergename='random',
                                                       kA=2)
Ejemplo n.º 7
0
 def test_recordMergeResult_assertRaisesWhenCompAlreadyPartOfMerge(self):
   MT = MergeTracker(4)
   print MT.excludeList
   MT.recordResult(2, 3, True)
   with self.assertRaises(AssertionError):
     MT.recordResult(0, 2, False)
   with self.assertRaises(AssertionError):
     MT.recordResult(1, 2, False)
  def test_select_merge_components_random_raisesError(self):
    ''' Verify that when comp 0 is excluded with K=3
          we cannot provide comp 0 as kA, [error is raised]
          AND
          in free choice, we only choose kA=1, kB=2
    '''
    MT = MergeTracker(3)
    MSelector = MergePairSelector()

    MT.excludeList = set([0])
    MT._synchronize_and_verify()
    for trial in range(10):
      kA, kB = MSelector.select_merge_components(None, None, MT, kA=1, mergename='random')
      assert kA == 1
      assert kB == 2
    for trial in range(10):
      kA, kB = MSelector.select_merge_components(None, None, MT, kA=2, mergename='random')
      assert kA == 1
      assert kB == 2
    with self.assertRaises(AssertionError):
      kA, kB = MSelector.select_merge_components(None, None, MT, mergename='random', kA=0)
Ejemplo n.º 9
0
 def test_select_merge_components_random(self):
     ''' Verify that under random choices, we select among 3 components
       equally often
 '''
     MT = MergeTracker(3)
     MSelector = MergePairSelector()
     counts = np.zeros(3)
     for trial in range(1000):
         kA, kB = MSelector.select_merge_components(None,
                                                    None,
                                                    MT,
                                                    mergename='random')
         counts[kA] += 1
         counts[kB] += 1
     counts /= np.sum(counts)
     minFrac = 0.25
     maxFrac = 0.4
     # Uniform at random means fraction of choice should be ~1/3 for each
     assert np.all(counts > minFrac)
     assert np.all(counts < maxFrac)
Ejemplo n.º 10
0
 def test_synchronize_catch_former_bug3(self):
   ''' 
       This prevents relapse of a bug captured in Jan 2013
   '''
   MT = MergeTracker(7)
   MT.excludeList = set([3, 0, 2, 6])
   MT.excludePairs[0] = set([0, 1, 2, 3, 4, 5, 6])
   MT.excludePairs[1] = set([0, 1, 2, 3, 5])
   MT.excludePairs[2] = set([0, 1, 2, 3, 4, 5, 6])
   MT.excludePairs[3] = set([0, 1, 2, 3, 4, 5, 6])
   MT.excludePairs[4] = set([0, 2, 3, 4, 5])
   MT.excludePairs[5] = set([0, 1, 2, 3, 4, 5])
   MT.excludePairs[6] = set([0, 1, 2, 3, 4, 5, 6])
   MT._synchronize_and_verify()
   assert 1 in MT.getAvailableComps()
   assert 4 in MT.getAvailableComps()
   assert 5 in MT.excludePairs[1]
   assert 1 in MT.excludePairs[5]
   assert 6 in MT.excludePairs[4]
   assert 6 in MT.excludePairs[1]
Ejemplo n.º 11
0
 def test_synchronize_catch_former_bug3(self):
     ''' 
     This prevents relapse of a bug captured in Jan 2013
 '''
     MT = MergeTracker(7)
     MT.excludeList = set([3, 0, 2, 6])
     MT.excludePairs[0] = set([0, 1, 2, 3, 4, 5, 6])
     MT.excludePairs[1] = set([0, 1, 2, 3, 5])
     MT.excludePairs[2] = set([0, 1, 2, 3, 4, 5, 6])
     MT.excludePairs[3] = set([0, 1, 2, 3, 4, 5, 6])
     MT.excludePairs[4] = set([0, 2, 3, 4, 5])
     MT.excludePairs[5] = set([0, 1, 2, 3, 4, 5])
     MT.excludePairs[6] = set([0, 1, 2, 3, 4, 5, 6])
     MT._synchronize_and_verify()
     assert 1 in MT.getAvailableComps()
     assert 4 in MT.getAvailableComps()
     assert 5 in MT.excludePairs[1]
     assert 1 in MT.excludePairs[5]
     assert 6 in MT.excludePairs[4]
     assert 6 in MT.excludePairs[1]
Ejemplo n.º 12
0
 def test_synchronize_catch_former_bug2(self):
   ''' Given un-synched excludeList and excludePairs,
         verify that the synchronization will discover (correctly)
         that no pairs are left
       This prevents relapse of a bug captured in Jan 2013
   '''
   MT = MergeTracker(6)
   MT.excludeList = set([1, 4, 2, 3])
   MT.excludePairs[0] = set([0, 1, 3, 4, 5])
   MT.excludePairs[1] = set([0, 1, 2, 3, 4, 5])
   MT.excludePairs[2] = set([0, 1, 2, 3, 4, 5])
   MT.excludePairs[3] = set([0, 1, 2, 3, 4, 5])
   MT.excludePairs[4] = set([0, 1, 2, 3, 4, 5])
   MT.excludePairs[5] = set([0, 1, 3, 4, 5])
   MT._synchronize_and_verify()
   for k in range(6):
     assert k in MT.excludeList
   assert not MT.hasAvailablePairs()
Ejemplo n.º 13
0
  def test_recordMergeResult(self):
    MT = MergeTracker(6)
    MT.recordResult(0, 1, False)
    MT.recordResult(0, 2, False)
    MT.recordResult(0, 3, False)
    assert len(MT.excludeList) == 0
    MT.recordResult(0, 4, True)
    assert 0 in MT.excludeList
    assert 1 not in MT.excludeList
    MT.recordResult(1, 2, True)
    assert 1 in MT.excludeList
    assert 2 not in MT.excludeList
    MT.recordResult(2, 3, True)
    assert 2 in MT.excludeList

    assert MT.K == 3
    assert MT.OrigK == 6
    assert (0,4) in MT.acceptedOrigIDs
    assert (1,2) in MT.acceptedOrigIDs
    assert (3,5) in MT.acceptedOrigIDs
Ejemplo n.º 14
0
 def test_recordMergeResult_assertRaisesOnRepeatPair(self):
     MT = MergeTracker(4)
     print MT.excludeList
     MT.recordResult(0, 1, True)
     with self.assertRaises(AssertionError):
         MT.recordResult(0, 1, True)
Ejemplo n.º 15
0
    def test_recordMergeResult(self):
        MT = MergeTracker(6)
        MT.recordResult(0, 1, False)
        MT.recordResult(0, 2, False)
        MT.recordResult(0, 3, False)
        assert len(MT.excludeList) == 0
        MT.recordResult(0, 4, True)
        assert 0 in MT.excludeList
        assert 1 not in MT.excludeList
        MT.recordResult(1, 2, True)
        assert 1 in MT.excludeList
        assert 2 not in MT.excludeList
        MT.recordResult(2, 3, True)
        assert 2 in MT.excludeList

        assert MT.K == 3
        assert MT.OrigK == 6
        assert (0, 4) in MT.acceptedOrigIDs
        assert (1, 2) in MT.acceptedOrigIDs
        assert (3, 5) in MT.acceptedOrigIDs
Ejemplo n.º 16
0
 def test_recordMergeResult_assertRaisesOnRepeatPair(self):
   MT = MergeTracker(4)
   print MT.excludeList
   MT.recordResult(0, 1, True)
   with self.assertRaises(AssertionError):
     MT.recordResult(0, 1, True)
Ejemplo n.º 17
0
 def test_synchronize_catch_former_bug2(self):
     ''' Given un-synched excludeList and excludePairs,
       verify that the synchronization will discover (correctly)
       that no pairs are left
     This prevents relapse of a bug captured in Jan 2013
 '''
     MT = MergeTracker(6)
     MT.excludeList = set([1, 4, 2, 3])
     MT.excludePairs[0] = set([0, 1, 3, 4, 5])
     MT.excludePairs[1] = set([0, 1, 2, 3, 4, 5])
     MT.excludePairs[2] = set([0, 1, 2, 3, 4, 5])
     MT.excludePairs[3] = set([0, 1, 2, 3, 4, 5])
     MT.excludePairs[4] = set([0, 1, 2, 3, 4, 5])
     MT.excludePairs[5] = set([0, 1, 3, 4, 5])
     MT._synchronize_and_verify()
     for k in range(6):
         assert k in MT.excludeList
     assert not MT.hasAvailablePairs()