1
/****************************************************************************
3
** Copyright (c) 2006-2012 C.B. Barber. All rights reserved.
4
** $Id: //main/2011/qhull/src/qhulltest/RboxPoints_test.cpp#4 $$Change: 1490 $
5
** $DateTime: 2012/02/19 20:27:01 $$Author: bbarber $
7
****************************************************************************/
10
#include "RoadTest.h" // QT_VERSION
12
#include "RboxPoints.h"
13
#include "QhullError.h"
17
using std::ostringstream;
19
using std::stringstream;
23
//! Test C++ interface to Rbox
24
//! See eg/q_test for tests of rbox commands
25
class RboxPoints_test : public RoadTest
43
new RboxPoints_test();
46
void RboxPoints_test::
50
QCOMPARE(rp.dimension(), 0);
51
QCOMPARE(rp.count(), 0);
52
QVERIFY(QString::fromStdString(rp.comment()) != QString(""));
53
QVERIFY(rp.isEmpty());
54
QVERIFY(!rp.hasRboxMessage());
55
QCOMPARE(rp.rboxStatus(), qh_ERRnone);
56
QCOMPARE(QString::fromStdString(rp.rboxMessage()), QString("rbox warning: no points generated\n"));
58
RboxPoints rp2("c"); // 3-d cube
59
QCOMPARE(rp2.dimension(), 3);
60
QCOMPARE(rp2.count(), 8);
61
QCOMPARE(QString::fromStdString(rp2.comment()), QString("rbox \"c\""));
62
QVERIFY(!rp2.isEmpty());
63
QVERIFY(!rp2.hasRboxMessage());
64
QCOMPARE(rp2.rboxStatus(), qh_ERRnone);
65
QCOMPARE(QString::fromStdString(rp2.rboxMessage()), QString("rbox: OK\n"));
68
void RboxPoints_test::
73
rp.appendPoints("D0 c");
74
QFAIL("'D0 c' did not fail.");
75
}catch (const std::exception &e) {
76
const char *s= e.what();
77
cout << "INFO : Caught " << s;
78
QCOMPARE(QString(s).left(6), QString("QH6189"));
79
QVERIFY(rp.hasRboxMessage());
80
QCOMPARE(QString::fromStdString(rp.rboxMessage()).left(8), QString("rbox err"));
81
QCOMPARE(rp.rboxStatus(), 6189);
82
rp.clearRboxMessage();
83
QVERIFY(!rp.hasRboxMessage());
88
QFAIL("setDimension(-1) did not fail.");
89
}catch (const RoadError &e) {
90
const char *s= e.what();
91
cout << "INFO : Caught " << s;
92
QCOMPARE(QString(s).left(7), QString("QH10062"));
93
QCOMPARE(e.errorCode(), 10062);
94
QCOMPARE(QString::fromStdString(e.what()), QString(s));
95
RoadLogEvent logEvent= e.roadLogEvent();
96
QCOMPARE(logEvent.int1(), -1);
100
void RboxPoints_test::
103
// isEmpty -- t_construct
106
void RboxPoints_test::
109
// comment -- t_construct
110
// count -- t_construct
111
// dimension -- t_construct
114
QCOMPARE(rp.dimension(), 0);
116
QCOMPARE(rp.dimension(), 2);
118
QCOMPARE(rp.dimension(), 2);
120
rp.setDimension(102);
121
QFAIL("setDimension(102) did not fail.");
122
}catch (const std::exception &e) {
123
cout << "INFO : Caught " << e.what();
125
QCOMPARE(rp.newCount(), 0);
126
rp.appendPoints("D2 P1 P2");
127
QCOMPARE(rp.count(), 2);
128
QCOMPARE(rp.newCount(), 2); // From previous appendPoints();
129
PointCoordinates pc(2);
130
pc << 1.0 << 0.0 << 2.0 << 0.0;
131
QCOMPARE(pc.dimension(), 2);
132
QCOMPARE(pc.count(), 2);
134
rp.setNewCount(10); // Normally only used by appendPoints for rbox processing
135
QCOMPARE(rp.newCount(), 10);
140
void RboxPoints_test::
144
Coordinates::ConstIterator cci= rp.beginCoordinates();
145
orgQhull::Coordinates::Iterator ci= rp.beginCoordinates();
146
QCOMPARE(*cci, -0.5);
149
while(++cci<rp.endCoordinates()){
150
QVERIFY(++ci<rp.endCoordinates());
154
QVERIFY(++ci==rp.endCoordinates());
156
orgQhull::Coordinates::Iterator ci4= rp.beginCoordinates(4);
157
QCOMPARE(rp.endCoordinates()-ci4, 4*3);
158
orgQhull::Coordinates::ConstIterator cci4= rp.beginCoordinates(4);
159
orgQhull::Coordinates::ConstIterator cci5= rp.endCoordinates();
160
QCOMPARE(cci5-cci4, 4*3);
163
void RboxPoints_test::
166
RboxPoints rp("c D2");
168
s << "4 count" << endl;
169
s << "2 dimension" << endl;
170
s << "1 2 3 4 5 6 7 8" << endl;
172
QCOMPARE(rp.count(), 8);
173
orgQhull::Coordinates::Iterator ci= rp.beginCoordinates(7);
177
s2 << "4 count" << endl;
178
s2 << "2 dimension" << endl;
179
s2 << "1 2 3 4 5 6 7 " << endl;
181
QFAIL("incomplete appendPoints() did not fail.");
182
}catch (const std::exception &e) {
183
cout << "INFO : Caught " << e.what();
187
QCOMPARE(rp2.count(), 8);
188
orgQhull::Coordinates::ConstIterator cci2= rp2.beginCoordinates(6);
189
QCOMPARE(*(cci2+1), 6.0);
190
rp2.appendPoints("D2 10 P0");
191
QCOMPARE(rp2.count(), 19);
192
orgQhull::Coordinates::ConstIterator cie= rp2.beginCoordinates(8);
195
coordT points[] = { 0, 1,1,0,1,1,0,0};
197
rp3.append(8,points);
198
QCOMPARE(rp3.count(), 4);
199
orgQhull::Coordinates::Iterator ci3= rp3.beginCoordinates(3);
203
void RboxPoints_test::
206
RboxPoints rp("c D2");
210
QString qs= QString::fromStdString(s);
211
QCOMPARE(qs.count("-0.5"), 4);
216
#include "moc/RboxPoints_test.moc"