QhullFacetList_test.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2008-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/qhulltest/QhullFacetList_test.cpp#2 $$Change: 1342 $
00005 ** $DateTime: 2011/03/07 21:55:47 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 //pre-compiled headers
00010 #include <iostream>
00011 #include "../road/RoadTest.h" // QT_VERSION
00012 
00013 #include "QhullFacetList.h"
00014 #include "QhullError.h"
00015 #include "QhullFacet.h"
00016 #include "QhullVertexSet.h"
00017 #include "Qhull.h"
00018 
00019 using std::cout;
00020 using std::endl;
00021 using std::ostringstream;
00022 using std::ostream;
00023 using std::string;
00024 
00025 namespace orgQhull {
00026 
00027 class QhullFacetList_test : public RoadTest
00028 {
00029     Q_OBJECT
00030 
00031 #//Test slots
00032 private slots:
00033     void cleanup();
00034     void t_construct();
00035     void t_convert();
00036     void t_readonly();
00037     void t_foreach();
00038     void t_io();
00039 };//QhullFacetList_test
00040 
00041 void
00042 add_QhullFacetList_test()
00043 {
00044     new QhullFacetList_test();
00045 }
00046 
00047 //Executed after each testcase
00048 void QhullFacetList_test::
00049 cleanup()
00050 {
00051     UsingLibQhull::checkQhullMemoryEmpty();
00052     RoadTest::cleanup();
00053 }
00054 
00055 void QhullFacetList_test::
00056 t_construct()
00057 {
00058     RboxPoints rcube("c");
00059     Qhull q(rcube,"QR0");  // rotated unit cube
00060     QhullFacetList fs2= q.facetList();
00061     QVERIFY(!fs2.isEmpty());
00062     QCOMPARE(fs2.count(),6);
00063     QhullFacetList fs3(q.endFacet(), q.endFacet());
00064     QVERIFY(fs3.isEmpty());
00065     QhullFacetList fs4(q.endFacet().previous(), q.endFacet());
00066     QCOMPARE(fs4.count(), 1);
00067     QhullFacetList fs5(q.beginFacet(), q.endFacet());
00068     QCOMPARE(fs2.count(), fs5.count());
00069     QVERIFY(fs2==fs5);
00070     QhullFacetList fs6= fs2; // copy constructor
00071     QVERIFY(fs6==fs2);
00072     std::vector<QhullFacet> fv= fs2.toStdVector();
00073     QCOMPARE(fv.size(), 6u);
00074 }//t_construct
00075 
00076 void QhullFacetList_test::
00077 t_convert()
00078 {
00079     RboxPoints rcube("c");
00080     Qhull q(rcube,"QR0 QV2");  // rotated unit cube
00081     QhullFacetList fs2= q.facetList();
00082     QVERIFY(!fs2.isSelectAll());
00083     QVERIFY(!fs2.isEmpty());
00084     QCOMPARE(fs2.count(),3);
00085     std::vector<QhullFacet> fv= fs2.toStdVector();
00086     QCOMPARE(fv.size(), 3u);
00087     QList<QhullFacet> fv2= fs2.toQList();
00088     QCOMPARE(fv2.size(), 3);
00089     std::vector<QhullVertex> fv5= fs2.vertices_toStdVector(q.runId());
00090     QCOMPARE(fv5.size(), 7u);
00091     QList<QhullVertex> fv6= fs2.vertices_toQList(q.runId());
00092     QCOMPARE(fv6.size(), 7);
00093     fs2.selectAll();
00094     QVERIFY(fs2.isSelectAll());
00095     std::vector<QhullFacet> fv3= fs2.toStdVector();
00096     QCOMPARE(fv3.size(), 6u);
00097     QList<QhullFacet> fv4= fs2.toQList();
00098     QCOMPARE(fv4.size(), 6);
00099     std::vector<QhullVertex> fv7= fs2.vertices_toStdVector(q.runId());
00100     QCOMPARE(fv7.size(), 8u);
00101     QList<QhullVertex> fv8= fs2.vertices_toQList(q.runId());
00102     QCOMPARE(fv8.size(), 8);
00103 }//t_convert
00104 
00106 void QhullFacetList_test::
00107 t_readonly()
00108 {
00109     RboxPoints rcube("c");
00110     Qhull q(rcube,"QV0");  // good facets are adjacent to point 0
00111     QhullFacetList fs= q.facetList();
00112     QVERIFY(!fs.isSelectAll());
00113     QCOMPARE(fs.count(), 3);
00114     QCOMPARE(fs.first(), q.firstFacet());
00115     fs.selectAll();
00116     QVERIFY(fs.isSelectAll());
00117     QCOMPARE(fs.count(), 6);
00118     fs.selectGood();
00119     QVERIFY(!fs.isSelectAll());
00120     QCOMPARE(fs.count(), 3);
00121     fs.selectAll();
00122     QVERIFY(fs.isSelectAll());
00123     QCOMPARE(fs.count(), 6);
00124     QhullFacet f= fs.first();
00125     QhullFacet f2= fs.last();
00126     fs.selectAll();
00127     QVERIFY(fs.contains(f));
00128     QVERIFY(fs.contains(f2));
00129     QVERIFY(f.isGood());
00130     QVERIFY(!f2.isGood());
00131     fs.selectGood();
00132     QVERIFY(fs.contains(f));
00133     QVERIFY(!fs.contains(f2));
00134 }//t_readonly
00135 
00136 void QhullFacetList_test::
00137 t_foreach()
00138 {
00139     RboxPoints rcube("c");
00140     // Spot check predicates and accessors.  See QhullLinkedList_test
00141     Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00142     QhullFacetList fs= q.facetList();
00143     QVERIFY(fs.contains(q.firstFacet()));
00144     QhullFacet f= q.firstFacet().next();
00145     QVERIFY(fs.contains(f));
00146     QCOMPARE(fs.first(), *fs.begin());
00147     QCOMPARE(*(fs.end()-1), fs.last());
00148     QCOMPARE(fs.first(), q.firstFacet());
00149     QCOMPARE(*fs.begin(), q.beginFacet());
00150     QCOMPARE(*fs.end(), q.endFacet());
00151 }//t_foreach
00152 
00153 void QhullFacetList_test::
00154 t_io()
00155 {
00156     RboxPoints rcube("c");
00157     {
00158         Qhull q(rcube,"QR0 QV0");   // good facets are adjacent to point 0
00159         QhullFacetList fs= q.facetList();
00160         ostringstream os;
00161         os << fs.print(q.runId()); // Runs all print options
00162         os << "\nFacets only\n" << fs; // printVertices() requires a runId
00163         cout << os.str();
00164         QString facets= QString::fromStdString(os.str());
00165         QCOMPARE(facets.count("(v"), 7+12*3*2);
00166         QCOMPARE(facets.count(QRegExp("f\\d")), 3*7 + 13*3*2);
00167     }
00168 }//t_io
00169 
00170 }//orgQhull
00171 
00172 #include "moc/QhullFacetList_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