~ubuntu-branches/ubuntu/trusty/qhull/trusty-proposed

« back to all changes in this revision

Viewing changes to src/qhulltest/QhullLinkedList_test.cpp

  • Committer: Package Import Robot
  • Author(s): Barak A. Pearlmutter
  • Date: 2014-02-13 11:09:12 UTC
  • mfrom: (8.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20140213110912-ifwyxorlsnnl1ebh
Tags: 2012.1-4
Add convenience link to #include <qhull/qhull.h> to simplify transition.

Show diffs side-by-side

added added

removed removed

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