示例#1
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     #Creates a very basic branch-tree
     self.s1 = Segment("A")
     self.s2 = Segment("A")
     self.s3 = Segment()
     self.s4 = Segment("T")
     self.s1.createBranch(self.s2)
     self.s1.createBranch(self.s3)
     self.s3.createBranch(self.s4)
示例#2
0
 def testLowerBoundSubstitutionCost(self):
     s5 = Segment("T", parent=self.s1)
     self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 1)
     self.assertEqual(self.s2.lowerBoundSubstitutionCost(), 0)
     self.assertEqual(self.s3.lowerBoundSubstitutionCost(), 0)
     self.assertEqual(self.s4.lowerBoundSubstitutionCost(), 0)
     s6 = Segment("T", parent=self.s1)
     self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 1)
     s7 = Segment("G", parent=self.s1)
     self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 2)
示例#3
0
 def testUpperBoundSubstitutionCost(self):
     s5 = Segment("T", parent=self.s1)
     self.assertEqual(self.s1.upperBoundSubstitutionCost(), 2)
     self.assertEqual(self.s2.upperBoundSubstitutionCost(), 0)
     self.assertEqual(self.s3.upperBoundSubstitutionCost(), 0)
     self.assertEqual(self.s4.upperBoundSubstitutionCost(), 0)
     s6 = Segment("T", parent=self.s1)
     self.assertEqual(self.s1.upperBoundSubstitutionCost(), 3)
     s7 = Segment("G", parent=self.s1)
     self.assertEqual(self.s1.upperBoundSubstitutionCost(), 4)
示例#4
0
 def testRearrangementAmbiguity(self):
     self.assertEqual(self.s1.rearrangementAmbiguity(), 1)
     self.assertEqual(self.s2.rearrangementAmbiguity(), 0)
     self.assertEqual(self.s3.rearrangementAmbiguity(), 0)
     self.s3.createBond(Segment().left)
     self.assertEqual(self.s3.rearrangementAmbiguity(), 1)
     self.assertEqual(self.s4.rearrangementAmbiguity(), 0)
示例#5
0
 def testSubstitutionAmbiguity(self):
     self.assertEqual(self.s1.substitutionAmbiguity(), 0)
     self.assertEqual(self.s2.substitutionAmbiguity(), 0)
     self.assertEqual(self.s3.substitutionAmbiguity(), 0)
     self.assertEqual(self.s4.substitutionAmbiguity(), 0)
     s5 = Segment("T", parent=self.s1)
     self.assertEqual(self.s1.substitutionAmbiguity(), 1)
示例#6
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     #Creates a very basic branch-tree
     self.s1 = Segment("A")
     self.s2 = Segment("A")
     self.s3 = Segment()
     self.s4 = Segment("T")
     self.s1.createBranch(self.s2)
     self.s1.createBranch(self.s3)
     self.s3.createBranch(self.s4)
示例#7
0
 def testAncestor(self):
     self.assertEqual(self.s1.ancestor(), self.s1)
     self.assertEqual(self.s2.ancestor(), self.s1)
     self.assertEqual(self.s3.ancestor(), self.s1)
     self.assertEqual(self.s4.ancestor(), self.s1)
     self.assertEqual(self.s5.ancestor(), self.s1)
     self.s3.createBond(Segment().left)
     self.assertEqual(self.s4.ancestor(), self.s3)
     self.assertEqual(self.s5.ancestor(), self.s3)
