1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | |
---|
4 | import sys |
---|
5 | |
---|
6 | import unittest |
---|
7 | import triang |
---|
8 | |
---|
9 | |
---|
10 | class triangTestCase(unittest.TestCase): |
---|
11 | def setUp(self): |
---|
12 | pass |
---|
13 | |
---|
14 | def tearDown(self): |
---|
15 | pass |
---|
16 | |
---|
17 | def testrectangle(self): |
---|
18 | |
---|
19 | points = [] |
---|
20 | seglist = [] |
---|
21 | segattlist = [] |
---|
22 | holelist = [] |
---|
23 | regionlist = [] |
---|
24 | |
---|
25 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] |
---|
26 | # This will cause a seg fault |
---|
27 | #points = [[0.0,0.0],[0.0,10.0],[3.0,0.0],[3.0,10.0]] |
---|
28 | |
---|
29 | # automatically generate pointattlist |
---|
30 | pointattlist = [] |
---|
31 | for point in points: |
---|
32 | pointattlist.append([]) |
---|
33 | #print "pointattlist",pointattlist |
---|
34 | #pointattlist = [[],[],[],[]] |
---|
35 | trilist = [] |
---|
36 | mode = "Qzcn" |
---|
37 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
38 | pointattlist,segattlist,trilist, mode) |
---|
39 | self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)], |
---|
40 | 'generatedtrianglelist is wrong!') |
---|
41 | #print "data['generatedsegmentlist']",data['generatedsegmentlist'] |
---|
42 | self.failUnless(data['generatedsegmentlist'] ==[(2, 0), (3, 2), (1, 3), |
---|
43 | (0, 1)] |
---|
44 | , 'generatedsegmentlist is wrong!') |
---|
45 | self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0), |
---|
46 | (3.0, 0.0), (3.0, 10.0)], |
---|
47 | ' is wrong!') |
---|
48 | |
---|
49 | #print "data['generatedtriangleneighborlist']", |
---|
50 | #data['generatedtriangleneighborlist'] |
---|
51 | self.failUnless(data['generatedtriangleneighborlist'] ==[(-1, 1, -1), |
---|
52 | (-1, 0, -1)], |
---|
53 | 'generatedtriangleneighborlist is wrong!') |
---|
54 | |
---|
55 | |
---|
56 | def testrectangleII(self): |
---|
57 | |
---|
58 | points = [] |
---|
59 | seglist = [] |
---|
60 | holelist = [] |
---|
61 | regionlist = [] |
---|
62 | |
---|
63 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] |
---|
64 | pointattlist = [[],[],[],[]] |
---|
65 | regionlist.append( (1.2,1.2,5.0) ) |
---|
66 | seglist = [(0,1),(1,3),(3,2),(2,0)] |
---|
67 | segattlist = [0,0,0,0] |
---|
68 | trilist = [] |
---|
69 | mode = "Qzp" |
---|
70 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
71 | pointattlist,segattlist,trilist, mode) |
---|
72 | |
---|
73 | self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)], |
---|
74 | 'trianglelist is wrong!') |
---|
75 | self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3), |
---|
76 | (3, 2), (2, 0)], |
---|
77 | 'segmentlist is wrong!') |
---|
78 | self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0), |
---|
79 | (3.0, 0.0), (3.0, 10.0)], |
---|
80 | ' is wrong!') |
---|
81 | |
---|
82 | def testsegmarker(self): |
---|
83 | |
---|
84 | points = [] |
---|
85 | seglist = [] |
---|
86 | holelist = [] |
---|
87 | regionlist = [] |
---|
88 | |
---|
89 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] |
---|
90 | pointattlist = [[],[],[],[]] |
---|
91 | regionlist.append( (1.2,1.2,5.0) ) |
---|
92 | seglist = [(0,1),(1,3),(3,2),(2,0)] |
---|
93 | segattlist = [1.0,2.0,3.0,4.0] |
---|
94 | trilist = [] |
---|
95 | mode = "Qzp" |
---|
96 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
97 | pointattlist,segattlist,trilist, mode) |
---|
98 | |
---|
99 | self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)], |
---|
100 | 'trianglelist is wrong!') |
---|
101 | self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3), |
---|
102 | (3, 2), (2, 0)], |
---|
103 | 'segmentlist is wrong!') |
---|
104 | self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0), |
---|
105 | (3.0, 0.0), (3.0, 10.0)], |
---|
106 | ' is wrong!') |
---|
107 | self.failUnless(data['generatedsegmentmarkerlist'] ==[1,2,3,4], |
---|
108 | ' is wrong!') |
---|
109 | |
---|
110 | def testbad_region(self): |
---|
111 | |
---|
112 | points = [] |
---|
113 | seglist = [] |
---|
114 | holelist = [] |
---|
115 | regionlist = [(1.2,1.2)] |
---|
116 | |
---|
117 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] |
---|
118 | pointattlist = [[],[],[],[]] |
---|
119 | seglist = [(0,1),(1,3),(3,2),(2,0)] |
---|
120 | segattlist = [0,0,0,0] |
---|
121 | trilist = [] |
---|
122 | mode = "Qzpn" |
---|
123 | try: |
---|
124 | data = triang.genMesh(points,seglist,holelist, |
---|
125 | regionlist,pointattlist,segattlist, |
---|
126 | trilist, mode) |
---|
127 | |
---|
128 | except TypeError: |
---|
129 | pass |
---|
130 | else: |
---|
131 | self.failUnless(0 ==1, |
---|
132 | 'bad region list did not raise error!') |
---|
133 | |
---|
134 | def testregion_with_maxarea(self): |
---|
135 | |
---|
136 | points = [] |
---|
137 | seglist = [] |
---|
138 | holelist = [] |
---|
139 | regionlist = [(3,1,1.0)] |
---|
140 | |
---|
141 | points = [(0.0,0.0),(6.0,0.0),(6.0,6.0),(0.0,6.0)] |
---|
142 | pointattlist = [[],[],[],[]] |
---|
143 | seglist = [(0,1),(1,2),(3,2),(3,0),(0,2)] |
---|
144 | segattlist = [0,0,0,0,0] |
---|
145 | trilist = [] |
---|
146 | mode = "Qzpna36a" |
---|
147 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
148 | pointattlist,segattlist, trilist, mode) |
---|
149 | |
---|
150 | self.failUnless(len(data['generatedtrianglelist']) == 2, |
---|
151 | 'testregion_with_maxarea 1: # of tris is wrong!') |
---|
152 | ## Another test case |
---|
153 | regionlist = [(3,1,1.0),(1,3,1.0,8.0)] |
---|
154 | mode = "Qzp21na36a" |
---|
155 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
156 | pointattlist,segattlist, trilist, mode) |
---|
157 | #print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist']) |
---|
158 | # for Duncan On unix this returns a 7 triangle result. |
---|
159 | # for Duncan on Windows returns a 6 triangle result. |
---|
160 | # for Ole on nautilus this returns 6 |
---|
161 | # for Duncan on nautilus this returns 7 |
---|
162 | # ??, it seems to be the results from triangle that is |
---|
163 | # causing the different results, and we are treating |
---|
164 | # triangle as a back box. |
---|
165 | |
---|
166 | self.failUnless(len(data['generatedtrianglelist']) >= 6, |
---|
167 | 'testregion_with_maxarea 2: # of tris is wrong!') |
---|
168 | ## Another test case |
---|
169 | regionlist = [(3,1,1.0,8.0),(1,3,1.0,8.0)] |
---|
170 | mode = "Qzpna36a" |
---|
171 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
172 | pointattlist,segattlist, trilist, mode) |
---|
173 | #print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist']) |
---|
174 | # On unix this returns a 10 triangle result. |
---|
175 | # Windows returns a 8 triangle result. |
---|
176 | self.failUnless(len(data['generatedtrianglelist']) >= 8, |
---|
177 | 'testregion_with_maxarea 3: # of tris is wrong!') |
---|
178 | |
---|
179 | ## Another test case |
---|
180 | regionlist = [(3,1,1.0),(1,3,1.0,8.0)] |
---|
181 | mode = "Qzpna8a" |
---|
182 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
183 | pointattlist,segattlist, trilist, mode) |
---|
184 | #print "len(data['generatedtrianglelist']",len(data['generatedtrianglelist']) |
---|
185 | # On unix this returns a 10 triangle result. |
---|
186 | # Windows returns a 8 triangle result. |
---|
187 | |
---|
188 | self.failUnless(len(data['generatedtrianglelist']) >= 8, |
---|
189 | 'testregion_with_maxarea 4: # of tris is wrong!') |
---|
190 | |
---|
191 | def testbad_point(self): |
---|
192 | |
---|
193 | holelist = [] |
---|
194 | regionlist = [] |
---|
195 | |
---|
196 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0)] |
---|
197 | pointattlist = [[],[],[],[]] |
---|
198 | seglist = [(0,1),(1,3),(3,2),(2,0)] |
---|
199 | segattlist = [0,0,0,0] |
---|
200 | trilist = [] |
---|
201 | mode = "Qzpn" |
---|
202 | try: |
---|
203 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
204 | pointattlist,segattlist, trilist, mode) |
---|
205 | |
---|
206 | except TypeError: |
---|
207 | pass |
---|
208 | else: |
---|
209 | self.failUnless(0 ==1, |
---|
210 | 'bad point list did not raise error!') |
---|
211 | |
---|
212 | def testbad_hole(self): |
---|
213 | |
---|
214 | holelist = [(9.0)] |
---|
215 | regionlist = [] |
---|
216 | |
---|
217 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] |
---|
218 | pointattlist = [[],[],[],[]] |
---|
219 | seglist = [(0,1),(1,3),(3,2),(2,0)] |
---|
220 | segattlist = [0,0,0,0] |
---|
221 | trilist = [] |
---|
222 | mode = "Qzpn" |
---|
223 | try: |
---|
224 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
225 | pointattlist,segattlist, trilist, mode) |
---|
226 | |
---|
227 | except TypeError: |
---|
228 | pass |
---|
229 | else: |
---|
230 | self.failUnless(0 ==1, |
---|
231 | 'bad hole list did not raise error!') |
---|
232 | |
---|
233 | def testbad_segment(self): |
---|
234 | |
---|
235 | holelist = [] |
---|
236 | regionlist = [] |
---|
237 | |
---|
238 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] |
---|
239 | pointattlist = [[],[],[],[]] |
---|
240 | seglist = [(0,1),(1,3),(3,2),(2)] |
---|
241 | segattlist = [0,0,0,0] |
---|
242 | trilist = [] |
---|
243 | mode = "Qzpn" |
---|
244 | try: |
---|
245 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
246 | pointattlist,segattlist, trilist, mode) |
---|
247 | |
---|
248 | except TypeError: |
---|
249 | pass |
---|
250 | else: |
---|
251 | self.failUnless(0 ==1, |
---|
252 | 'bad segment list did not raise error!') |
---|
253 | |
---|
254 | def testbad_segattlist(self): |
---|
255 | |
---|
256 | holelist = [] |
---|
257 | regionlist = [] |
---|
258 | |
---|
259 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] |
---|
260 | pointattlist = [[],[],[],[]] |
---|
261 | seglist = [(0,1),(1,3),(3,2),(2,0)] |
---|
262 | segattlist = [0,0] |
---|
263 | trilist = [] |
---|
264 | mode = "Qzpn" |
---|
265 | try: |
---|
266 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
267 | pointattlist,segattlist, trilist, mode) |
---|
268 | |
---|
269 | self.failUnless(data['trianglelist'] ==[(1, 0, 2), (2, 3, 1)], |
---|
270 | 'trianglelist is wrong!') |
---|
271 | except TypeError: |
---|
272 | pass |
---|
273 | else: |
---|
274 | self.failUnless(0 ==1, |
---|
275 | 'bad segment attribute list did not raise error!') |
---|
276 | |
---|
277 | def testrectangle_regions(self): |
---|
278 | |
---|
279 | points = [] |
---|
280 | seglist = [] |
---|
281 | holelist = [] |
---|
282 | regionlist = [] |
---|
283 | |
---|
284 | points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)] |
---|
285 | pointattlist = [[],[],[],[]] |
---|
286 | #it seems that |
---|
287 | #triangle only associates one region with a triangle |
---|
288 | regionlist.append( (1.3,1.3,88.33) ) |
---|
289 | regionlist.append( (1.2,1.2,77,55) ) |
---|
290 | seglist = [(0,1),(1,3),(3,2),(2,0)] |
---|
291 | segattlist = [0,0,0,0] |
---|
292 | trilist = [] |
---|
293 | mode = "QAzpq" |
---|
294 | data = triang.genMesh(points,seglist,holelist,regionlist, |
---|
295 | pointattlist,segattlist, trilist, mode) |
---|
296 | |
---|
297 | self.failUnless(data['generatedtriangleattributelist'] ==[[77.0], [77.0], [77.0], [77.0]], |
---|
298 | 'triangleattributelist is wrong!') |
---|
299 | |
---|
300 | |
---|
301 | if __name__ == "__main__": |
---|
302 | |
---|
303 | suite = unittest.makeSuite(triangTestCase,'test') |
---|
304 | runner = unittest.TextTestRunner() |
---|
305 | runner.run(suite) |
---|