Exemplo n.º 1
0
    def test_unionAgo_unionAtTime_samesetAfterShouldSucceed(self):
        set = RetroactiveUnionFind()
        set.unionAgo('a1','a2', tdelta = 5) 
        a1 = set.forest.getNode('a1')        
        a2 = set.forest.getNode('a2')

        self.assertEqual(set.sameSetAgo('a1','a2',7), True)
Exemplo n.º 2
0
    def test_unionAgo_unionAtTime_samesetBeforeShouldFail(self):
        set = RetroactiveUnionFind()
        set.unionAgo('a1','a2', tdelta = 5) 
        a1 = set.forest.getNode('a1')        
        a2 = set.forest.getNode('a2')

        self.assertEqual(set.sameSetAgo('a1','a2',2), False)
Exemplo n.º 3
0
    def test_unionAgo_unionAtSameTime_shouldHaveSameRoot(self):
        set = RetroactiveUnionFind()
        set.unionAgo('a1','a2') 
        a1 = set.forest.getNode('a1')        
        a2 = set.forest.getNode('a2')

        self.assertEqual(set.forest.getRoot(a1),set.forest.getRoot(a2))
Exemplo n.º 4
0
def FullyRetroactive(initstate):
    """
    Determine which implementation should be applied,
    and delegate to the corresponding code.

    initstate :: simple, non-retroactive data structure
    """
    if isinstance(initstate, SDPS):
        return GeneralFullyRetroactive(PartiallyRetroactive(initstate))
    elif isinstance(initstate, Deque):
        ##TODO: update once FR Deque is implemented
        return GeneralFullyRetroactive(PartiallyRetroactive(initstate))
    elif isinstance(initstate, Queue):
        return FullyRetroactive(Deque())
    elif isinstance(initstate, Stack):
        return FullyRetroactive(Deque())
    elif isinstance(initstate, PriorityQueue):
        return GeneralFullyRetroactive(PartiallyRetroactive(initstate))
    elif isinstance(initstate, UnionFind):
        return RetroactiveUnionFind()
    else:
        return GeneralFullyRetroactive(PartiallyRetroactive(initstate))
Exemplo n.º 5
0
    def test_unionAgo_unionTwice_pToPostXIntact(self):
        set = RetroactiveUnionFind()
        set.unionAgo('a1','a2', tdelta = 5) 
        set.unionAgo('a2','a3', tdelta = 3) 
        set.unionAgo('a3','a4', tdelta = 7) 
        set.unionAgo('a4','a5', tdelta = 14) 
        set.unionAgo('a5','a6', tdelta = 7) 
        set.unionAgo('a6','a7', tdelta = 7)
        set.unionAgo('a7','a8', tdelta = 7)


        set.unionAgo('a3','b1', tdelta = 7)
        set.unionAgo('b1','b2', tdelta = 7)
        set.unionAgo('b2','b3', tdelta = 7)

        set.unionAgo('b3','a8',6)

        # c to postX
        self.assertEqual(set.sameSetAgo('a1','a7',14), True)
Exemplo n.º 6
0
    def test_unionAgo_unionTwice_pToPreXIntact(self):
        set = RetroactiveUnionFind()
        set.unionAgo('a1','a2', tdelta = 5) 
        set.unionAgo('a2','a3', tdelta = 3) 
        set.unionAgo('a3','a4', tdelta = 7) 
        set.unionAgo('a4','a5', tdelta = 14) 
        set.unionAgo('a5','a6', tdelta = 7) 

        set.unionAgo('a3','b1', tdelta = 7)
        set.unionAgo('b1','b2', tdelta = 7)
        set.unionAgo('b2','b3', tdelta = 7)

        set.unionAgo('b3','a6',6)

        # p to preX
        self.assertEqual(set.sameSetAgo('a1','a4',7), True)
        # check the other branch for safety
        self.assertEqual(set.sameSetAgo('a1','b2',7), True)
Exemplo n.º 7
0
    def test_unionAgo_unionTwiceSubTree_unionTimeShouldChange(self):
        set = RetroactiveUnionFind()
        set.unionAgo('a1','a2', tdelta = 5) 
        set.unionAgo('a2','a3', tdelta = 14) 
        set.unionAgo('a3','a4', tdelta = 7) 
        
        set.unionAgo('a2','b1', tdelta = 7)
        set.unionAgo('b1','b2', tdelta = 7)
        set.unionAgo('b2','b3', tdelta = 7)

        self.assertEqual(set.sameSetAgo('b3','a4',6), False)
        set.unionAgo('b3','a4',6)
        self.assertEqual(set.sameSetAgo('b3','a4',6), True)
Exemplo n.º 8
0
    def test_unionAgo_unionTwice_unionTimeShouldChange(self):
        set = RetroactiveUnionFind()
        set.unionAgo('a1','a2', tdelta = 5) 
        set.unionAgo('a1','a2', tdelta = 2) 

        self.assertEqual(set.sameSetAgo('a1','a2',2), True)