00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <iostream>
00010 using std::cout;
00011 using std::endl;
00012 #include "../road/RoadTest.h"
00013
00014 #include "QhullPoint.h"
00015
00016 #include "Qhull.h"
00017
00018 namespace orgQhull {
00019
00020 class Point_test : public RoadTest
00021 {
00022 Q_OBJECT
00023
00024 #//Test slots
00025 private slots:
00026 void initTestCase();
00027 void t_construct();
00028 void t_getset();
00029 void t_operator();
00030 void t_const_iterator();
00031 void t_iterator();
00032 void t_point_iterator();
00033
00034
00035 };
00036
00037 void
00038 add_Point_test()
00039 {
00040 new Point_test();
00041 }
00042
00043 void Point_test::
00044 initTestCase(){
00045 RboxPoints rcube("c");
00046 Qhull q(rcube, "");
00047 UsingQhullLib::setGlobals();
00048 }
00049
00050 void Point_test::
00051 t_construct()
00052 {
00053 QhullPoint p;
00054 QCOMPARE(p.dimension(), 0);
00055 coordT c[]= {0.0, 1.0, 2.0};
00056 QhullPoint p2;
00057 p2.defineAs(3, c);
00058 QCOMPARE(p2.dimension(), 3);
00059 QCOMPARE(p2.coordinates(), c);
00060 coordT c2[]= {0.0, 1.0, 2.0};
00061 QhullPoint p3(3, c2);
00062 QVERIFY(p3==p2);
00063 QhullPoint p5(p3);
00064 QVERIFY(p5==p3);
00065 }
00066
00067 void Point_test::
00068 t_getset()
00069 {
00070 coordT c[]= {0.0, 1.0, 2.0};
00071 QhullPoint p(3, c);
00072 QCOMPARE(p.coordinates(), c);
00073 QCOMPARE(p.dimension(), 3);
00074 QCOMPARE(p[2], 2.0);
00075 QhullPoint p2(p);
00076 p2.defineAs(p);
00077 QVERIFY(p2==p);
00078 QVERIFY(p2.coordinates()==p.coordinates());
00079 QVERIFY(p2.dimension()==p.dimension());
00080 p2.setDimension(2);
00081 QCOMPARE(p2.dimension(), 2);
00082 QVERIFY(p2!=p);
00083 coordT c2[]= {0.0, 1.0};
00084 p2.setCoordinates(c2);
00085 QCOMPARE(p2.coordinates(), c2);
00086 p.defineAs(2, c);
00087 QVERIFY(p2==p);
00088 QCOMPARE(p[1], 1.0);
00089 }
00090
00091 void Point_test::
00092 t_operator()
00093 {
00094 QhullPoint p;
00095 QhullPoint p2(p);
00096 QVERIFY(p==p2);
00097 QVERIFY(!(p!=p2));
00098 coordT c[]= {0.0, 1.0, 2.0};
00099 QhullPoint p3(3, c);
00100 QVERIFY(p3!=p2);
00101 QhullPoint p4(p3);
00102 QVERIFY(p4==p3);
00103 coordT c5[]= {5.0, 6.0, 7.0};
00104 QhullPoint p5(3, c5);
00105 QVERIFY(p5!=p3);
00106 QCOMPARE(p5[1], 6.0);
00107 QCOMPARE(p5[0], 5.0);
00108 const coordT *c0= &p5[0];
00109 QCOMPARE(*c0, 5.0);
00110 }
00111
00112 void Point_test::
00113 t_const_iterator()
00114 {
00115 coordT c[]= {1.0, 2.0, 3.0};
00116 QhullPoint p(3, c);
00117 QhullPoint::const_iterator i(p.coordinates());
00118 QhullPoint::const_iterator i2= p.coordinates();
00119 QVERIFY(i==i2);
00120 QVERIFY(i>=i2);
00121 QVERIFY(i<=i2);
00122 QCOMPARE(*i, 1.0);
00123 QCOMPARE(*(i+1), 2.0);
00124 QCOMPARE(*(i+1), i[1]);
00125 i= p.end();
00126 QVERIFY(i!=i2);
00127 i= i2;
00128 QVERIFY(i==i2);
00129 i= p.end();
00130 i= p.begin();
00131 QCOMPARE(*i, 1.0);
00132 QhullPoint::ConstIterator i3= p.end();
00133 QCOMPARE(*(i3-1), 3.0);
00134 QCOMPARE(*(i3-1), i3[-1]);
00135 QVERIFY(i!=i3);
00136 QVERIFY(i<i3);
00137 QVERIFY(i<=i3);
00138 QVERIFY(i3>i);
00139 QVERIFY(i3>=i);
00140 }
00141
00142
00143 void Point_test::
00144 t_iterator()
00145 {
00146 coordT c[]= {1.0, 2.0, 3.0};
00147 QhullPoint p(3, c);
00148 QhullPoint::Iterator i(p.coordinates());
00149 QhullPoint::iterator i2= p.coordinates();
00150 QVERIFY(i==i2);
00151 QVERIFY(i>=i2);
00152 QVERIFY(i<=i2);
00153 QCOMPARE(*i, 1.0);
00154 QCOMPARE(*(i+1), 2.0);
00155 QCOMPARE(*(i+1), i[1]);
00156 i= p.end();
00157 QVERIFY(i!=i2);
00158 i= i2;
00159 QVERIFY(i==i2);
00160 i= p.end();
00161 i= p.begin();
00162 QCOMPARE(*i, 1.0);
00163 QhullPoint::Iterator i3= p.end();
00164 QCOMPARE(*(i3-1), 3.0);
00165 QCOMPARE(*(i3-1), i3[-1]);
00166 QVERIFY(i!=i3);
00167 QVERIFY(i<i3);
00168 QVERIFY(i<=i3);
00169 QVERIFY(i3>i);
00170 QVERIFY(i3>=i);
00171
00172
00173
00174 }
00175
00176 void Point_test::
00177 t_point_iterator()
00178 {
00179 coordT c[]= {1.0, 3.0, 4.0};
00180 QhullPoint p(3, c);
00181 QhullPointIterator i(p);
00182 QhullPointIterator i2= p;
00183 QVERIFY(i2.hasNext());
00184 QVERIFY(!i2.hasPrevious());
00185 QVERIFY(i.hasNext());
00186 QVERIFY(!i.hasPrevious());
00187 i.toBack();
00188 i2.toFront();
00189 QVERIFY(!i.hasNext());
00190 QVERIFY(i.hasPrevious());
00191 QVERIFY(i2.hasNext());
00192 QVERIFY(!i2.hasPrevious());
00193
00194 coordT c2[]= {1.0, 3.0, 4.0};
00195 QhullPoint p2(0, c2);
00196 i2= p2;
00197 QVERIFY(!i2.hasNext());
00198 QVERIFY(!i2.hasPrevious());
00199 i2.toBack();
00200 QVERIFY(!i2.hasNext());
00201 QVERIFY(!i2.hasPrevious());
00202 QCOMPARE(i.peekPrevious(), 4.0);
00203 QCOMPARE(i.previous(), 4.0);
00204 QCOMPARE(i.previous(), 3.0);
00205 QCOMPARE(i.previous(), 1.0);
00206 QVERIFY(!i.hasPrevious());
00207 QCOMPARE(i.peekNext(), 1.0);
00208
00209 QCOMPARE(i.next(), 1.0);
00210 QCOMPARE(i.peekNext(), 3.0);
00211 QCOMPARE(i.next(), 3.0);
00212 QCOMPARE(i.next(), 4.0);
00213 QVERIFY(!i.hasNext());
00214 i.toFront();
00215 QCOMPARE(i.next(), 1.0);
00216 }
00217
00218
00219
00220 #if 0
00221
00222 void Point_test::
00223 t_io()
00224 {
00225 QhullPoint p;
00226 cout<< "INFO: empty point" << p << endl;
00227 const coordT c[]= {1.0, 3.0, 4.0};
00228 QhullPoint p2(2, c);
00229 cout<< "INFO: " << p2 << endl;
00230 }
00231
00232 error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class orgQhull::QhullPoint &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAVPoint@orgQhull@@@Z) referenced in function "private: void __thiscall orgQhull::Point_test::t_io(void)" (?t_io@Point_test@orgQhull@@AAEXXZ)
00233
00234 #endif
00235
00236 }
00237
00238 #include "moc/Point_test.moc"