示例#8
0
class SegmentTest(unittest.TestCase):
    """Tests the segment and associated label classes, including testing label functionality, but ignoring sides, which are 
    tested in sideTest.py"""
    
    def setUp(self):
        unittest.TestCase.setUp(self)
        #Creates a very basic branch-tree
        self.s1 = Segment("A")
        self.s2 = Segment("A")
        self.s3 = Segment()
        self.s4 = Segment("T")
        self.s1.createBranch(self.s2)
        self.s1.createBranch(self.s3)
        self.s3.createBranch(self.s4)
    
    def tearDown(self):
        unittest.TestCase.tearDown(self)
        
    def testChildren(self):
        self.assertEqual(self.s1.children, set([ self.s2, self.s3 ]))
        self.assertEqual(self.s2.children, set())
        self.assertEqual(self.s3.children, set([ self.s4 ]))
        self.assertEqual(self.s4.children, set())
        
    def testParent(self):
        self.assertEqual(self.s1.parent, None)
        self.assertEqual(self.s2.parent, self.s1)
        self.assertEqual(self.s3.parent, self.s1)
        self.assertEqual(self.s4.parent, self.s3)
    
    def testDeleteBranch(self):
        self.s1.deleteBranch(self.s2)
        self.assertEqual(self.s2.parent, None)
        self.assertEqual(self.s1.children, set([ self.s3 ]))
        self.s1.deleteBranch(self.s3)
        self.assertEqual(self.s3.parent, None)
        self.assertEqual(self.s1.children, set())
        
    def testDisconnect(self):
        self.s3.disconnect()
        self.assertEqual(self.s3.parent, None)
        self.assertEqual(self.s2.parent, self.s1)
        self.assertEqual(self.s4.parent, self.s1)
        self.assertEqual(self.s1.children, set([ self.s2, self.s4 ]))
        self.assertEqual(self.s3.children, set())
    
    def testStr(self): 
        self.assertEqual(str(self.s1), "A")
        self.assertEqual(str(self.s2), "A")
        self.assertEqual(str(self.s3), str(None))
        self.assertEqual(str(self.s4), "T")
    
    def testLabel(self): 
        self.assertEqual(self.s1.label, Label("A"))
        self.assertEqual(self.s2.label, Label("A"))
        self.assertEqual(self.s3.label, None)
        self.assertEqual(self.s4.label, Label("T"))
    
    def testDeleteLabel(self): 
        self.s1.deleteLabel()
        self.assertEqual(self.s1.label, None)
        
    def testAncestor(self):
        self.assertEqual(self.s1.ancestor(), self.s1)
        self.assertEqual(self.s2.ancestor(), self.s1)
        self.assertEqual(self.s3.ancestor(), self.s1)
        self.assertEqual(self.s4.ancestor(), self.s1)
        self.s3.label = Label("A")
        self.assertEqual(self.s4.ancestor(), self.s3)
        
    def testLiftedLabels(self):
        """The lifted label function returns the segments that contain the lifting labels
        """
        self.assertEqual(self.s1.liftedLabels(), set([ self.s2, self.s4 ]))
        self.assertEqual(self.s2.liftedLabels(), set())
        self.assertEqual(self.s3.liftedLabels(), set([ self.s4 ]))
        self.assertEqual(self.s4.liftedLabels(), set())
    
    def testNonTrivialLiftedLabels(self):
        self.assertEqual(self.s1.nonTrivialLiftedLabels(), set([ self.s4 ]))
        s5 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.nonTrivialLiftedLabels(), set([ self.s4, s5 ]))
    
    def testSubstitutionAmbiguity(self):
        self.assertEqual(self.s1.substitutionAmbiguity(), 0)
        self.assertEqual(self.s2.substitutionAmbiguity(), 0)
        self.assertEqual(self.s3.substitutionAmbiguity(), 0)
        self.assertEqual(self.s4.substitutionAmbiguity(), 0)
        s5 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.substitutionAmbiguity(), 1)
        
    def testLowerBoundSubstitutionCost(self):
        s5 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 1)
        self.assertEqual(self.s2.lowerBoundSubstitutionCost(), 0)
        self.assertEqual(self.s3.lowerBoundSubstitutionCost(), 0)
        self.assertEqual(self.s4.lowerBoundSubstitutionCost(), 0)
        s6 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 1)
        s7 = Segment("G", parent=self.s1)
        self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 2)
    
    def testUpperBoundSubstitutionCost(self):
        s5 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.upperBoundSubstitutionCost(), 2)
        self.assertEqual(self.s2.upperBoundSubstitutionCost(), 0)
        self.assertEqual(self.s3.upperBoundSubstitutionCost(), 0)
        self.assertEqual(self.s4.upperBoundSubstitutionCost(), 0)
        s6 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.upperBoundSubstitutionCost(), 3)
        s7 = Segment("G", parent=self.s1)
        self.assertEqual(self.s1.upperBoundSubstitutionCost(), 4)
示例#9
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     #Creates a very basic branch-tree
     self.s1 = Segment().left
     self.s2 = Segment().left
     self.s3 = Segment().left
     self.s4 = Segment().left
     self.s5 = Segment().left
     self.s1.segment.createBranch(self.s2.segment)
     self.s1.segment.createBranch(self.s3.segment)
     self.s3.segment.createBranch(self.s4.segment)
     self.s3.segment.createBranch(self.s5.segment)
     
     self.s1B = Segment().left
     self.s2B = Segment().left
     self.s3B = Segment().left
     self.s4B = Segment().left
     self.s5B = Segment().left
     self.s1B.segment.createBranch(self.s2B.segment)
     self.s1B.segment.createBranch(self.s3B.segment)
     self.s3B.segment.createBranch(self.s4B.segment)
     self.s5B.segment.createBranch(self.s5B.segment)
     
     self.s1.createBond(self.s1B)
     self.s2.createBond(self.s2B)
     self.s4.createBond(self.s4B)
     self.s5.createBond(self.s5B.opposite)
