##// END OF EJS Templates
qbarset test update
sauimone -
r1158:a0c848b1f57a
parent child
Show More
@@ -1,343 +1,436
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 void setPen_data();
60 void setPen();
61 void setBrush_data();
62 void setBrush();
63 void setLabelPen_data();
64 void setLabelPen();
65 void setLabelBrush_data();
66 void setLabelBrush();
67 void setLabelFont_data();
68 void setLabelFont();
69
59 70 private:
60 71 QBarSet* m_barset;
61 72 };
62 73
63 74 void tst_QBarSet::initTestCase()
64 75 {
65 76 }
66 77
67 78 void tst_QBarSet::cleanupTestCase()
68 79 {
69 80 }
70 81
71 82 void tst_QBarSet::init()
72 83 {
73 84 m_barset = new QBarSet(QString("Name"));
74 85 }
75 86
76 87 void tst_QBarSet::cleanup()
77 88 {
78 89 delete m_barset;
79 90 m_barset = 0;
80 91 }
81 92
82 93 void tst_QBarSet::qbarset_data()
83 94 {
84 95 }
85 96
86 97 void tst_QBarSet::qbarset()
87 98 {
88 99 QBarSet barset(QString("Name"));
89 100 QCOMPARE(barset.name(), QString("Name"));
90 101 QCOMPARE(barset.count(), 0);
91 102 QVERIFY(qFuzzyIsNull(barset.sum()));
92 103 }
93 104
94 105 void tst_QBarSet::name_data()
95 106 {
96 107 QTest::addColumn<QString> ("name");
97 108 QTest::addColumn<QString> ("result");
98 109 QTest::newRow("name0") << QString("name0") << QString("name0");
99 110 QTest::newRow("name1") << QString("name1") << QString("name1");
100 111 }
101 112
102 113 void tst_QBarSet::name()
103 114 {
104 115 QFETCH(QString, name);
105 116 QFETCH(QString, result);
106 117
107 118 m_barset->setName(name);
108 119 QCOMPARE(m_barset->name(), result);
109 120 }
110 121
111 122 void tst_QBarSet::append_data()
112 123 {
113 124 QTest::addColumn<int> ("count");
114 125 QTest::newRow("0") << 0;
115 126 QTest::newRow("5") << 5;
116 127 QTest::newRow("100") << 100;
117 128 QTest::newRow("1000") << 1000;
118 129 }
119 130
120 131 void tst_QBarSet::append()
121 132 {
122 133 QFETCH(int, count);
123 134
124 135 QCOMPARE(m_barset->count(), 0);
125 136 QVERIFY(qFuzzyIsNull(m_barset->sum()));
126 137
127 138 qreal sum(0.0);
128 139 qreal value(0.0);
129 140
130 141 for (int i=0; i<count; i++) {
131 142 m_barset->append(value);
132 143 QCOMPARE(m_barset->at(i), value);
133 144 sum += value;
134 145 value += 1.0;
135 146 }
136 147
137 148 QCOMPARE(m_barset->count(), count);
138 149 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
139 150 }
140 151
141 152 void tst_QBarSet::appendOperator_data()
142 153 {
143 154 append_data();
144 155 }
145 156
146 157 void tst_QBarSet::appendOperator()
147 158 {
148 159 QFETCH(int, count);
149 160
150 161 QCOMPARE(m_barset->count(), 0);
151 162 QVERIFY(qFuzzyIsNull(m_barset->sum()));
152 163
153 164 qreal sum(0.0);
154 165 qreal value(0.0);
155 166
156 167 for (int i=0; i<count; i++) {
157 168 *m_barset << value;
158 169 QCOMPARE(m_barset->at(i), value);
159 170 sum += value;
160 171 value += 1.0;
161 172 }
162 173
163 174 QCOMPARE(m_barset->count(), count);
164 175 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
165 176 }
166 177
167 178 void tst_QBarSet::insert_data()
168 179 {
169 180 }
170 181
171 182 void tst_QBarSet::insert()
172 183 {
173 184 QCOMPARE(m_barset->count(), 0);
174 185 QVERIFY(qFuzzyIsNull(m_barset->sum()));
175 186
176 187 m_barset->insert(0, 1.0); // 1.0
177 188 QCOMPARE(m_barset->at(0), 1.0);
178 189 QCOMPARE(m_barset->count(), 1);
179 190 QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0));
180 191
181 192 m_barset->insert(0, 2.0); // 2.0 1.0
182 193 QCOMPARE(m_barset->at(0), 2.0);
183 194 QCOMPARE(m_barset->at(1), 1.0);
184 195 QCOMPARE(m_barset->count(), 2);
185 196 QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0));
186 197
187 198 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
188 199 QCOMPARE(m_barset->at(1), 3.0);
189 200 QCOMPARE(m_barset->at(0), 2.0);
190 201 QCOMPARE(m_barset->at(2), 1.0);
191 202 QCOMPARE(m_barset->count(), 3);
192 203 QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0));
193 204 }
194 205
195 206 void tst_QBarSet::remove_data()
196 207 {
197 208 }
198 209
199 210 void tst_QBarSet::remove()
200 211 {
201 212 QCOMPARE(m_barset->count(), 0);
202 213 QVERIFY(qFuzzyIsNull(m_barset->sum()));
203 214
204 215 m_barset->append(1.0);
205 216 m_barset->append(2.0);
206 217 m_barset->append(3.0);
207 218 m_barset->append(4.0);
208 219
209 220 QCOMPARE(m_barset->count(), 4);
210 221 QCOMPARE(m_barset->sum(), 10.0);
211 222
212 223 m_barset->remove(2); // 1.0 2.0 4.0
213 224 QCOMPARE(m_barset->at(0), 1.0);
214 225 QCOMPARE(m_barset->at(1), 2.0);
215 226 QCOMPARE(m_barset->at(2), 4.0);
216 227 QCOMPARE(m_barset->count(), 3);
217 228 QCOMPARE(m_barset->sum(), 7.0);
218 229
219 230 m_barset->remove(0); // 2.0 4.0
220 231 QCOMPARE(m_barset->at(0), 2.0);
221 232 QCOMPARE(m_barset->at(1), 4.0);
222 233 QCOMPARE(m_barset->count(), 2);
223 234 QCOMPARE(m_barset->sum(), 6.0);
224 235 }
225 236
226 237 void tst_QBarSet::replace_data()
227 238 {
228 239
229 240 }
230 241
231 242 void tst_QBarSet::replace()
232 243 {
233 244 QCOMPARE(m_barset->count(), 0);
234 245 QVERIFY(qFuzzyIsNull(m_barset->sum()));
235 246
236 247 m_barset->append(1.0);
237 248 m_barset->append(2.0);
238 249 m_barset->append(3.0);
239 250 m_barset->append(4.0);
240 251
241 252 QCOMPARE(m_barset->count(), 4);
242 253 QCOMPARE(m_barset->sum(), 10.0);
243 254
244 255 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
245 256 QCOMPARE(m_barset->count(), 4);
246 257 QCOMPARE(m_barset->sum(), 14.0);
247 258 QCOMPARE(m_barset->at(0), 5.0);
248 259
249 260 m_barset->replace(3, 6.0);
250 261 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
251 262 QCOMPARE(m_barset->sum(), 16.0);
252 263 QCOMPARE(m_barset->at(0), 5.0);
253 264 QCOMPARE(m_barset->at(1), 2.0);
254 265 QCOMPARE(m_barset->at(2), 3.0);
255 266 QCOMPARE(m_barset->at(3), 6.0);
256 267 }
257 268
258 269 void tst_QBarSet::at_data()
259 270 {
260 271
261 272 }
262 273
263 274 void tst_QBarSet::at()
264 275 {
265 276 QCOMPARE(m_barset->count(), 0);
266 277 QVERIFY(qFuzzyIsNull(m_barset->sum()));
267 278
268 279 m_barset->append(1.0);
269 280 m_barset->append(2.0);
270 281 m_barset->append(3.0);
271 282 m_barset->append(4.0);
272 283
273 284 QCOMPARE(m_barset->at(0), 1.0);
274 285 QCOMPARE(m_barset->at(1), 2.0);
275 286 QCOMPARE(m_barset->at(2), 3.0);
276 287 QCOMPARE(m_barset->at(3), 4.0);
277 288 }
278 289
279 290 void tst_QBarSet::atOperator_data()
280 291 {
281 292
282 293 }
283 294
284 295 void tst_QBarSet::atOperator()
285 296 {
286 297 QCOMPARE(m_barset->count(), 0);
287 298 QVERIFY(qFuzzyIsNull(m_barset->sum()));
288 299
289 300 m_barset->append(1.0);
290 301 m_barset->append(2.0);
291 302 m_barset->append(3.0);
292 303 m_barset->append(4.0);
293 304
294 305 QCOMPARE(m_barset->operator [](0), 1.0);
295 306 QCOMPARE(m_barset->operator [](1), 2.0);
296 307 QCOMPARE(m_barset->operator [](2), 3.0);
297 308 QCOMPARE(m_barset->operator [](3), 4.0);
298 309 }
299 310
300 311 void tst_QBarSet::count_data()
301 312 {
302 313
303 314 }
304 315
305 316 void tst_QBarSet::count()
306 317 {
307 318 QCOMPARE(m_barset->count(), 0);
308 319 QVERIFY(qFuzzyIsNull(m_barset->sum()));
309 320
310 321 m_barset->append(1.0);
311 322 QCOMPARE(m_barset->count(),1);
312 323 m_barset->append(2.0);
313 324 QCOMPARE(m_barset->count(),2);
314 325 m_barset->append(3.0);
315 326 QCOMPARE(m_barset->count(),3);
316 327 m_barset->append(4.0);
317 328 QCOMPARE(m_barset->count(),4);
318 329 }
319 330
320 331 void tst_QBarSet::sum_data()
321 332 {
322 333
323 334 }
324 335
325 336 void tst_QBarSet::sum()
326 337 {
327 338 QCOMPARE(m_barset->count(), 0);
328 339 QVERIFY(qFuzzyIsNull(m_barset->sum()));
329 340
330 341 m_barset->append(1.0);
331 342 QVERIFY(qFuzzyCompare(m_barset->sum(),1.0));
332 343 m_barset->append(2.0);
333 344 QVERIFY(qFuzzyCompare(m_barset->sum(),3.0));
334 345 m_barset->append(3.0);
335 346 QVERIFY(qFuzzyCompare(m_barset->sum(),6.0));
336 347 m_barset->append(4.0);
337 348 QVERIFY(qFuzzyCompare(m_barset->sum(),10.0));
338 349 }
339 350
351 void tst_QBarSet::setPen_data()
352 {
353
354 }
355
356 void tst_QBarSet::setPen()
357 {
358 QVERIFY(m_barset->pen() == QPen());
359
360 QPen pen;
361 pen.setColor(QColor(128,128,128,128));
362 m_barset->setPen(pen);
363
364 QVERIFY(m_barset->pen() == pen);
365 }
366
367 void tst_QBarSet::setBrush_data()
368 {
369
370 }
371
372 void tst_QBarSet::setBrush()
373 {
374 QVERIFY(m_barset->brush() == QBrush());
375
376 QBrush brush;
377 brush.setColor(QColor(128,128,128,128));
378 m_barset->setBrush(brush);
379
380 QVERIFY(m_barset->brush() == brush);
381 }
382
383 void tst_QBarSet::setLabelPen_data()
384 {
385
386 }
387
388 void tst_QBarSet::setLabelPen()
389 {
390 QVERIFY(m_barset->labelPen() == QPen());
391
392 QPen pen;
393 pen.setColor(QColor(128,128,128,128));
394 m_barset->setLabelPen(pen);
395
396 QVERIFY(m_barset->labelPen() == pen);
397 }
398
399 void tst_QBarSet::setLabelBrush_data()
400 {
401
402 }
403
404 void tst_QBarSet::setLabelBrush()
405 {
406 QVERIFY(m_barset->labelBrush() == QBrush());
407
408 QBrush brush;
409 brush.setColor(QColor(128,128,128,128));
410 m_barset->setLabelBrush(brush);
411
412 QVERIFY(m_barset->labelBrush() == brush);
413 }
414
415 void tst_QBarSet::setLabelFont_data()
416 {
417
418 }
419
420 void tst_QBarSet::setLabelFont()
421 {
422 QVERIFY(m_barset->labelFont() == QFont());
423
424 QFont font;
425 font.setBold(true);
426 font.setItalic(true);
427 m_barset->setLabelFont(font);
428
429 QVERIFY(m_barset->labelFont() == font);
430 }
431
432
340 433 QTEST_MAIN(tst_QBarSet)
341 434
342 435 #include "tst_qbarset.moc"
343 436
General Comments 0
You need to be logged in to leave comments. Login now