source: inundation/ga/storm_surge/pmesh/triangmoduleHarness.py @ 651

Last change on this file since 651 was 651, checked in by duncan, 20 years ago

comments

File size: 8.2 KB
Line 
1#!/usr/bin/env python
2#
3
4import unittest
5import triang
6
7class triangTestCase(unittest.TestCase):
8    def setUp(self):
9        pass
10       
11    def tearDown(self):
12        pass
13 
14    def testrectangle(self):
15
16        points = []
17        seglist = []
18        segattlist = []
19        holelist = []
20        regionlist = []
21
22        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
23        # This will cause a seg fault
24        #points = [[0.0,0.0],[0.0,10.0],[3.0,0.0],[3.0,10.0]]
25
26        # automatically generate pointattlist
27        pointattlist = []
28        for point in points:
29            pointattlist.append([])
30        #print "pointattlist",pointattlist
31        #pointattlist = [[],[],[],[]]
32        trilist = []
33        mode = "Qzcn"
34        data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist,trilist, mode)
35        self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
36                        'generatedtrianglelist is wrong!')
37        #print "data['generatedsegmentlist']",data['generatedsegmentlist']
38        self.failUnless(data['generatedsegmentlist'] ==[(2, 0), (3, 2), (1, 3), (0, 1)]
39              ,          'generatedsegmentlist is wrong!')
40        self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0), (3.0, 0.0), (3.0, 10.0)],
41                        ' is wrong!')
42       
43        #print "data['generatedtriangleneighborlist']",data['generatedtriangleneighborlist']
44        self.failUnless(data['generatedtriangleneighborlist'] ==[(-1, 1, -1), (-1, 0, -1)],
45                        'generatedtriangleneighborlist is wrong!')
46
47       
48    def testrectangleII(self):
49
50        points = []
51        seglist = []
52        holelist = []
53        regionlist = []
54
55        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
56        pointattlist = [[],[],[],[]]
57        regionlist.append( (1.2,1.2,5.0) )
58        seglist = [(0,1),(1,3),(3,2),(2,0)]
59        segattlist = [0,0,0,0]
60        trilist = []
61        mode = "Qzp"
62        data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist,trilist, mode)
63       
64        self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
65                        'trianglelist is wrong!')
66        self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3), (3, 2), (2, 0)],
67                        'segmentlist is wrong!')
68        self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0), (3.0, 0.0), (3.0, 10.0)],
69                        ' is wrong!')
70       
71    def testbad_region(self):
72
73        points = []
74        seglist = []
75        holelist = []
76        regionlist = [(1.2,1.2)]
77
78        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
79        pointattlist = [[],[],[],[]]
80        seglist = [(0,1),(1,3),(3,2),(2,0)]
81        segattlist = [0,0,0,0]
82        trilist = []
83        mode = "Qzpn"
84        try:
85            data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
86           
87        except TypeError:
88            pass
89        else:
90            self.failUnless(0 ==1,
91                        'bad region list did not raise error!')
92     
93    def testregion_with_maxarea(self):
94
95        points = []
96        seglist = []
97        holelist = []
98        regionlist = [(3,1,1.0)]
99
100        points = [(0.0,0.0),(6.0,0.0),(6.0,6.0),(0.0,6.0)]
101        pointattlist = [[],[],[],[]]
102        seglist = [(0,1),(1,2),(3,2),(3,0),(0,2)]
103        segattlist = [0,0,0,0,0]
104        trilist = []
105        mode = "Qzpna36a"
106        data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
107        self.failUnless(len(data['generatedtrianglelist']) == 2,
108                        'testregion_with_maxarea 1: # of tris is wrong!')
109        ## Another test case   
110        regionlist = [(3,1,1.0),(1,3,1.0,8.0)]
111        mode = "Qzpna36a"
112        data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
113        self.failUnless(len(data['generatedtrianglelist']) == 6,
114                        'testregion_with_maxarea 2: # of tris is wrong!')
115        ## Another test case   
116        regionlist = [(3,1,1.0,8.0),(1,3,1.0,8.0)]
117        mode = "Qzpna36a"
118        data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
119        self.failUnless(len(data['generatedtrianglelist']) == 8,
120                        'testregion_with_maxarea 3: # of tris is wrong!')
121                 
122        ## Another test case   
123        regionlist = [(3,1,1.0),(1,3,1.0,8.0)]
124        mode = "Qzpna8a"
125        data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
126        self.failUnless(len(data['generatedtrianglelist']) == 8,
127                        'testregion_with_maxarea 4: # of tris is wrong!')
128                 
129                 
130    def testbad_point(self):
131
132        holelist = []
133        regionlist = []
134
135        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0)]
136        pointattlist = [[],[],[],[]]
137        seglist = [(0,1),(1,3),(3,2),(2,0)]
138        segattlist = [0,0,0,0]
139        trilist = []
140        mode = "Qzpn"
141        try:
142            data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
143           
144        except TypeError:
145            pass
146        else:
147            self.failUnless(0 ==1,
148                        'bad point list did not raise error!')
149     
150    def testbad_hole(self):
151
152        holelist = [(9.0)]
153        regionlist = []
154
155        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
156        pointattlist = [[],[],[],[]]
157        seglist = [(0,1),(1,3),(3,2),(2,0)]
158        segattlist = [0,0,0,0]
159        trilist = []
160        mode = "Qzpn"
161        try:
162            data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
163           
164        except TypeError:
165            pass
166        else:
167            self.failUnless(0 ==1,
168                        'bad hole list did not raise error!')
169     
170    def testbad_segment(self):
171
172        holelist = []
173        regionlist = []
174
175        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
176        pointattlist = [[],[],[],[]]
177        seglist = [(0,1),(1,3),(3,2),(2)]
178        segattlist = [0,0,0,0]
179        trilist = []
180        mode = "Qzpn"
181        try:
182            data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
183           
184        except TypeError:
185            pass
186        else:
187            self.failUnless(0 ==1,
188                        'bad segment list did not raise error!')
189     
190    def testbad_segattlist(self):
191
192        holelist = []
193        regionlist = []
194
195        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
196        pointattlist = [[],[],[],[]]
197        seglist = [(0,1),(1,3),(3,2),(2,0)]
198        segattlist = [0,0]
199        trilist = []
200        mode = "Qzpn"
201        try:
202            data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
203           
204            self.failUnless(data['trianglelist'] ==[(1, 0, 2), (2, 3, 1)],
205                        'trianglelist is wrong!')
206        except TypeError:
207            pass
208        else:
209            self.failUnless(0 ==1,
210                        'bad segment attribute list did not raise error!')
211           
212    def testrectangle_regions(self):
213
214        points = []
215        seglist = []
216        holelist = []
217        regionlist = []
218
219        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
220        pointattlist = [[],[],[],[]]
221        #it seems that
222        #triangle only associates one region with a triangle
223        regionlist.append( (1.3,1.3,88.33) )
224        regionlist.append( (1.2,1.2,77,55) )
225        seglist = [(0,1),(1,3),(3,2),(2,0)]
226        segattlist = [0,0,0,0]
227        trilist = []
228        mode = "QAzpq"
229        data = triang.genMesh(points,seglist,holelist,regionlist,pointattlist,segattlist, trilist, mode)
230           
231        self.failUnless(data['generatedtriangleattributelist'] ==[[77.0], [77.0], [77.0], [77.0]],
232                        'triangleattributelist is wrong!')
233       
234       
235if __name__ == "__main__":
236
237    suite = unittest.makeSuite(triangTestCase,'test')
238    runner = unittest.TextTestRunner()
239    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.