示例#10
0
class SideTest(unittest.TestCase):
    """Tests the segment and associated label classes, including testing label functionality, but ignoring sides, which are 
    tested in sideTest.py"""
    
    def setUp(self):
        unittest.TestCase.setUp(self)
        #Creates a very basic branch-tree
        self.s1 = Segment().left
        self.s2 = Segment().left
        self.s3 = Segment().left
        self.s4 = Segment().left
        self.s5 = Segment().left
        self.s1.segment.createBranch(self.s2.segment)
        self.s1.segment.createBranch(self.s3.segment)
        self.s3.segment.createBranch(self.s4.segment)
        self.s3.segment.createBranch(self.s5.segment)
        
        self.s1B = Segment().left
        self.s2B = Segment().left
        self.s3B = Segment().left
        self.s4B = Segment().left
        self.s5B = Segment().left
        self.s1B.segment.createBranch(self.s2B.segment)
        self.s1B.segment.createBranch(self.s3B.segment)
        self.s3B.segment.createBranch(self.s4B.segment)
        self.s5B.segment.createBranch(self.s5B.segment)
        
        self.s1.createBond(self.s1B)
        self.s2.createBond(self.s2B)
        self.s4.createBond(self.s4B)
        self.s5.createBond(self.s5B.opposite)
    
    def tearDown(self):
        unittest.TestCase.tearDown(self)
        
    def testOpposite(self):
        self.assertEquals(self.s1.opposite, self.s1.segment.right)
        self.assertEquals(self.s2.opposite, self.s2.segment.right)
        
    def testChildren(self):
        self.assertEqual(set(self.s1.children()), set([ self.s2, self.s3 ]))
        self.assertEqual(set(self.s2.children()), set())
        self.assertEqual(set(self.s3.children()), set([ self.s4, self.s5 ]))
        self.assertEqual(set(self.s4.children()), set())
        
    def testParent(self):
        self.assertEqual(self.s1.parent(), None)
        self.assertEqual(self.s2.parent(), self.s1)
        self.assertEqual(self.s3.parent(), self.s1)
        self.assertEqual(self.s4.parent(), self.s3)
    
    def testCreateAndDeleteBond(self):
        self.assertEqual(self.s1.bond, self.s1B)
        self.assertEqual(self.s1B.bond, self.s1)
        self.s1.deleteBond()
        self.assertEqual(self.s1.bond, None)
        self.assertEqual(self.s1B.bond, None)
        
    def testAncestor(self):
        self.assertEqual(self.s1.ancestor(), self.s1)
        self.assertEqual(self.s2.ancestor(), self.s1)
        self.assertEqual(self.s3.ancestor(), self.s1)
        self.assertEqual(self.s4.ancestor(), self.s1)
        self.assertEqual(self.s5.ancestor(), self.s1)
        self.s3.createBond(Segment().left)
        self.assertEqual(self.s4.ancestor(), self.s3)
        self.assertEqual(self.s5.ancestor(), self.s3)
        
    def testIsJunction(self):
        self.assertTrue(self.s1.isJunction())
        self.assertTrue(not self.s2.isJunction())
        self.assertTrue(self.s3.isJunction())
        self.assertTrue(not self.s4.isJunction())
        self.assertTrue(not self.s5.isJunction())
        
    def testLiftedBonds(self):
        """The lifted bond function returns the segments that contain the lifting Bonds
        """
        self.assertEqual(self.s1.liftedBonds(), set([ self.s2, self.s4, self.s5 ]))
        self.assertEqual(self.s2.liftedBonds(), set())
        self.assertEqual(self.s3.liftedBonds(), set([ self.s4, self.s5 ]))
        self.assertEqual(self.s4.liftedBonds(), set())
        self.assertEqual(self.s5.liftedBonds(), set())
    
    def testNonTrivialLiftedBonds(self):
        self.assertEqual(self.s1.nonTrivialLiftedBonds(), set([ self.s4, self.s5 ]))
        self.assertEqual(self.s3.nonTrivialLiftedBonds(), set([ self.s4, self.s5 ]))
        self.assertEqual(self.s4.nonTrivialLiftedBonds(), set())
        
    def testRearrangementAmbiguity(self):
        self.assertEqual(self.s1.rearrangementAmbiguity(), 1)
        self.assertEqual(self.s2.rearrangementAmbiguity(), 0)
        self.assertEqual(self.s3.rearrangementAmbiguity(), 0)
        self.s3.createBond(Segment().left)
        self.assertEqual(self.s3.rearrangementAmbiguity(), 1)
        self.assertEqual(self.s4.rearrangementAmbiguity(), 0)
示例#11
0
 def testNonTrivialLiftedLabels(self):
     self.assertEqual(self.s1.nonTrivialLiftedLabels(), set([self.s4]))
     s5 = Segment("T", parent=self.s1)
     self.assertEqual(self.s1.nonTrivialLiftedLabels(), set([self.s4, s5]))
