RboxPoints_test.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2006-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/qhulltest/RboxPoints_test.cpp#2 $$Change: 1342 $
00005 ** $DateTime: 2011/03/07 21:55:47 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 //pre-compiled headers
00009 #include <iostream>
00010 #include "../road/RoadTest.h" // QT_VERSION
00011 
00012 #include "RboxPoints.h"
00013 #include "QhullError.h"
00014 
00015 using std::cout;
00016 using std::endl;
00017 using std::ostringstream;
00018 using std::string;
00019 using std::stringstream;
00020 
00021 namespace orgQhull {
00022 
00025 class RboxPoints_test : public RoadTest
00026 {
00027     Q_OBJECT
00028 
00029 #//Test slots
00030 private slots:
00031     void t_construct();
00032     void t_error();
00033     void t_test();
00034     void t_getSet();
00035     void t_foreach();
00036     void t_change();
00037     void t_ostream();
00038 };
00039 
00040 void
00041 add_RboxPoints_test()
00042 {
00043     new RboxPoints_test();
00044 }
00045 
00046 void RboxPoints_test::
00047 t_construct()
00048 {
00049     RboxPoints rp;
00050     QCOMPARE(rp.dimension(), 0);
00051     QCOMPARE(rp.count(), 0);
00052     QVERIFY(QString::fromStdString(rp.comment()) != QString(""));
00053     QVERIFY(rp.isEmpty());
00054     QVERIFY(!rp.hasRboxMessage());
00055     QCOMPARE(rp.rboxStatus(), qh_ERRnone);
00056     QCOMPARE(QString::fromStdString(rp.rboxMessage()), QString("rbox warning: no points generated\n"));
00057 
00058     RboxPoints rp2("c"); // 3-d cube
00059     QCOMPARE(rp2.dimension(), 3);
00060     QCOMPARE(rp2.count(), 8);
00061     QCOMPARE(QString::fromStdString(rp2.comment()), QString("rbox \"c\""));
00062     QVERIFY(!rp2.isEmpty());
00063     QVERIFY(!rp2.hasRboxMessage());
00064     QCOMPARE(rp2.rboxStatus(), qh_ERRnone);
00065     QCOMPARE(QString::fromStdString(rp2.rboxMessage()), QString("rbox: OK\n"));
00066 }//t_construct
00067 
00068 void RboxPoints_test::
00069 t_error()
00070 {
00071     RboxPoints rp;
00072     try{
00073         rp.appendPoints("D0 c");
00074         QFAIL("'D0 c' did not fail.");
00075     }catch (const std::exception &e) {
00076         const char *s= e.what();
00077         cout << "INFO   : Caught " << s;
00078         QCOMPARE(QString(s).left(6), QString("QH6189"));
00079         QVERIFY(rp.hasRboxMessage());
00080         QCOMPARE(QString::fromStdString(rp.rboxMessage()).left(8), QString("rbox err"));
00081         QCOMPARE(rp.rboxStatus(), 6189);
00082         rp.clearRboxMessage();
00083         QVERIFY(!rp.hasRboxMessage());
00084     }
00085     try{
00086         RboxPoints rp2;
00087         rp2.setDimension(-1);
00088         QFAIL("setDimension(-1) did not fail.");
00089     }catch (const RoadError &e) {
00090         const char *s= e.what();
00091         cout << "INFO   : Caught " << s;
00092         QCOMPARE(QString(s).left(7), QString("QH10062"));
00093         QCOMPARE(e.errorCode(), 10062);
00094         QCOMPARE(QString::fromStdString(e.what()), QString(s));
00095         RoadLogEvent logEvent= e.roadLogEvent();
00096         QCOMPARE(logEvent.int1(), -1);
00097     }
00098 }//t_error
00099 
00100 void RboxPoints_test::
00101 t_test()
00102 {
00103     // isEmpty -- t_construct
00104 }//t_test
00105 
00106 void RboxPoints_test::
00107 t_getSet()
00108 {
00109     // comment -- t_construct
00110     // count -- t_construct
00111     // dimension -- t_construct
00112 
00113     RboxPoints rp;
00114     QCOMPARE(rp.dimension(), 0);
00115     rp.setDimension(2);
00116     QCOMPARE(rp.dimension(), 2);
00117     rp.setDimension(2);
00118     QCOMPARE(rp.dimension(), 2);
00119     try{
00120         rp.setDimension(102);
00121         QFAIL("setDimension(102) did not fail.");
00122     }catch (const std::exception &e) {
00123         cout << "INFO   : Caught " << e.what();
00124     }
00125     QCOMPARE(rp.newCount(), 0);
00126     rp.appendPoints("D2 P1 P2");
00127     QCOMPARE(rp.count(), 2);
00128     QCOMPARE(rp.newCount(), 2); // From previous appendPoints();
00129     PointCoordinates pc(2);
00130     pc << 1.0 << 0.0 << 2.0 << 0.0;
00131     QCOMPARE(pc.dimension(), 2);
00132     QCOMPARE(pc.count(), 2);
00133     QVERIFY(rp==pc);
00134     rp.setNewCount(10);  // Normally only used by appendPoints for rbox processing
00135     QCOMPARE(rp.newCount(), 10);
00136     rp.reservePoints();
00137     QVERIFY(rp==pc);
00138 }//t_getSet
00139 
00140 void RboxPoints_test::
00141 t_foreach()
00142 {
00143     RboxPoints rp("c");
00144     Coordinates::ConstIterator cci= rp.beginCoordinates();
00145     orgQhull::Coordinates::Iterator ci= rp.beginCoordinates();
00146     QCOMPARE(*cci, -0.5);
00147     QCOMPARE(*ci, *cci);
00148     int i=1;
00149     while(++cci<rp.endCoordinates()){
00150         QVERIFY(++ci<rp.endCoordinates());
00151         QCOMPARE(*cci, *ci);
00152         i++;
00153     }
00154     QVERIFY(++ci==rp.endCoordinates());
00155     QCOMPARE(i, 8*3);
00156     orgQhull::Coordinates::Iterator ci4= rp.beginCoordinates(4);
00157     QCOMPARE(rp.endCoordinates()-ci4, 4*3);
00158     orgQhull::Coordinates::ConstIterator cci4= rp.beginCoordinates(4);
00159     orgQhull::Coordinates::ConstIterator cci5= rp.endCoordinates();
00160     QCOMPARE(cci5-cci4, 4*3);
00161 }//t_foreach
00162 
00163 void RboxPoints_test::
00164 t_change()
00165 {
00166     RboxPoints rp("c D2");
00167     stringstream s;
00168     s << "4 count" << endl;
00169     s << "2 dimension" << endl;
00170     s << "1 2 3 4 5 6 7 8" << endl;
00171     rp.appendPoints(s);
00172     QCOMPARE(rp.count(), 8);
00173     orgQhull::Coordinates::Iterator ci= rp.beginCoordinates(7);
00174     QCOMPARE(*ci, 7.0);
00175     try{
00176         stringstream s2;
00177         s2 << "4 count" << endl;
00178         s2 << "2 dimension" << endl;
00179         s2 << "1 2 3 4 5 6 7 " << endl;
00180         rp.appendPoints(s2);
00181         QFAIL("incomplete appendPoints() did not fail.");
00182     }catch (const std::exception &e) {
00183         cout << "INFO   : Caught " << e.what();
00184     }
00185     RboxPoints rp2;
00186     rp2.append(rp);
00187     QCOMPARE(rp2.count(), 8);
00188     orgQhull::Coordinates::ConstIterator cci2= rp2.beginCoordinates(6);
00189     QCOMPARE(*(cci2+1), 6.0);
00190     rp2.appendPoints("D2 10 P0");
00191     QCOMPARE(rp2.count(), 19);
00192     orgQhull::Coordinates::ConstIterator cie= rp2.beginCoordinates(8);
00193     QCOMPARE(*cie, 0.0);
00194     RboxPoints rp3;
00195     coordT points[] = { 0, 1,1,0,1,1,0,0};
00196     rp3.setDimension(2);
00197     rp3.append(8,points);
00198     QCOMPARE(rp3.count(), 4);
00199     orgQhull::Coordinates::Iterator ci3= rp3.beginCoordinates(3);
00200     QCOMPARE(*ci3, 0.0);
00201 }//t_change
00202 
00203 void RboxPoints_test::
00204 t_ostream()
00205 {
00206     RboxPoints rp("c D2");
00207     ostringstream oss;
00208     oss << rp;
00209     string s= oss.str();
00210     QString qs= QString::fromStdString(s);
00211     QCOMPARE(qs.count("-0.5"), 4);
00212 }//t_ostream
00213 
00214 }//orgQhull
00215 
00216 #include "moc/RboxPoints_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