QhullLinkedList_test.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2009-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/qhulltest/QhullLinkedList_test.cpp#3 $$Change: 2062 $
5 ** $DateTime: 2016/01/17 13:13:18 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 //pre-compiled headers
10 #include <QtCore/QList>
11 #include "qhulltest/RoadTest.h"
12 
14 #include "libqhullcpp/Qhull.h"
16 #include "libqhullcpp/RboxPoints.h"
17 
18 namespace orgQhull {
19 
20 class QhullLinkedList_test : public RoadTest
21 {
22  Q_OBJECT
23 
24 #
25 private slots:
26  void cleanup();
27  void t_construct();
28  void t_convert();
29  void t_element();
30  void t_search();
31  void t_iterator();
32  void t_const_iterator();
34  void t_io();
35 };//QhullLinkedList_test
36 
37 void
39 {
40  new QhullLinkedList_test(); // RoadTest::s_testcases
41 }
42 
43 //Executed after each testcase
45 cleanup()
46 {
48 }
49 
52 {
53  // QhullLinkedList vs; //private (compiler error). No memory allocation
54  RboxPoints rcube("c");
55  {
56  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
57  QCOMPARE(q.facetCount(), 12);
58  QhullVertexList vs = QhullVertexList(q.beginVertex(), q.endVertex());
59  QCOMPARE(vs.count(), 8);
60  QCOMPARE(vs.size(), 8u);
61  QVERIFY(!vs.isEmpty());
62  QhullVertexList vs2 = q.vertexList();
63  QCOMPARE(vs2.count(), 8);
64  QCOMPARE(vs2.size(),8u);
65  QVERIFY(!vs2.isEmpty());
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 
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  std::vector<QhullVertex> vs2= vs.toStdVector();
84  QCOMPARE(vs2.size(), vs.size());
86  for(int k= 0; k<(int)vs2.size(); k++){
87  QCOMPARE(vs2[k], *i++);
88  }
89  QList<QhullVertex> vs3= vs.toQList();
90  QCOMPARE(vs3.count(), vs.count());
91  i= vs.begin();
92  for(int k= 0; k<vs3.count(); k++){
93  QCOMPARE(vs3[k], *i++);
94  }
95  QhullVertexList vs4(q.endVertex(), q.endVertex());
96  QVERIFY(vs4.isEmpty());
97  QVERIFY(vs==vs);
98  QVERIFY(vs4==vs4);
99  QVERIFY(vs!=vs4);
100  }
101 }//t_convert
102 
103 //ReadOnly tested by t_convert
104 
106 t_element()
107 {
108  RboxPoints rcube("c");
109  Qhull q(rcube,"QR0"); // rotated unit cube
110  QhullVertexList vs = q.vertexList();
111  QhullVertex v= vs.first();
112  QCOMPARE(v.previous(), QhullVertex(NULL));
113  QCOMPARE(vs.front(), vs.first());
114  QhullVertex v2= vs.last();
115  QCOMPARE(v2.next().next(), QhullVertex(NULL)); // sentinel has NULL next
116  QCOMPARE(vs.back(), v2);
117  QCOMPARE(vs.back(), vs.last());
118 }//t_element
119 
121 t_search()
122 {
123  RboxPoints rcube("c");
124  Qhull q(rcube,"QR0"); // rotated unit cube
125  QhullVertexList vs = q.vertexList();
126  QhullVertex v(q);
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 
138 t_iterator()
139 {
140  RboxPoints rcube("c");
141  {
142  Qhull q(rcube,"QR0"); // rotated unit cube
143  QhullVertexList vs = q.vertexList();
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());
160  QCOMPARE(*i2, *i3);
161 
162  (i3= i)++;
163  QCOMPARE((*i3).id(), v2.id());
164  QVERIFY(i==i);
165  QVERIFY(i!=i2);
166 
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 
200 {
201  RboxPoints rcube("c");
202  {
203  Qhull q(rcube,"QR0"); // rotated unit cube
204  QhullVertexList vs = q.vertexList();
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());
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 
253 {
254  RboxPoints rcube("c");
255  Qhull q(rcube,"QR0"); // rotated unit cube
256  QhullVertexList vs(q.endVertex(), q.endVertex());
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 
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"
orgQhull::QhullLinkedList_test::cleanup
void cleanup()
Definition: QhullLinkedList_test.cpp:51
orgQhull::QhullLinkedList::toStdVector
std::vector< T > toStdVector() const
Definition: QhullLinkedList.h:228
orgQhull::QhullLinkedList::end
iterator end()
Definition: QhullLinkedList.h:124
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::QhullVertexList
QhullLinkedList< QhullVertex > QhullVertexList
Definition: QhullVertex.h:34
orgQhull::QhullLinkedList::count
countT count() const
Definition: QhullLinkedList.h:254
orgQhull::QhullLinkedList_test::t_construct
void t_construct()
Definition: QhullLinkedList_test.cpp:57
orgQhull::QhullLinkedList_test
Definition: QhullLinkedList_test.cpp:26
Qhull.h
orgQhull::QhullLinkedList_test::t_iterator
void t_iterator()
Definition: QhullLinkedList_test.cpp:144
orgQhull::QhullVertex
Definition: QhullVertex.h:48
orgQhull::QhullVertex::id
countT id() const
Definition: QhullVertex.h:88
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::QhullLinkedList_test::t_search
void t_search()
Definition: QhullLinkedList_test.cpp:127
orgQhull::QhullLinkedList::iterator
Definition: QhullLinkedList.h:127
orgQhull::QhullLinkedList_test::t_QhullLinkedList_iterator
void t_QhullLinkedList_iterator()
Definition: QhullLinkedList_test.cpp:258
orgQhull::QhullLinkedList::const_iterator
Definition: QhullLinkedList.h:164
orgQhull::QhullLinkedList_test::t_convert
void t_convert()
Definition: QhullLinkedList_test.cpp:80
orgQhull::QhullLinkedList_test::t_io
void t_io()
Definition: QhullLinkedList_test.cpp:324
orgQhull::QhullLinkedList::contains
bool contains(const T &t) const
Definition: QhullLinkedList.h:269
orgQhull::QhullLinkedList::size
size_t size() const
Definition: QhullLinkedList.h:100
q
q
orgQhull::QhullVertexListIterator
QhullLinkedListIterator< QhullVertex > QhullVertexListIterator
Definition: QhullVertex.h:36
orgQhull::QhullLinkedList_test::t_element
void t_element()
Definition: QhullLinkedList_test.cpp:112
orgQhull::QhullLinkedList::begin
iterator begin()
Definition: QhullLinkedList.h:120
orgQhull::RboxPoints
Definition: RboxPoints.h:37
orgQhull::add_QhullLinkedList_test
void add_QhullLinkedList_test()
Definition: QhullLinkedList_test.cpp:44
orgQhull::QhullLinkedList::isEmpty
bool isEmpty() const
Definition: QhullLinkedList.h:97
orgQhull::QhullLinkedList::first
const T & first() const
Definition: QhullLinkedList.h:106
orgQhull::QhullLinkedListIterator
Definition: QhullLinkedList.h:200
RoadTest.h
orgQhull::QhullLinkedList
Definition: QhullLinkedList.h:50
orgQhull::QhullVertex::next
QhullVertex next() const
Definition: QhullVertex.h:92
QhullVertex.h
RboxPoints.h
orgQhull::QhullLinkedList::last
const T last() const
Definition: QhullLinkedList.h:110
orgQhull::RoadTest::cleanup
void cleanup()
Executed after each test.
Definition: RoadTest.cpp:38
orgQhull::QhullLinkedList_test::t_const_iterator
void t_const_iterator()
Definition: QhullLinkedList_test.cpp:205
obb.v
list v
Definition: obb.py:48
QhullLinkedList.h


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:14