示例#12
0
class SegmentTest(unittest.TestCase):
    """Tests the segment and associated label classes, including testing label functionality, but ignoring sides, which are 
    tested in sideTest.py"""
    def setUp(self):
        unittest.TestCase.setUp(self)
        #Creates a very basic branch-tree
        self.s1 = Segment("A")
        self.s2 = Segment("A")
        self.s3 = Segment()
        self.s4 = Segment("T")
        self.s1.createBranch(self.s2)
        self.s1.createBranch(self.s3)
        self.s3.createBranch(self.s4)

    def tearDown(self):
        unittest.TestCase.tearDown(self)

    def testChildren(self):
        self.assertEqual(self.s1.children, set([self.s2, self.s3]))
        self.assertEqual(self.s2.children, set())
        self.assertEqual(self.s3.children, set([self.s4]))
        self.assertEqual(self.s4.children, set())

    def testParent(self):
        self.assertEqual(self.s1.parent, None)
        self.assertEqual(self.s2.parent, self.s1)
        self.assertEqual(self.s3.parent, self.s1)
        self.assertEqual(self.s4.parent, self.s3)

    def testDeleteBranch(self):
        self.s1.deleteBranch(self.s2)
        self.assertEqual(self.s2.parent, None)
        self.assertEqual(self.s1.children, set([self.s3]))
        self.s1.deleteBranch(self.s3)
        self.assertEqual(self.s3.parent, None)
        self.assertEqual(self.s1.children, set())

    def testDisconnect(self):
        self.s3.disconnect()
        self.assertEqual(self.s3.parent, None)
        self.assertEqual(self.s2.parent, self.s1)
        self.assertEqual(self.s4.parent, self.s1)
        self.assertEqual(self.s1.children, set([self.s2, self.s4]))
        self.assertEqual(self.s3.children, set())

    def testStr(self):
        self.assertEqual(str(self.s1), "A")
        self.assertEqual(str(self.s2), "A")
        self.assertEqual(str(self.s3), str(None))
        self.assertEqual(str(self.s4), "T")

    def testLabel(self):
        self.assertEqual(self.s1.label, Label("A"))
        self.assertEqual(self.s2.label, Label("A"))
        self.assertEqual(self.s3.label, None)
        self.assertEqual(self.s4.label, Label("T"))

    def testDeleteLabel(self):
        self.s1.deleteLabel()
        self.assertEqual(self.s1.label, None)

    def testAncestor(self):
        self.assertEqual(self.s1.ancestor(), self.s1)
        self.assertEqual(self.s2.ancestor(), self.s1)
        self.assertEqual(self.s3.ancestor(), self.s1)
        self.assertEqual(self.s4.ancestor(), self.s1)
        self.s3.label = Label("A")
        self.assertEqual(self.s4.ancestor(), self.s3)

    def testLiftedLabels(self):
        """The lifted label function returns the segments that contain the lifting labels
        """
        self.assertEqual(self.s1.liftedLabels(), set([self.s2, self.s4]))
        self.assertEqual(self.s2.liftedLabels(), set())
        self.assertEqual(self.s3.liftedLabels(), set([self.s4]))
        self.assertEqual(self.s4.liftedLabels(), set())

    def testNonTrivialLiftedLabels(self):
        self.assertEqual(self.s1.nonTrivialLiftedLabels(), set([self.s4]))
        s5 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.nonTrivialLiftedLabels(), set([self.s4, s5]))

    def testSubstitutionAmbiguity(self):
        self.assertEqual(self.s1.substitutionAmbiguity(), 0)
        self.assertEqual(self.s2.substitutionAmbiguity(), 0)
        self.assertEqual(self.s3.substitutionAmbiguity(), 0)
        self.assertEqual(self.s4.substitutionAmbiguity(), 0)
        s5 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.substitutionAmbiguity(), 1)

    def testLowerBoundSubstitutionCost(self):
        s5 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 1)
        self.assertEqual(self.s2.lowerBoundSubstitutionCost(), 0)
        self.assertEqual(self.s3.lowerBoundSubstitutionCost(), 0)
        self.assertEqual(self.s4.lowerBoundSubstitutionCost(), 0)
        s6 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 1)
        s7 = Segment("G", parent=self.s1)
        self.assertEqual(self.s1.lowerBoundSubstitutionCost(), 2)

    def testUpperBoundSubstitutionCost(self):
        s5 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.upperBoundSubstitutionCost(), 2)
        self.assertEqual(self.s2.upperBoundSubstitutionCost(), 0)
        self.assertEqual(self.s3.upperBoundSubstitutionCost(), 0)
        self.assertEqual(self.s4.upperBoundSubstitutionCost(), 0)
        s6 = Segment("T", parent=self.s1)
        self.assertEqual(self.s1.upperBoundSubstitutionCost(), 3)
        s7 = Segment("G", parent=self.s1)
        self.assertEqual(self.s1.upperBoundSubstitutionCost(), 4)