1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
/****************************************************************************
**
** Copyright (c) 2009-2015 C.B. Barber. All rights reserved.
** $Id: //main/2015/qhull/src/qhulltest/QhullLinkedList_test.cpp#3 $$Change: 2062 $
** $DateTime: 2016/01/17 13:13:18 $$Author: bbarber $
**
****************************************************************************/
//pre-compiled headers
#include <QtCore/QList>
#include "qhulltest/RoadTest.h"
#include "libqhullcpp/QhullLinkedList.h"
#include "libqhullcpp/Qhull.h"
#include "libqhullcpp/QhullVertex.h"
#include "libqhullcpp/RboxPoints.h"
namespace orgQhull {
class QhullLinkedList_test : public RoadTest
{
Q_OBJECT
#//!\name Test slots
private slots:
void cleanup();
void t_construct();
void t_convert();
void t_element();
void t_search();
void t_iterator();
void t_const_iterator();
void t_QhullLinkedList_iterator();
void t_io();
};//QhullLinkedList_test
void
add_QhullLinkedList_test()
{
new QhullLinkedList_test(); // RoadTest::s_testcases
}
//Executed after each testcase
void QhullLinkedList_test::
cleanup()
{
RoadTest::cleanup();
}
void QhullLinkedList_test::
t_construct()
{
// QhullLinkedList vs; //private (compiler error). No memory allocation
RboxPoints rcube("c");
{
Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
QCOMPARE(q.facetCount(), 12);
QhullVertexList vs = QhullVertexList(q.beginVertex(), q.endVertex());
QCOMPARE(vs.count(), 8);
QCOMPARE(vs.size(), 8u);
QVERIFY(!vs.isEmpty());
QhullVertexList vs2 = q.vertexList();
QCOMPARE(vs2.count(), 8);
QCOMPARE(vs2.size(),8u);
QVERIFY(!vs2.isEmpty());
QVERIFY(vs==vs2);
// vs= vs2; // disabled. Would not copy the vertices
QhullVertexList vs3= vs2; // copy constructor
QVERIFY(vs3==vs2);
}
}//t_construct
void QhullLinkedList_test::
t_convert()
{
RboxPoints rcube("c");
{
Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
QCOMPARE(q.facetCount(), 12);
QhullVertexList vs = q.vertexList();
QCOMPARE(vs.size(), 8u);
QVERIFY(!vs.isEmpty());
std::vector<QhullVertex> vs2= vs.toStdVector();
QCOMPARE(vs2.size(), vs.size());
QhullVertexList::Iterator i= vs.begin();
for(int k= 0; k<(int)vs2.size(); k++){
QCOMPARE(vs2[k], *i++);
}
QList<QhullVertex> vs3= vs.toQList();
QCOMPARE(vs3.count(), vs.count());
i= vs.begin();
for(int k= 0; k<vs3.count(); k++){
QCOMPARE(vs3[k], *i++);
}
QhullVertexList vs4(q.endVertex(), q.endVertex());
QVERIFY(vs4.isEmpty());
QVERIFY(vs==vs);
QVERIFY(vs4==vs4);
QVERIFY(vs!=vs4);
}
}//t_convert
//ReadOnly tested by t_convert
void QhullLinkedList_test::
t_element()
{
RboxPoints rcube("c");
Qhull q(rcube,"QR0"); // rotated unit cube
QhullVertexList vs = q.vertexList();
QhullVertex v= vs.first();
QCOMPARE(v.previous(), QhullVertex(NULL));
QCOMPARE(vs.front(), vs.first());
QhullVertex v2= vs.last();
QCOMPARE(v2.next().next(), QhullVertex(NULL)); // sentinel has NULL next
QCOMPARE(vs.back(), v2);
QCOMPARE(vs.back(), vs.last());
}//t_element
void QhullLinkedList_test::
t_search()
{
RboxPoints rcube("c");
Qhull q(rcube,"QR0"); // rotated unit cube
QhullVertexList vs = q.vertexList();
QhullVertex v(q);
QVERIFY(!vs.contains(v));
QCOMPARE(vs.count(v), 0);
QhullVertex v2= *vs.begin();
QhullVertex v3= vs.last();
QVERIFY(vs.contains(v2));
QCOMPARE(vs.count(v2), 1);
QVERIFY(vs.contains(v3));
QCOMPARE(vs.count(v3), 1);
}//t_search
void QhullLinkedList_test::
t_iterator()
{
RboxPoints rcube("c");
{
Qhull q(rcube,"QR0"); // rotated unit cube
QhullVertexList vs = q.vertexList();
QhullVertexList::Iterator i= vs.begin();
QhullVertexList::iterator i2= vs.begin();
QVERIFY(i==i2);
// No comparisons
i= vs.begin();
QVERIFY(i==i2);
i2= vs.end();
QVERIFY(i!=i2);
QhullVertex v3(*i);
i2--;
QhullVertex v8= *i2;
QhullVertex v= vs.first();
QhullVertex v2= v.next();
QCOMPARE(v3.id(), v.id());
QCOMPARE(v8.id(), vs.last().id());
QhullVertexList::Iterator i3(i2);
QCOMPARE(*i2, *i3);
(i3= i)++;
QCOMPARE((*i3).id(), v2.id());
QVERIFY(i==i);
QVERIFY(i!=i2);
QhullVertexList::ConstIterator i4= vs.begin();
QVERIFY(i==i4); // iterator COMP const_iterator
QVERIFY(i4==i); // const_iterator COMP iterator
QVERIFY(i2!=i4);
QVERIFY(i4!=i2);
++i4;
i= vs.begin();
i2= vs.begin();
QCOMPARE(i, i2++);
QCOMPARE(*i2, v2);
QCOMPARE(++i, i2);
QCOMPARE(i, i2--);
QCOMPARE(i2, vs.begin());
QCOMPARE(--i, i2);
QCOMPARE(i2 += 8, vs.end());
QCOMPARE(i2 -= 8, vs.begin());
QCOMPARE(i2+0, vs.begin());
QCOMPARE(i2+8, vs.end());
i2 += 8;
i= i2-0;
QCOMPARE(i, i2);
i= i2-8;
QCOMPARE(i, vs.begin());
//vs.begin end tested above
// QhullVertexList is const-only
}
}//t_iterator
void QhullLinkedList_test::
t_const_iterator()
{
RboxPoints rcube("c");
{
Qhull q(rcube,"QR0"); // rotated unit cube
QhullVertexList vs = q.vertexList();
QhullVertexList::ConstIterator i= vs.begin();
QhullVertexList::const_iterator i2= vs.begin();
QVERIFY(i==i2);
i= vs.begin();
QVERIFY(i==i2);
i2= vs.end();
QVERIFY(i!=i2);
QhullVertex v3(*i);
i2--;
QhullVertex v8= *i2;
QhullVertex v= vs.first();
QhullVertex v2= v.next();
QCOMPARE(v3.id(), v.id());
QCOMPARE(v8.id(), vs.last().id());
QhullVertexList::ConstIterator i3(i2);
QCOMPARE(*i2, *i3);
(i3= i)++;
QCOMPARE((*i3).id(), v2.id());
QVERIFY(i==i);
QVERIFY(i!=i2);
// See t_iterator for const_iterator COMP iterator
i= vs.begin();
i2= vs.constBegin();
QCOMPARE(i, i2++);
QCOMPARE(*i2, v2);
QCOMPARE(++i, i2);
QCOMPARE(i, i2--);
QCOMPARE(i2, vs.constBegin());
QCOMPARE(--i, i2);
QCOMPARE(i2 += 8, vs.constEnd());
QCOMPARE(i2 -= 8, vs.constBegin());
QCOMPARE(i2+0, vs.constBegin());
QCOMPARE(i2+8, vs.constEnd());
i2 += 8;
i= i2-0;
QCOMPARE(i, i2);
i= i2-8;
QCOMPARE(i, vs.constBegin());
// QhullVertexList is const-only
}
}//t_const_iterator
void QhullLinkedList_test::
t_QhullLinkedList_iterator()
{
RboxPoints rcube("c");
Qhull q(rcube,"QR0"); // rotated unit cube
QhullVertexList vs(q.endVertex(), q.endVertex());
QhullVertexListIterator i= vs;
QCOMPARE(vs.count(), 0);
QVERIFY(!i.hasNext());
QVERIFY(!i.hasPrevious());
i.toBack();
QVERIFY(!i.hasNext());
QVERIFY(!i.hasPrevious());
QhullVertexList vs2 = q.vertexList();
QhullVertexListIterator i2(vs2);
QCOMPARE(vs2.count(), 8);
i= vs2;
QVERIFY(i2.hasNext());
QVERIFY(!i2.hasPrevious());
QVERIFY(i.hasNext());
QVERIFY(!i.hasPrevious());
i2.toBack();
i.toFront();
QVERIFY(!i2.hasNext());
QVERIFY(i2.hasPrevious());
QVERIFY(i.hasNext());
QVERIFY(!i.hasPrevious());
// i at front, i2 at end/back, 4 neighbors
QhullVertexList vs3 = q.vertexList(); // same as vs2
QhullVertex v3(vs3.first());
QhullVertex v4= vs3.first();
QCOMPARE(v3, v4);
QVERIFY(v3==v4);
QhullVertex v5(v4.next());
QVERIFY(v4!=v5);
QhullVertex v6(v5.next());
QhullVertex v7(v6.next());
QhullVertex v8(vs3.last());
QCOMPARE(i2.peekPrevious(), v8);
i2.previous();
i2.previous();
i2.previous();
i2.previous();
QCOMPARE(i2.previous(), v7);
QCOMPARE(i2.previous(), v6);
QCOMPARE(i2.previous(), v5);
QCOMPARE(i2.previous(), v4);
QVERIFY(!i2.hasPrevious());
QCOMPARE(i.peekNext(), v4);
// i.peekNext()= 1.0; // compiler error
QCOMPARE(i.next(), v4);
QCOMPARE(i.peekNext(), v5);
QCOMPARE(i.next(), v5);
QCOMPARE(i.next(), v6);
QCOMPARE(i.next(), v7);
i.next();
i.next();
i.next();
QCOMPARE(i.next(), v8);
QVERIFY(!i.hasNext());
i.toFront();
QCOMPARE(i.next(), v4);
}//t_QhullLinkedList_iterator
void QhullLinkedList_test::
t_io()
{
RboxPoints rcube("c");
Qhull q(rcube,"QR0"); // rotated unit cube
QhullVertexList vs(q.endVertex(), q.endVertex());
std::cout << "INFO: empty QhullVertextList" << vs << std::endl;
QhullVertexList vs2= q.vertexList();
std::cout << "INFO: " << vs2 << std::endl;
}//t_io
}//namespace orgQhull
#include "moc/QhullLinkedList_test.moc"
|