Ejemplo n.º 1
0
 def testConsistency(type,nonames=False):
     tempfile = cStringIO.StringIO()
     nodeNames=netio.writeNet_mat(self.simpleWeightedNet,tempfile,type=type)
     if nonames:
         nodeNames=[]
     string1=tempfile.getvalue()
     tempfile.seek(0)
     tempnet=netio.loadNet_mat(tempfile,nodeNames=nodeNames,type=type)
     tempfile = cStringIO.StringIO()
     netio.writeNet_mat(tempnet,tempfile,type=type)
     self.assertEqual(string1,tempfile.getvalue())
Ejemplo n.º 2
0
    def test_writeNet_mat(self):
        tempfile = cStringIO.StringIO() #virtual file
        netio.writeNet_mat(self.simpleWeightedNet,tempfile,type="square")
        self.assertEqual(tempfile.getvalue(),"0\t1.0\t2.0\t3.0\n1.0\t0\t4.0\t0.0\n2.0\t4.0\t0\t0.0\n3.0\t0.0\t0.0\t0\n")

        tempfile = cStringIO.StringIO()
        netio.writeNet_mat(self.simpleWeightedNet,tempfile,type="upperdiag")
        self.assertEqual(tempfile.getvalue(),"0\t1.0\t2.0\t3.0\n\t0\t4.0\t0.0\n\t\t0\t0.0\n\t\t\t0\n")

        tempfile = cStringIO.StringIO()
        netio.writeNet_mat(self.simpleWeightedNet,tempfile,type="supperdiag")
        self.assertEqual(tempfile.getvalue(),"1.0\t2.0\t3.0\n\t4.0\t0.0\n\t\t0.0\n")

        tempfile = cStringIO.StringIO()
        netio.writeNet_mat(self.simpleWeightedNet,tempfile,type="lowerdiag")
        self.assertEqual(tempfile.getvalue(),"0\n1.0\t0\n2.0\t4.0\t0\n3.0\t0.0\t0.0\t0\n")

        tempfile = cStringIO.StringIO()
        netio.writeNet_mat(self.simpleWeightedNet,tempfile,type="slowerdiag")
        self.assertEqual(tempfile.getvalue(),"1.0\n2.0\t4.0\n3.0\t0.0\t0.0\n")