#!/usr/bin/env python # import sys sys.path.append('..') import tempfile import unittest from mesh import * from loadASCII import * class loadASCIITestCase(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_import_trianglulation(self): a_att = [5,2] d_att =[4,2] f_att = [3,2] e_att = [2,2] a_xy = [0.0, 0.0] a = Vertex ( a_xy[0],a_xy[1], attributes =a_att) d = Vertex (0.0, 4.0, attributes =d_att) f = Vertex (4.0,0.0, attributes =f_att) e = Vertex (1.0,1.0, attributes =e_att) s1 = Segment(a,d, marker = "50") s2 = Segment(d,f, marker = "40") s3 = Segment(a,f, marker = "30") s4 = Segment(a,e, marker = "20") r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 45) m = Mesh(userVertices=[a,d,f,e], userSegments=[s1,s2,s3,s4], regions=[r1]) m.generateMesh("QApza2.1") seg = m.getMeshSegments() points = m.getMeshVertices() fileName = tempfile.mktemp(".txt") #print "fileName",fileName m.exportASCIItrianglulationfile(fileName) dict = import_trianglulation(fileName) os.remove(fileName) #print dict #print "seg",seg for pimport,pactual,pimpatt in map(None,dict['generatedpointlist'],points,dict['generatedpointattributelist']): self.failUnless( pimport == [pactual.x,pactual.y], 'loadASCIITestCase failed. test 1') self.failUnless( pimpatt == pactual.attributes, 'loadASCIITestCase failed. test 1.1') self.failUnless( dict['segmentlist'][0] == [0,1], 'loadASCIITestCase failed. test 3') for segimp,segactual in map(None,dict['generatedsegmentmarkerlist'],seg): self.failUnless( segimp == segactual.marker, 'loadASCIITestCase failed. test 4') self.failUnless( dict['generatedtrianglelist'][0] == [3,2,4], 'loadASCIITestCase failed. test 5') self.failUnless( dict['generatedtriangleneighborlist'][0] == [-1,2,3], 'loadASCIITestCase failed. test 6') self.failUnless( dict['generatedtriangleattributelist'][0] == ["1.3"], 'loadASCIITestCase failed. test 7') def test_import_mesh(self): a_att = [5,2] d_att =[4,2] f_att = [3,2] e_att = [2,2] a_xy = [0.0, 0.0] a = Vertex ( a_xy[0],a_xy[1], attributes =a_att) d = Vertex (0.0, 4.0, attributes =d_att) f = Vertex (4.0,0.0, attributes =f_att) e = Vertex (1.0,1.0, attributes =e_att) s1 = Segment(a,d, marker = "50") s2 = Segment(d,f, marker = "40") s3 = Segment(a,f, marker = "30") s4 = Segment(a,e, marker = "20") r1 = Region(0.3, 0.3,tag = "1.3", maxArea = 36) h1 = Hole(0.2,0.6) m = Mesh(userVertices=[a,d,f,e], userSegments=[s1,s2,s3,s4], regions=[r1], holes=[h1]) seg = m.getUserSegments() points = m.getUserVertices() holes = m.getHoles() regions = m.getRegions() fileName = tempfile.mktemp(".txt") m.exportASCIImeshfile(fileName) #print "***************************fileName", fileName dict = import_mesh(fileName) os.remove(fileName) #print dict for pimport,pactual,pimpatt in map(None,dict['pointlist'],points,dict['pointattributelist']): self.failUnless( pimport == [pactual.x,pactual.y], 'loadASCIITestCase failed. test 1') self.failUnless( pimpatt == pactual.attributes, 'loadASCIITestCase failed. test 1.1') self.failUnless( dict['segmentlist'][0] == [0,1], 'loadASCIITestCase failed. test 3') for segimp,segactual in map(None,dict['segmentmarkerlist'],seg): self.failUnless( segimp == segactual.marker, 'loadASCIITestCase failed. test 4') for holeimp,holeactual in map(None,dict['holelist'],holes): self.failUnless( holeimp == [holeactual.x,holeactual.y], 'loadASCIITestCase failed. test 5') for regimp,regactual,regattimp, regmaxarea in map(None,dict['regionlist'],regions, dict['regionattributelist'], dict['regionmaxarealist']): self.failUnless( regimp == [regactual.x,regactual.y], 'loadASCIITestCase failed. test 6') self.failUnless( regattimp == regactual.getTag(), 'loadASCIITestCase failed. test 7') self.failUnless( regmaxarea == regactual.getMaxArea(), 'loadASCIITestCase failed. test 7') def test_loadxy(self): import os import tempfile fileName = tempfile.mktemp(".xya") file = open(fileName,"w") file.write("title row \n\ 1.0 0.0 10.0 0.0\n\ 0.0 1.0 0.0 10.0\n\ 1.0 0.0 10.4 40.0\n") file.close() #print fileName m = importMeshFromFile(fileName) os.remove(fileName) self.failUnless(m.userVertices[0].x == 1.0, 'loadxy, test 1 failed') self.failUnless(m.userVertices[0].y == 0.0, 'loadxy, test 2 failed') self.failUnless(m.userVertices[0].attributes == [10.0,0.0], 'loadxy, test 2.2 failed') self.failUnless(m.userVertices[1].x == 0.0, 'loadxy, test 3 failed') self.failUnless(m.userVertices[1].y == 1.0, 'loadxy, test 4 failed') self.failUnless(m.userVertices[1].attributes == [0.0,10.0], 'loadxy, test 5 failed') #------------------------------------------------------------- if __name__ == "__main__": suite = unittest.makeSuite(loadASCIITestCase,'test') runner = unittest.TextTestRunner() runner.run(suite)