QhullLinkedList_test.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2009-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/qhulltest/QhullLinkedList_test.cpp#2 $$Change: 1342 $
00005 ** $DateTime: 2011/03/07 21:55:47 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 //pre-compiled headers
00010 #include <QtCore/QList>
00011 #include "../road/RoadTest.h"
00012 
00013 #include "QhullLinkedList.h"
00014 #include "Qhull.h"
00015 
00016 namespace orgQhull {
00017 
00018 class QhullLinkedList_test : public RoadTest
00019 {
00020     Q_OBJECT
00021 
00022 #//Test slots
00023 private slots:
00024     void cleanup();
00025     void t_construct();
00026     void t_convert();
00027     void t_element();
00028     void t_search();
00029     void t_iterator();
00030     void t_const_iterator();
00031     void t_QhullLinkedList_iterator();
00032     void t_io();
00033 };//QhullLinkedList_test
00034 
00035 void
00036 add_QhullLinkedList_test()
00037 {
00038     new QhullLinkedList_test();
00039 }
00040 
00041 //Executed after each testcase
00042 void QhullLinkedList_test::
00043 cleanup()
00044 {
00045     UsingLibQhull::checkQhullMemoryEmpty();
00046     RoadTest::cleanup();
00047 }
00048 
00049 void QhullLinkedList_test::
00050 t_construct()
00051 {
00052     // QhullLinkedList vs; //private (compiler error).  No memory allocation
00053     RboxPoints rcube("c");
00054     {
00055         Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00056         QCOMPARE(q.facetCount(), 12);
00057         QhullVertexList vs = QhullVertexList(q.beginVertex(), q.endVertex());
00058         QCOMPARE(vs.count(), 8);
00059         QCOMPARE(vs.size(), 8u);
00060         QVERIFY(!vs.isEmpty());
00061         QhullVertexList vs2 = q.vertexList();
00062         QCOMPARE(vs2.count(), 8);
00063         QCOMPARE(vs2.size(),8u);
00064         QVERIFY(!vs2.isEmpty());
00065         QVERIFY(!vs2.empty());
00066         QVERIFY(vs==vs2);
00067         // vs= vs2; // disabled.  Would not copy the vertices
00068         QhullVertexList vs3= vs2; // copy constructor
00069         QVERIFY(vs3==vs2);
00070     }
00071 }//t_construct
00072 
00073 void QhullLinkedList_test::
00074 t_convert()
00075 {
00076     RboxPoints rcube("c");
00077     {
00078         Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00079         QCOMPARE(q.facetCount(), 12);
00080         QhullVertexList vs = q.vertexList();
00081         QCOMPARE(vs.size(), 8u);
00082         QVERIFY(!vs.isEmpty());
00083         QVERIFY(!vs.empty());
00084         std::vector<QhullVertex> vs2= vs.toStdVector();
00085         QCOMPARE(vs2.size(), vs.size());
00086         QhullVertexList::Iterator i= vs.begin();
00087         for(int k= 0; k<(int)vs2.size(); k++){
00088             QCOMPARE(vs2[k], *i++);
00089         }
00090         QList<QhullVertex> vs3= vs.toQList();
00091         QCOMPARE(vs3.count(), vs.count());
00092         i= vs.begin();
00093         for(int k= 0; k<vs3.count(); k++){
00094             QCOMPARE(vs3[k], *i++);
00095         }
00096         QhullVertexList vs4(q.endVertex(), q.endVertex());
00097         QVERIFY(vs4.isEmpty());
00098         QVERIFY(vs==vs);
00099         QVERIFY(vs4==vs4);
00100         QVERIFY(vs!=vs4);
00101     }
00102 }//t_convert
00103 
00104 //ReadOnly tested by t_convert
00105 
00106 void QhullLinkedList_test::
00107 t_element()
00108 {
00109     RboxPoints rcube("c");
00110     Qhull q(rcube,"QR0");  // rotated unit cube
00111     QhullVertexList vs = q.vertexList();
00112     QhullVertex v= vs.first();
00113     QCOMPARE(v.previous(), QhullVertex(NULL));
00114     QCOMPARE(vs.front(), vs.first());
00115     QhullVertex v2= vs.last();
00116     QCOMPARE(v2.next().next(), QhullVertex(NULL)); // sentinel has NULL next
00117     QCOMPARE(vs.back(), vs.last());
00118 }//t_element
00119 
00120 void QhullLinkedList_test::
00121 t_search()
00122 {
00123     RboxPoints rcube("c");
00124     Qhull q(rcube,"QR0");  // rotated unit cube
00125     QhullVertexList vs = q.vertexList();
00126     QhullVertex v;
00127     QVERIFY(!vs.contains(v));
00128     QCOMPARE(vs.count(v), 0);
00129     QhullVertex v2= *vs.begin();
00130     QhullVertex v3= vs.last();
00131     QVERIFY(vs.contains(v2));
00132     QCOMPARE(vs.count(v2), 1);
00133     QVERIFY(vs.contains(v3));
00134     QCOMPARE(vs.count(v3), 1);
00135 }//t_search
00136 
00137 void QhullLinkedList_test::
00138 t_iterator()
00139 {
00140     RboxPoints rcube("c");
00141     {
00142         Qhull q(rcube,"QR0");  // rotated unit cube
00143         QhullVertexList vs = q.vertexList();
00144         QhullVertexList::Iterator i= vs.begin();
00145         QhullVertexList::iterator i2= vs.begin();
00146         QVERIFY(i==i2);
00147         // No comparisons
00148         i= vs.begin();
00149         QVERIFY(i==i2);
00150         i2= vs.end();
00151         QVERIFY(i!=i2);
00152         QhullVertex v3(*i);
00153         i2--;
00154         QhullVertex v8= *i2;
00155         QhullVertex v= vs.first();
00156         QhullVertex v2= v.next();
00157         QCOMPARE(v3.id(), v.id());
00158         QCOMPARE(v8.id(), vs.last().id());
00159         QhullVertexList::Iterator i3(i2);
00160         QCOMPARE(*i2, *i3);
00161 
00162         (i3= i)++;
00163         QCOMPARE((*i3).id(), v2.id());
00164         QVERIFY(i==i);
00165         QVERIFY(i!=i2);
00166 
00167         QhullVertexList::ConstIterator i4= vs.begin();
00168         QVERIFY(i==i4); // iterator COMP const_iterator
00169         QVERIFY(i4==i); // const_iterator COMP iterator
00170         QVERIFY(i2!=i4);
00171         QVERIFY(i4!=i2);
00172         ++i4;
00173 
00174         i= vs.begin();
00175         i2= vs.begin();
00176         QCOMPARE(i, i2++);
00177         QCOMPARE(*i2, v2);
00178         QCOMPARE(++i, i2);
00179         QCOMPARE(i, i2--);
00180         QCOMPARE(i2, vs.begin());
00181         QCOMPARE(--i, i2);
00182         QCOMPARE(i2 += 8, vs.end());
00183         QCOMPARE(i2 -= 8, vs.begin());
00184         QCOMPARE(i2+0, vs.begin());
00185         QCOMPARE(i2+8, vs.end());
00186         i2 += 8;
00187         i= i2-0;
00188         QCOMPARE(i, i2);
00189         i= i2-8;
00190         QCOMPARE(i, vs.begin());
00191 
00192         //vs.begin end tested above
00193 
00194         // QhullVertexList is const-only
00195     }
00196 }//t_iterator
00197 
00198 void QhullLinkedList_test::
00199 t_const_iterator()
00200 {
00201     RboxPoints rcube("c");
00202     {
00203         Qhull q(rcube,"QR0");  // rotated unit cube
00204         QhullVertexList vs = q.vertexList();
00205         QhullVertexList::ConstIterator i= vs.begin();
00206         QhullVertexList::const_iterator i2= vs.begin();
00207         QVERIFY(i==i2);
00208         i= vs.begin();
00209         QVERIFY(i==i2);
00210         i2= vs.end();
00211         QVERIFY(i!=i2);
00212         QhullVertex v3(*i);
00213         i2--;
00214         QhullVertex v8= *i2;
00215         QhullVertex v= vs.first();
00216         QhullVertex v2= v.next();
00217         QCOMPARE(v3.id(), v.id());
00218         QCOMPARE(v8.id(), vs.last().id());
00219         QhullVertexList::ConstIterator i3(i2);
00220         QCOMPARE(*i2, *i3);
00221 
00222         (i3= i)++;
00223         QCOMPARE((*i3).id(), v2.id());
00224         QVERIFY(i==i);
00225         QVERIFY(i!=i2);
00226 
00227         // See t_iterator for const_iterator COMP iterator
00228 
00229         i= vs.begin();
00230         i2= vs.constBegin();
00231         QCOMPARE(i, i2++);
00232         QCOMPARE(*i2, v2);
00233         QCOMPARE(++i, i2);
00234         QCOMPARE(i, i2--);
00235         QCOMPARE(i2, vs.constBegin());
00236         QCOMPARE(--i, i2);
00237         QCOMPARE(i2 += 8, vs.constEnd());
00238         QCOMPARE(i2 -= 8, vs.constBegin());
00239         QCOMPARE(i2+0, vs.constBegin());
00240         QCOMPARE(i2+8, vs.constEnd());
00241         i2 += 8;
00242         i= i2-0;
00243         QCOMPARE(i, i2);
00244         i= i2-8;
00245         QCOMPARE(i, vs.constBegin());
00246 
00247         // QhullVertexList is const-only
00248     }
00249 }//t_const_iterator
00250 
00251 void QhullLinkedList_test::
00252 t_QhullLinkedList_iterator()
00253 {
00254     RboxPoints rcube("c");
00255     Qhull q(rcube,"QR0");  // rotated unit cube
00256     QhullVertexList vs(q.endVertex(), q.endVertex());
00257     QhullVertexListIterator i= vs;
00258     QCOMPARE(vs.count(), 0);
00259     QVERIFY(!i.hasNext());
00260     QVERIFY(!i.hasPrevious());
00261     i.toBack();
00262     QVERIFY(!i.hasNext());
00263     QVERIFY(!i.hasPrevious());
00264 
00265     QhullVertexList vs2 = q.vertexList();
00266     QhullVertexListIterator i2(vs2);
00267     QCOMPARE(vs2.count(), 8);
00268     i= vs2;
00269     QVERIFY(i2.hasNext());
00270     QVERIFY(!i2.hasPrevious());
00271     QVERIFY(i.hasNext());
00272     QVERIFY(!i.hasPrevious());
00273     i2.toBack();
00274     i.toFront();
00275     QVERIFY(!i2.hasNext());
00276     QVERIFY(i2.hasPrevious());
00277     QVERIFY(i.hasNext());
00278     QVERIFY(!i.hasPrevious());
00279 
00280     // i at front, i2 at end/back, 4 neighbors
00281     QhullVertexList vs3 = q.vertexList(); // same as vs2
00282     QhullVertex v3(vs3.first());
00283     QhullVertex v4= vs3.first();
00284     QCOMPARE(v3, v4);
00285     QVERIFY(v3==v4);
00286     QhullVertex v5(v4.next());
00287     QVERIFY(v4!=v5);
00288     QhullVertex v6(v5.next());
00289     QhullVertex v7(v6.next());
00290     QhullVertex v8(vs3.last());
00291     QCOMPARE(i2.peekPrevious(), v8);
00292     i2.previous();
00293     i2.previous();
00294     i2.previous();
00295     i2.previous();
00296     QCOMPARE(i2.previous(), v7);
00297     QCOMPARE(i2.previous(), v6);
00298     QCOMPARE(i2.previous(), v5);
00299     QCOMPARE(i2.previous(), v4);
00300     QVERIFY(!i2.hasPrevious());
00301     QCOMPARE(i.peekNext(), v4);
00302     // i.peekNext()= 1.0; // compiler error
00303     QCOMPARE(i.next(), v4);
00304     QCOMPARE(i.peekNext(), v5);
00305     QCOMPARE(i.next(), v5);
00306     QCOMPARE(i.next(), v6);
00307     QCOMPARE(i.next(), v7);
00308     i.next();
00309     i.next();
00310     i.next();
00311     QCOMPARE(i.next(), v8);
00312     QVERIFY(!i.hasNext());
00313     i.toFront();
00314     QCOMPARE(i.next(), v4);
00315 }//t_QhullLinkedList_iterator
00316 
00317 void QhullLinkedList_test::
00318 t_io()
00319 {
00320     RboxPoints rcube("c");
00321     Qhull q(rcube,"QR0");  // rotated unit cube
00322     QhullVertexList vs(q.endVertex(), q.endVertex());
00323     std::cout << "INFO:     empty QhullVertextList" << vs << std::endl;
00324     QhullVertexList vs2= q.vertexList();
00325     std::cout << "INFO:   " << vs2 << std::endl;
00326 }//t_io
00327 
00328 }//namespace orgQhull
00329 
00330 #include "moc/QhullLinkedList_test.moc"
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


libqhull
Author(s): Robert Krug
autogenerated on Tue Jun 18 2013 12:38:50