~ubuntu-branches/ubuntu/trusty/qhull/trusty-proposed

« back to all changes in this revision

Viewing changes to src/qhulltest/RboxPoints_test.cpp

  • Committer: Package Import Robot
  • Author(s): Barak A. Pearlmutter
  • Date: 2014-02-13 11:09:12 UTC
  • mfrom: (8.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20140213110912-ifwyxorlsnnl1ebh
Tags: 2012.1-4
Add convenience link to #include <qhull/qhull.h> to simplify transition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
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 $
 
6
**
 
7
****************************************************************************/
 
8
//pre-compiled headers
 
9
#include <iostream>
 
10
#include "RoadTest.h" // QT_VERSION
 
11
 
 
12
#include "RboxPoints.h"
 
13
#include "QhullError.h"
 
14
 
 
15
using std::cout;
 
16
using std::endl;
 
17
using std::ostringstream;
 
18
using std::string;
 
19
using std::stringstream;
 
20
 
 
21
namespace orgQhull {
 
22
 
 
23
//! Test C++ interface to Rbox
 
24
//! See eg/q_test for tests of rbox commands
 
25
class RboxPoints_test : public RoadTest
 
26
{
 
27
    Q_OBJECT
 
28
 
 
29
#//Test slots
 
30
private slots:
 
31
    void t_construct();
 
32
    void t_error();
 
33
    void t_test();
 
34
    void t_getSet();
 
35
    void t_foreach();
 
36
    void t_change();
 
37
    void t_ostream();
 
38
};
 
39
 
 
40
void
 
41
add_RboxPoints_test()
 
42
{
 
43
    new RboxPoints_test();
 
44
}
 
45
 
 
46
void RboxPoints_test::
 
47
t_construct()
 
48
{
 
49
    RboxPoints rp;
 
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"));
 
57
 
 
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"));
 
66
}//t_construct
 
67
 
 
68
void RboxPoints_test::
 
69
t_error()
 
70
{
 
71
    RboxPoints rp;
 
72
    try{
 
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());
 
84
    }
 
85
    try{
 
86
        RboxPoints rp2;
 
87
        rp2.setDimension(-1);
 
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);
 
97
    }
 
98
}//t_error
 
99
 
 
100
void RboxPoints_test::
 
101
t_test()
 
102
{
 
103
    // isEmpty -- t_construct
 
104
}//t_test
 
105
 
 
106
void RboxPoints_test::
 
107
t_getSet()
 
108
{
 
109
    // comment -- t_construct
 
110
    // count -- t_construct
 
111
    // dimension -- t_construct
 
112
 
 
113
    RboxPoints rp;
 
114
    QCOMPARE(rp.dimension(), 0);
 
115
    rp.setDimension(2);
 
116
    QCOMPARE(rp.dimension(), 2);
 
117
    rp.setDimension(2);
 
118
    QCOMPARE(rp.dimension(), 2);
 
119
    try{
 
120
        rp.setDimension(102);
 
121
        QFAIL("setDimension(102) did not fail.");
 
122
    }catch (const std::exception &e) {
 
123
        cout << "INFO   : Caught " << e.what();
 
124
    }
 
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);
 
133
    QVERIFY(rp==pc);
 
134
    rp.setNewCount(10);  // Normally only used by appendPoints for rbox processing
 
135
    QCOMPARE(rp.newCount(), 10);
 
136
    rp.reservePoints();
 
137
    QVERIFY(rp==pc);
 
138
}//t_getSet
 
139
 
 
140
void RboxPoints_test::
 
141
t_foreach()
 
142
{
 
143
    RboxPoints rp("c");
 
144
    Coordinates::ConstIterator cci= rp.beginCoordinates();
 
145
    orgQhull::Coordinates::Iterator ci= rp.beginCoordinates();
 
146
    QCOMPARE(*cci, -0.5);
 
147
    QCOMPARE(*ci, *cci);
 
148
    int i=1;
 
149
    while(++cci<rp.endCoordinates()){
 
150
        QVERIFY(++ci<rp.endCoordinates());
 
151
        QCOMPARE(*cci, *ci);
 
152
        i++;
 
153
    }
 
154
    QVERIFY(++ci==rp.endCoordinates());
 
155
    QCOMPARE(i, 8*3);
 
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);
 
161
}//t_foreach
 
162
 
 
163
void RboxPoints_test::
 
164
t_change()
 
165
{
 
166
    RboxPoints rp("c D2");
 
167
    stringstream s;
 
168
    s << "4 count" << endl;
 
169
    s << "2 dimension" << endl;
 
170
    s << "1 2 3 4 5 6 7 8" << endl;
 
171
    rp.appendPoints(s);
 
172
    QCOMPARE(rp.count(), 8);
 
173
    orgQhull::Coordinates::Iterator ci= rp.beginCoordinates(7);
 
174
    QCOMPARE(*ci, 7.0);
 
175
    try{
 
176
        stringstream s2;
 
177
        s2 << "4 count" << endl;
 
178
        s2 << "2 dimension" << endl;
 
179
        s2 << "1 2 3 4 5 6 7 " << endl;
 
180
        rp.appendPoints(s2);
 
181
        QFAIL("incomplete appendPoints() did not fail.");
 
182
    }catch (const std::exception &e) {
 
183
        cout << "INFO   : Caught " << e.what();
 
184
    }
 
185
    RboxPoints rp2;
 
186
    rp2.append(rp);
 
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);
 
193
    QCOMPARE(*cie, 0.0);
 
194
    RboxPoints rp3;
 
195
    coordT points[] = { 0, 1,1,0,1,1,0,0};
 
196
    rp3.setDimension(2);
 
197
    rp3.append(8,points);
 
198
    QCOMPARE(rp3.count(), 4);
 
199
    orgQhull::Coordinates::Iterator ci3= rp3.beginCoordinates(3);
 
200
    QCOMPARE(*ci3, 0.0);
 
201
}//t_change
 
202
 
 
203
void RboxPoints_test::
 
204
t_ostream()
 
205
{
 
206
    RboxPoints rp("c D2");
 
207
    ostringstream oss;
 
208
    oss << rp;
 
209
    string s= oss.str();
 
210
    QString qs= QString::fromStdString(s);
 
211
    QCOMPARE(qs.count("-0.5"), 4);
 
212
}//t_ostream
 
213
 
 
214
}//orgQhull
 
215
 
 
216
#include "moc/RboxPoints_test.moc"