RboxPoints_test.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2006-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/qhulltest/RboxPoints_test.cpp#2 $$Change: 2062 $
5 ** $DateTime: 2016/01/17 13:13:18 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 //pre-compiled headers
10 #include <iostream>
11 #include "RoadTest.h" // QT_VERSION
12 
13 #include "libqhullcpp/RboxPoints.h"
14 #include "libqhullcpp/QhullError.h"
15 
16 using std::cout;
17 using std::endl;
18 using std::ostringstream;
19 using std::string;
20 using std::stringstream;
21 
22 namespace orgQhull {
23 
26 class RboxPoints_test : public RoadTest
27 {
28  Q_OBJECT
29 
30 #
31 private slots:
32  void t_construct();
33  void t_error();
34  void t_test();
35  void t_getSet();
36  void t_foreach();
37  void t_change();
38  void t_ostream();
39 };
40 
41 void
43 {
44  new RboxPoints_test(); // RoadTest::s_testcases
45 }
46 
49 {
50  RboxPoints rp;
51  QCOMPARE(rp.dimension(), 0);
52  QCOMPARE(rp.count(), 0);
53  QVERIFY(QString::fromStdString(rp.comment()) != QString(""));
54  QVERIFY(rp.isEmpty());
55  QVERIFY(!rp.hasRboxMessage());
56  QCOMPARE(rp.rboxStatus(), qh_ERRnone);
57  QCOMPARE(QString::fromStdString(rp.rboxMessage()), QString("rbox warning: no points generated\n"));
58 
59  RboxPoints rp2("c"); // 3-d cube
60  QCOMPARE(rp2.dimension(), 3);
61  QCOMPARE(rp2.count(), 8);
62  QCOMPARE(QString::fromStdString(rp2.comment()), QString("rbox \"c\""));
63  QVERIFY(!rp2.isEmpty());
64  QVERIFY(!rp2.hasRboxMessage());
65  QCOMPARE(rp2.rboxStatus(), qh_ERRnone);
66  QCOMPARE(QString::fromStdString(rp2.rboxMessage()), QString("rbox: OK\n"));
67 }//t_construct
68 
71 {
72  RboxPoints rp;
73  try{
74  rp.appendPoints("D0 c");
75  QFAIL("'D0 c' did not fail.");
76  }catch (const std::exception &e) {
77  const char *s= e.what();
78  cout << "INFO : Caught " << s;
79  QCOMPARE(QString(s).left(6), QString("QH6189"));
80  QVERIFY(rp.hasRboxMessage());
81  QCOMPARE(QString::fromStdString(rp.rboxMessage()).left(8), QString("rbox err"));
82  QCOMPARE(rp.rboxStatus(), 6189);
83  rp.clearRboxMessage();
84  QVERIFY(!rp.hasRboxMessage());
85  }
86  try{
87  RboxPoints rp2;
88  rp2.setDimension(-1);
89  QFAIL("setDimension(-1) did not fail.");
90  }catch (const RoadError &e) {
91  const char *s= e.what();
92  cout << "INFO : Caught " << s;
93  QCOMPARE(QString(s).left(7), QString("QH10062"));
94  QCOMPARE(e.errorCode(), 10062);
95  QCOMPARE(QString::fromStdString(e.what()), QString(s));
96  RoadLogEvent logEvent= e.roadLogEvent();
97  QCOMPARE(logEvent.int1(), -1);
98  }
99 }//t_error
100 
103 {
104  // isEmpty -- t_construct
105 }//t_test
106 
109 {
110  // comment -- t_construct
111  // count -- t_construct
112  // dimension -- t_construct
113 
114  RboxPoints rp;
115  QCOMPARE(rp.dimension(), 0);
116  rp.setDimension(2);
117  QCOMPARE(rp.dimension(), 2);
118  try{
119  rp.setDimension(102);
120  QFAIL("setDimension(102) did not fail.");
121  }catch (const std::exception &e) {
122  cout << "INFO : Caught " << e.what();
123  }
124  QCOMPARE(rp.newCount(), 0);
125  rp.appendPoints("D2 P1 P2");
126  QCOMPARE(rp.count(), 2);
127  QCOMPARE(rp.newCount(), 2); // From previous appendPoints();
128  PointCoordinates pc(rp.qh(), 2, "Test qh() and <<");
129  pc << 1.0 << 0.0 << 2.0 << 0.0;
130  QCOMPARE(pc.dimension(), 2);
131  QCOMPARE(pc.count(), 2);
132  QVERIFY(rp==pc);
133  rp.setNewCount(10); // Normally only used by appendPoints for rbox processing
134  QCOMPARE(rp.newCount(), 10);
135  rp.reservePoints();
136  QVERIFY(rp==pc);
137 }//t_getSet
138 
141 {
142  RboxPoints rp("c");
145  QCOMPARE(*cci, -0.5);
146  QCOMPARE(*ci, *cci);
147  int i=1;
148  while(++cci<rp.endCoordinates()){
149  QVERIFY(++ci<rp.endCoordinates());
150  QCOMPARE(*cci, *ci);
151  i++;
152  }
153  QVERIFY(++ci==rp.endCoordinates());
154  QCOMPARE(i, 8*3);
156  QCOMPARE(rp.endCoordinates()-ci4, 4*3);
159  QCOMPARE(cci5-cci4, 4*3);
160 }//t_foreach
161 
164 {
165  RboxPoints rp("c D2");
166  stringstream s;
167  s << "4 count" << endl;
168  s << "2 dimension" << endl;
169  s << "1 2 3 4 5 6 7 8" << endl;
170  rp.appendPoints(s);
171  QCOMPARE(rp.count(), 8);
173  QCOMPARE(*ci, 7.0);
174  try{
175  stringstream s2;
176  s2 << "4 count" << endl;
177  s2 << "2 dimension" << endl;
178  s2 << "1 2 3 4 5 6 7 " << endl;
179  rp.appendPoints(s2);
180  QFAIL("incomplete appendPoints() did not fail.");
181  }catch (const std::exception &e) {
182  cout << "INFO : Caught " << e.what();
183  }
184  RboxPoints rp2;
185  rp2.append(rp);
186  QCOMPARE(rp2.count(), 8);
188  QCOMPARE(*(cci2+1), 6.0);
189  rp2.appendPoints("D2 10 P0");
190  QCOMPARE(rp2.count(), 19);
192  QCOMPARE(*cie, 0.0);
193  RboxPoints rp3;
194  coordT points[] = { 0, 1,1,0,1,1,0,0};
195  rp3.setDimension(2);
196  rp3.append(8,points);
197  QCOMPARE(rp3.count(), 4);
199  QCOMPARE(*ci3, 0.0);
200 }//t_change
201 
204 {
205  RboxPoints rp("c D2");
206  ostringstream oss;
207  oss << rp;
208  string s= oss.str();
209  QString qs= QString::fromStdString(s);
210  QCOMPARE(qs.count("-0.5"), 4);
211 }//t_ostream
212 
213 }//orgQhull
214 
215 #include "moc/RboxPoints_test.moc"
coordT
#define coordT
Definition: libqhull.h:80
orgQhull::RboxPoints_test::t_change
void t_change()
Definition: RboxPoints_test.cpp:163
orgQhull::RoadError::what
virtual const char * what() const
Definition: RoadError.cpp:137
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::PointCoordinates
Definition: PointCoordinates.h:38
orgQhull::RboxPoints_test::t_foreach
void t_foreach()
Definition: RboxPoints_test.cpp:140
orgQhull::RoadError
Definition: RoadError.h:32
orgQhull::RboxPoints::rboxMessage
std::string rboxMessage() const
Definition: RboxPoints.cpp:86
orgQhull::RoadLogEvent
Definition: RoadLogEvent.h:28
orgQhull::PointCoordinates::setDimension
void setDimension(int i)
Definition: PointCoordinates.cpp:162
orgQhull::RboxPoints::rboxStatus
int rboxStatus() const
Definition: RboxPoints.cpp:98
orgQhull::PointCoordinates::append
void append(const std::vector< coordT > &otherCoordinates)
QhullPoints coordinates, constData, data, count, size.
Definition: PointCoordinates.h:71
orgQhull::PointCoordinates::comment
std::string comment() const
Definition: PointCoordinates.h:82
orgQhull::RboxPoints::clearRboxMessage
void clearRboxMessage()
Definition: RboxPoints.cpp:79
orgQhull::RboxPoints_test::t_getSet
void t_getSet()
Definition: RboxPoints_test.cpp:108
orgQhull::QhullPoints::isEmpty
bool isEmpty() const
Definition: QhullPoints.h:110
orgQhull::QhullPoints::qh
QhullQh * qh() const
Definition: QhullPoints.h:117
orgQhull::RboxPoints::reservePoints
void reservePoints()
Definition: RboxPoints.h:72
orgQhull::Coordinates::iterator
Definition: Coordinates.h:152
qh_ERRnone
#define qh_ERRnone
Definition: libqhull.h:193
orgQhull::RboxPoints_test
Definition: RboxPoints_test.cpp:26
orgQhull::RboxPoints_test::t_error
void t_error()
Definition: RboxPoints_test.cpp:70
orgQhull::RboxPoints_test::t_construct
void t_construct()
Definition: RboxPoints_test.cpp:48
orgQhull::RboxPoints_test::t_test
void t_test()
Definition: RboxPoints_test.cpp:102
orgQhull::PointCoordinates::beginCoordinates
Coordinates::ConstIterator beginCoordinates() const
See QhullPoints for begin, constBegin, end.
Definition: PointCoordinates.h:98
orgQhull::RoadLogEvent::int1
int int1() const
Definition: RoadLogEvent.h:61
orgQhull::RboxPoints::newCount
countT newCount() const
Definition: RboxPoints.h:63
orgQhull::QhullPoints::count
countT count() const
Definition: QhullPoints.h:92
orgQhull::RboxPoints::hasRboxMessage
bool hasRboxMessage() const
Definition: RboxPoints.cpp:104
orgQhull::RoadTest
Definition: RoadTest.h:54
orgQhull::RboxPoints::appendPoints
void appendPoints(const char *rboxCommand)
Definition: RboxPoints.cpp:115
orgQhull::RboxPoints
Definition: RboxPoints.h:37
orgQhull::RboxPoints_test::t_ostream
void t_ostream()
Definition: RboxPoints_test.cpp:203
orgQhull::Coordinates::const_iterator
Definition: Coordinates.h:200
orgQhull::QhullPoints::dimension
int dimension() const
Definition: QhullPoints.h:98
RoadTest.h
orgQhull::PointCoordinates::endCoordinates
Coordinates::ConstIterator endCoordinates() const
Definition: PointCoordinates.h:102
orgQhull::add_RboxPoints_test
void add_RboxPoints_test()
Definition: RboxPoints_test.cpp:42
orgQhull::RboxPoints::setNewCount
void setNewCount(countT pointCount)
Definition: RboxPoints.h:67
RboxPoints.h
QhullError.h
orgQhull::RoadError::errorCode
int errorCode() const
Definition: RoadError.h:76
orgQhull::RoadError::roadLogEvent
RoadLogEvent roadLogEvent() const
Definition: RoadError.h:78


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:59