##// END OF EJS Templates
barseries unit testing
sauimone -
r1100:63e0c277c9b2
parent child
Show More
@@ -0,0 +1,6
1 !include( ../auto.pri ) {
2 error( "Couldn't find the auto.pri file!" )
3 }
4 SOURCES += tst_qbarseries.cpp
5
6 !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR"
@@ -0,0 +1,133
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include <QtTest/QtTest>
22 #include <qbarseries.h>
23 #include <qbarset>
24
25 QTCOMMERCIALCHART_USE_NAMESPACE
26
27 class tst_QBarSeries : public QObject
28 {
29 Q_OBJECT
30
31 public slots:
32 void initTestCase();
33 void cleanupTestCase();
34 void init();
35 void cleanup();
36
37 private slots:
38 void qbarseries_data();
39 void qbarseries();
40 void type_data();
41 void type();
42 void appendBarSet_data();
43 void appendBarSet();
44
45 private:
46 QBarSeries* m_barseries;
47 };
48
49 void tst_QBarSeries::initTestCase()
50 {
51 }
52
53 void tst_QBarSeries::cleanupTestCase()
54 {
55 }
56
57 void tst_QBarSeries::init()
58 {
59 QBarCategories categories;
60 categories << "category0" << "category1" << "category2";
61 m_barseries = new QBarSeries(categories);
62 }
63
64 void tst_QBarSeries::cleanup()
65 {
66 delete m_barseries;
67 m_barseries = 0;
68 }
69
70 void tst_QBarSeries::qbarseries_data()
71 {
72 QTest::addColumn<QBarCategories> ("categories");
73 QBarCategories c;
74 c << "category0" << "category1" << "category2";
75 QTest::newRow("categories") << c;
76 }
77
78 void tst_QBarSeries::qbarseries()
79 {
80 QFETCH(QBarCategories, categories);
81 QBarSeries *barseries = new QBarSeries(categories);
82 QVERIFY(barseries != 0);
83 QBarCategories verifyCategories = barseries->categories();
84
85 QVERIFY(verifyCategories.count() == categories.count());
86 for (int i=0; i<categories.count(); i++) {
87 QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0);
88 }
89 }
90
91 void tst_QBarSeries::type_data()
92 {
93
94 }
95
96 void tst_QBarSeries::type()
97 {
98 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
99 }
100
101 void tst_QBarSeries::appendBarSet_data()
102 {
103 }
104
105 void tst_QBarSeries::appendBarSet()
106 {
107 QVERIFY(m_barseries->barsetCount() == 0);
108
109 QBarSet *barset = new QBarSet("testset");
110 m_barseries->appendBarSet(barset);
111
112 QVERIFY(m_barseries->barsetCount() == 1);
113 }
114
115 /*
116 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
117 void appendBarSets(QList<QBarSet* > sets);
118 void removeBarSets(QList<QBarSet* > sets);
119 int barsetCount() const;
120 int categoryCount() const;
121 QList<QBarSet*> barSets() const;
122 QBarCategories categories() const;
123
124 void setLabelsVisible(bool visible = true);
125
126 bool setModel(QAbstractItemModel *model);
127 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
128 void setModelMappingRange(int first, int count = -1);
129 */
130 QTEST_MAIN(tst_QBarSeries)
131
132 #include "tst_qbarseries.moc"
133
@@ -1,10 +1,10
1 1 !include( ../test.pri ) {
2 2 error( "Couldn't find the test.pri file!" )
3 3 }
4 4
5 5 TEMPLATE = subdirs
6 SUBDIRS += qchartview qchart qlineseries #qbarset
6 SUBDIRS += qchartview qchart qlineseries qbarset qbarseries
7 7
8 8 test_private:{
9 9 SUBDIRS += chartdataset domain
10 10 }
@@ -1,345 +1,343
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtTest/QtTest>
22 22 #include <qbarset.h>
23 23
24 24 QTCOMMERCIALCHART_USE_NAMESPACE
25 25
26 26 class tst_QBarSet : public QObject
27 27 {
28 28 Q_OBJECT
29 29
30 30 public slots:
31 31 void initTestCase();
32 32 void cleanupTestCase();
33 33 void init();
34 34 void cleanup();
35 35
36 36 private slots:
37 37 void qbarset_data();
38 38 void qbarset();
39 39 void name_data();
40 40 void name();
41 41 void append_data();
42 42 void append();
43 43 void appendOperator_data();
44 44 void appendOperator();
45 45 void insert_data();
46 46 void insert();
47 47 void remove_data();
48 48 void remove();
49 49 void replace_data();
50 50 void replace();
51 51 void at_data();
52 52 void at();
53 53 void atOperator_data();
54 54 void atOperator();
55 55 void count_data();
56 56 void count();
57 57 void sum_data();
58 58 void sum();
59
60 private:
61
62 59 private:
63 60 QBarSet* m_barset;
64 61 };
65 62
66 63 void tst_QBarSet::initTestCase()
67 64 {
68 65 }
69 66
70 67 void tst_QBarSet::cleanupTestCase()
71 68 {
72 69 }
73 70
74 71 void tst_QBarSet::init()
75 72 {
76 73 m_barset = new QBarSet(QString("Name"));
77 74 }
78 75
79 76 void tst_QBarSet::cleanup()
80 77 {
81 78 delete m_barset;
82 79 m_barset = 0;
83 80 }
84 81
85 82 void tst_QBarSet::qbarset_data()
86 83 {
87 84 }
88 85
89 86 void tst_QBarSet::qbarset()
90 87 {
91 88 QBarSet barset(QString("Name"));
92 89 QCOMPARE(barset.name(), QString("Name"));
93 90 QCOMPARE(barset.count(), 0);
94 91 QVERIFY(qFuzzyIsNull(barset.sum()));
95 92 }
96 93
97 94 void tst_QBarSet::name_data()
98 95 {
99 QTest::addColumn<QString> ("names");
100 QTest::newRow("name0, name1") << QString("name0") << QString("name1");
96 QTest::addColumn<QString> ("name");
97 QTest::addColumn<QString> ("result");
98 QTest::newRow("name0") << QString("name0") << QString("name0");
99 QTest::newRow("name1") << QString("name1") << QString("name1");
101 100 }
102 101
103 102 void tst_QBarSet::name()
104 103 {
105 QFETCH(QString, names);
104 QFETCH(QString, name);
105 QFETCH(QString, result);
106 106
107 m_barset->setName(names);
108 QCOMPARE(m_barset->name(), names);
107 m_barset->setName(name);
108 QCOMPARE(m_barset->name(), result);
109 109 }
110 110
111 111 void tst_QBarSet::append_data()
112 112 {
113 // QTest::addColumn<QList<qreal> >("values");
114 // QTest::newRow("0.0 1.0 2.0 3.0 4.0") << (QList<qreal>(0.0) << qreal(1.0) << qreal(2.0) << qreal(3.0) << qreal(4.0));
115 113 QTest::addColumn<int> ("count");
116 QTest::newRow("0 1 2 3 4") << 0 << 1 << 2 << 3 << 4;
114 QTest::newRow("0") << 0;
115 QTest::newRow("5") << 5;
116 QTest::newRow("100") << 100;
117 QTest::newRow("1000") << 1000;
117 118 }
118 119
119 120 void tst_QBarSet::append()
120 121 {
121 122 QFETCH(int, count);
122 123
123 124 QCOMPARE(m_barset->count(), 0);
124 125 QVERIFY(qFuzzyIsNull(m_barset->sum()));
125 126
126 127 qreal sum(0.0);
127 128 qreal value(0.0);
128 129
129 130 for (int i=0; i<count; i++) {
130 131 m_barset->append(value);
131 132 QCOMPARE(m_barset->at(i), value);
132 133 sum += value;
133 134 value += 1.0;
134 135 }
135 136
136 137 QCOMPARE(m_barset->count(), count);
137 138 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
138 139 }
139 140
140 141 void tst_QBarSet::appendOperator_data()
141 142 {
142 143 append_data();
143 144 }
144 145
145 146 void tst_QBarSet::appendOperator()
146 147 {
147 148 QFETCH(int, count);
148 149
149 150 QCOMPARE(m_barset->count(), 0);
150 151 QVERIFY(qFuzzyIsNull(m_barset->sum()));
151 152
152 153 qreal sum(0.0);
153 154 qreal value(0.0);
154 155
155 156 for (int i=0; i<count; i++) {
156 157 *m_barset << value;
157 158 QCOMPARE(m_barset->at(i), value);
158 159 sum += value;
159 160 value += 1.0;
160 161 }
161 162
162 163 QCOMPARE(m_barset->count(), count);
163 164 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
164 165 }
165 166
166 167 void tst_QBarSet::insert_data()
167 168 {
168 // TODO?
169 169 }
170 170
171 171 void tst_QBarSet::insert()
172 172 {
173 173 QCOMPARE(m_barset->count(), 0);
174 174 QVERIFY(qFuzzyIsNull(m_barset->sum()));
175 175
176 176 m_barset->insert(0, 1.0); // 1.0
177 177 QCOMPARE(m_barset->at(0), 1.0);
178 178 QCOMPARE(m_barset->count(), 1);
179 QCOMPARE(m_barset->sum(), 1.0);
179 QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0));
180 180
181 181 m_barset->insert(0, 2.0); // 2.0 1.0
182 182 QCOMPARE(m_barset->at(0), 2.0);
183 183 QCOMPARE(m_barset->at(1), 1.0);
184 184 QCOMPARE(m_barset->count(), 2);
185 QCOMPARE(m_barset->sum(), 3.0);
185 QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0));
186 186
187 187 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
188 188 QCOMPARE(m_barset->at(1), 3.0);
189 189 QCOMPARE(m_barset->at(0), 2.0);
190 190 QCOMPARE(m_barset->at(2), 1.0);
191 191 QCOMPARE(m_barset->count(), 3);
192 QCOMPARE(m_barset->sum(), 6.0);
192 QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0));
193 193 }
194 194
195 195 void tst_QBarSet::remove_data()
196 196 {
197 // TODO?
198 197 }
199 198
200 199 void tst_QBarSet::remove()
201 200 {
202 201 QCOMPARE(m_barset->count(), 0);
203 202 QVERIFY(qFuzzyIsNull(m_barset->sum()));
204 203
205 204 m_barset->append(1.0);
206 205 m_barset->append(2.0);
207 206 m_barset->append(3.0);
208 207 m_barset->append(4.0);
209 208
210 209 QCOMPARE(m_barset->count(), 4);
211 210 QCOMPARE(m_barset->sum(), 10.0);
212 211
213 212 m_barset->remove(2); // 1.0 2.0 4.0
214 213 QCOMPARE(m_barset->at(0), 1.0);
215 214 QCOMPARE(m_barset->at(1), 2.0);
216 215 QCOMPARE(m_barset->at(2), 4.0);
217 216 QCOMPARE(m_barset->count(), 3);
218 217 QCOMPARE(m_barset->sum(), 7.0);
219 218
220 219 m_barset->remove(0); // 2.0 4.0
221 220 QCOMPARE(m_barset->at(0), 2.0);
222 221 QCOMPARE(m_barset->at(1), 4.0);
223 222 QCOMPARE(m_barset->count(), 2);
224 223 QCOMPARE(m_barset->sum(), 6.0);
225 224 }
226 225
227 226 void tst_QBarSet::replace_data()
228 227 {
229 228
230 229 }
231 230
232 231 void tst_QBarSet::replace()
233 232 {
234 233 QCOMPARE(m_barset->count(), 0);
235 234 QVERIFY(qFuzzyIsNull(m_barset->sum()));
236 235
237 236 m_barset->append(1.0);
238 237 m_barset->append(2.0);
239 238 m_barset->append(3.0);
240 239 m_barset->append(4.0);
241 240
242 241 QCOMPARE(m_barset->count(), 4);
243 242 QCOMPARE(m_barset->sum(), 10.0);
244 243
245 244 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
246 245 QCOMPARE(m_barset->count(), 4);
247 246 QCOMPARE(m_barset->sum(), 14.0);
248 247 QCOMPARE(m_barset->at(0), 5.0);
249 248
250 249 m_barset->replace(3, 6.0);
251 250 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
252 251 QCOMPARE(m_barset->sum(), 16.0);
253 252 QCOMPARE(m_barset->at(0), 5.0);
254 253 QCOMPARE(m_barset->at(1), 2.0);
255 254 QCOMPARE(m_barset->at(2), 3.0);
256 255 QCOMPARE(m_barset->at(3), 6.0);
257 256 }
258 257
259 258 void tst_QBarSet::at_data()
260 259 {
261 260
262 261 }
263 262
264 263 void tst_QBarSet::at()
265 264 {
266 265 QCOMPARE(m_barset->count(), 0);
267 266 QVERIFY(qFuzzyIsNull(m_barset->sum()));
268 267
269 268 m_barset->append(1.0);
270 269 m_barset->append(2.0);
271 270 m_barset->append(3.0);
272 271 m_barset->append(4.0);
273 272
274 273 QCOMPARE(m_barset->at(0), 1.0);
275 274 QCOMPARE(m_barset->at(1), 2.0);
276 275 QCOMPARE(m_barset->at(2), 3.0);
277 276 QCOMPARE(m_barset->at(3), 4.0);
278 277 }
279 278
280 279 void tst_QBarSet::atOperator_data()
281 280 {
282 281
283 282 }
284 283
285 284 void tst_QBarSet::atOperator()
286 285 {
287 286 QCOMPARE(m_barset->count(), 0);
288 287 QVERIFY(qFuzzyIsNull(m_barset->sum()));
289 288
290 289 m_barset->append(1.0);
291 290 m_barset->append(2.0);
292 291 m_barset->append(3.0);
293 292 m_barset->append(4.0);
294 293
295 294 QCOMPARE(m_barset->operator [](0), 1.0);
296 295 QCOMPARE(m_barset->operator [](1), 2.0);
297 296 QCOMPARE(m_barset->operator [](2), 3.0);
298 297 QCOMPARE(m_barset->operator [](3), 4.0);
299 298 }
300 299
301 300 void tst_QBarSet::count_data()
302 301 {
303 302
304 303 }
305 304
306 305 void tst_QBarSet::count()
307 306 {
308 307 QCOMPARE(m_barset->count(), 0);
309 308 QVERIFY(qFuzzyIsNull(m_barset->sum()));
310 309
311 310 m_barset->append(1.0);
312 311 QCOMPARE(m_barset->count(),1);
313 312 m_barset->append(2.0);
314 313 QCOMPARE(m_barset->count(),2);
315 314 m_barset->append(3.0);
316 315 QCOMPARE(m_barset->count(),3);
317 316 m_barset->append(4.0);
318 317 QCOMPARE(m_barset->count(),4);
319 318 }
320 319
321 320 void tst_QBarSet::sum_data()
322 321 {
323 322
324 323 }
325 324
326 325 void tst_QBarSet::sum()
327 326 {
328 327 QCOMPARE(m_barset->count(), 0);
329 328 QVERIFY(qFuzzyIsNull(m_barset->sum()));
330 329
331 330 m_barset->append(1.0);
332 QCOMPARE(m_barset->sum(),1.0);
331 QVERIFY(qFuzzyCompare(m_barset->sum(),1.0));
333 332 m_barset->append(2.0);
334 QCOMPARE(m_barset->sum(),3.0);
333 QVERIFY(qFuzzyCompare(m_barset->sum(),3.0));
335 334 m_barset->append(3.0);
336 QCOMPARE(m_barset->sum(),6.0);
335 QVERIFY(qFuzzyCompare(m_barset->sum(),6.0));
337 336 m_barset->append(4.0);
338 QCOMPARE(m_barset->sum(),10.0);
337 QVERIFY(qFuzzyCompare(m_barset->sum(),10.0));
339 338 }
340 339
341
342 340 QTEST_MAIN(tst_QBarSet)
343 341
344 342 #include "tst_qbarset.moc"
345 343
General Comments 0
You need to be logged in to leave comments. Login now