@@ -0,0 +1,6 | |||
|
1 | !include( ../auto.pri ) { | |
|
2 | error( "Couldn't find the auto.pri file!" ) | |
|
3 | } | |
|
4 | SOURCES += tst_qbarset.cpp | |
|
5 | ||
|
6 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -0,0 +1,345 | |||
|
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 <qbarset.h> | |
|
23 | ||
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
25 | ||
|
26 | class tst_QBarSet : public QObject | |
|
27 | { | |
|
28 | Q_OBJECT | |
|
29 | ||
|
30 | public slots: | |
|
31 | void initTestCase(); | |
|
32 | void cleanupTestCase(); | |
|
33 | void init(); | |
|
34 | void cleanup(); | |
|
35 | ||
|
36 | private slots: | |
|
37 | void qbarset_data(); | |
|
38 | void qbarset(); | |
|
39 | void name_data(); | |
|
40 | void name(); | |
|
41 | void append_data(); | |
|
42 | void append(); | |
|
43 | void appendOperator_data(); | |
|
44 | void appendOperator(); | |
|
45 | void insert_data(); | |
|
46 | void insert(); | |
|
47 | void remove_data(); | |
|
48 | void remove(); | |
|
49 | void replace_data(); | |
|
50 | void replace(); | |
|
51 | void at_data(); | |
|
52 | void at(); | |
|
53 | void atOperator_data(); | |
|
54 | void atOperator(); | |
|
55 | void count_data(); | |
|
56 | void count(); | |
|
57 | void sum_data(); | |
|
58 | void sum(); | |
|
59 | ||
|
60 | private: | |
|
61 | ||
|
62 | private: | |
|
63 | QBarSet* m_barset; | |
|
64 | }; | |
|
65 | ||
|
66 | void tst_QBarSet::initTestCase() | |
|
67 | { | |
|
68 | } | |
|
69 | ||
|
70 | void tst_QBarSet::cleanupTestCase() | |
|
71 | { | |
|
72 | } | |
|
73 | ||
|
74 | void tst_QBarSet::init() | |
|
75 | { | |
|
76 | m_barset = new QBarSet(QString("Name")); | |
|
77 | } | |
|
78 | ||
|
79 | void tst_QBarSet::cleanup() | |
|
80 | { | |
|
81 | delete m_barset; | |
|
82 | m_barset = 0; | |
|
83 | } | |
|
84 | ||
|
85 | void tst_QBarSet::qbarset_data() | |
|
86 | { | |
|
87 | } | |
|
88 | ||
|
89 | void tst_QBarSet::qbarset() | |
|
90 | { | |
|
91 | QBarSet barset(QString("Name")); | |
|
92 | QCOMPARE(barset.name(), QString("Name")); | |
|
93 | QCOMPARE(barset.count(), 0); | |
|
94 | QVERIFY(qFuzzyIsNull(barset.sum())); | |
|
95 | } | |
|
96 | ||
|
97 | void tst_QBarSet::name_data() | |
|
98 | { | |
|
99 | QTest::addColumn<QString> ("names"); | |
|
100 | QTest::newRow("name0, name1") << QString("name0") << QString("name1"); | |
|
101 | } | |
|
102 | ||
|
103 | void tst_QBarSet::name() | |
|
104 | { | |
|
105 | QFETCH(QString, names); | |
|
106 | ||
|
107 | m_barset->setName(names); | |
|
108 | QCOMPARE(m_barset->name(), names); | |
|
109 | } | |
|
110 | ||
|
111 | void tst_QBarSet::append_data() | |
|
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 | QTest::addColumn<int> ("count"); | |
|
116 | QTest::newRow("0 1 2 3 4") << 0 << 1 << 2 << 3 << 4; | |
|
117 | } | |
|
118 | ||
|
119 | void tst_QBarSet::append() | |
|
120 | { | |
|
121 | QFETCH(int, count); | |
|
122 | ||
|
123 | QCOMPARE(m_barset->count(), 0); | |
|
124 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
125 | ||
|
126 | qreal sum(0.0); | |
|
127 | qreal value(0.0); | |
|
128 | ||
|
129 | for (int i=0; i<count; i++) { | |
|
130 | m_barset->append(value); | |
|
131 | QCOMPARE(m_barset->at(i), value); | |
|
132 | sum += value; | |
|
133 | value += 1.0; | |
|
134 | } | |
|
135 | ||
|
136 | QCOMPARE(m_barset->count(), count); | |
|
137 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
|
138 | } | |
|
139 | ||
|
140 | void tst_QBarSet::appendOperator_data() | |
|
141 | { | |
|
142 | append_data(); | |
|
143 | } | |
|
144 | ||
|
145 | void tst_QBarSet::appendOperator() | |
|
146 | { | |
|
147 | QFETCH(int, count); | |
|
148 | ||
|
149 | QCOMPARE(m_barset->count(), 0); | |
|
150 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
151 | ||
|
152 | qreal sum(0.0); | |
|
153 | qreal value(0.0); | |
|
154 | ||
|
155 | for (int i=0; i<count; i++) { | |
|
156 | *m_barset << value; | |
|
157 | QCOMPARE(m_barset->at(i), value); | |
|
158 | sum += value; | |
|
159 | value += 1.0; | |
|
160 | } | |
|
161 | ||
|
162 | QCOMPARE(m_barset->count(), count); | |
|
163 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
|
164 | } | |
|
165 | ||
|
166 | void tst_QBarSet::insert_data() | |
|
167 | { | |
|
168 | // TODO? | |
|
169 | } | |
|
170 | ||
|
171 | void tst_QBarSet::insert() | |
|
172 | { | |
|
173 | QCOMPARE(m_barset->count(), 0); | |
|
174 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
175 | ||
|
176 | m_barset->insert(0, 1.0); // 1.0 | |
|
177 | QCOMPARE(m_barset->at(0), 1.0); | |
|
178 | QCOMPARE(m_barset->count(), 1); | |
|
179 | QCOMPARE(m_barset->sum(), 1.0); | |
|
180 | ||
|
181 | m_barset->insert(0, 2.0); // 2.0 1.0 | |
|
182 | QCOMPARE(m_barset->at(0), 2.0); | |
|
183 | QCOMPARE(m_barset->at(1), 1.0); | |
|
184 | QCOMPARE(m_barset->count(), 2); | |
|
185 | QCOMPARE(m_barset->sum(), 3.0); | |
|
186 | ||
|
187 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 | |
|
188 | QCOMPARE(m_barset->at(1), 3.0); | |
|
189 | QCOMPARE(m_barset->at(0), 2.0); | |
|
190 | QCOMPARE(m_barset->at(2), 1.0); | |
|
191 | QCOMPARE(m_barset->count(), 3); | |
|
192 | QCOMPARE(m_barset->sum(), 6.0); | |
|
193 | } | |
|
194 | ||
|
195 | void tst_QBarSet::remove_data() | |
|
196 | { | |
|
197 | // TODO? | |
|
198 | } | |
|
199 | ||
|
200 | void tst_QBarSet::remove() | |
|
201 | { | |
|
202 | QCOMPARE(m_barset->count(), 0); | |
|
203 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
204 | ||
|
205 | m_barset->append(1.0); | |
|
206 | m_barset->append(2.0); | |
|
207 | m_barset->append(3.0); | |
|
208 | m_barset->append(4.0); | |
|
209 | ||
|
210 | QCOMPARE(m_barset->count(), 4); | |
|
211 | QCOMPARE(m_barset->sum(), 10.0); | |
|
212 | ||
|
213 | m_barset->remove(2); // 1.0 2.0 4.0 | |
|
214 | QCOMPARE(m_barset->at(0), 1.0); | |
|
215 | QCOMPARE(m_barset->at(1), 2.0); | |
|
216 | QCOMPARE(m_barset->at(2), 4.0); | |
|
217 | QCOMPARE(m_barset->count(), 3); | |
|
218 | QCOMPARE(m_barset->sum(), 7.0); | |
|
219 | ||
|
220 | m_barset->remove(0); // 2.0 4.0 | |
|
221 | QCOMPARE(m_barset->at(0), 2.0); | |
|
222 | QCOMPARE(m_barset->at(1), 4.0); | |
|
223 | QCOMPARE(m_barset->count(), 2); | |
|
224 | QCOMPARE(m_barset->sum(), 6.0); | |
|
225 | } | |
|
226 | ||
|
227 | void tst_QBarSet::replace_data() | |
|
228 | { | |
|
229 | ||
|
230 | } | |
|
231 | ||
|
232 | void tst_QBarSet::replace() | |
|
233 | { | |
|
234 | QCOMPARE(m_barset->count(), 0); | |
|
235 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
236 | ||
|
237 | m_barset->append(1.0); | |
|
238 | m_barset->append(2.0); | |
|
239 | m_barset->append(3.0); | |
|
240 | m_barset->append(4.0); | |
|
241 | ||
|
242 | QCOMPARE(m_barset->count(), 4); | |
|
243 | QCOMPARE(m_barset->sum(), 10.0); | |
|
244 | ||
|
245 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 | |
|
246 | QCOMPARE(m_barset->count(), 4); | |
|
247 | QCOMPARE(m_barset->sum(), 14.0); | |
|
248 | QCOMPARE(m_barset->at(0), 5.0); | |
|
249 | ||
|
250 | m_barset->replace(3, 6.0); | |
|
251 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
|
252 | QCOMPARE(m_barset->sum(), 16.0); | |
|
253 | QCOMPARE(m_barset->at(0), 5.0); | |
|
254 | QCOMPARE(m_barset->at(1), 2.0); | |
|
255 | QCOMPARE(m_barset->at(2), 3.0); | |
|
256 | QCOMPARE(m_barset->at(3), 6.0); | |
|
257 | } | |
|
258 | ||
|
259 | void tst_QBarSet::at_data() | |
|
260 | { | |
|
261 | ||
|
262 | } | |
|
263 | ||
|
264 | void tst_QBarSet::at() | |
|
265 | { | |
|
266 | QCOMPARE(m_barset->count(), 0); | |
|
267 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
268 | ||
|
269 | m_barset->append(1.0); | |
|
270 | m_barset->append(2.0); | |
|
271 | m_barset->append(3.0); | |
|
272 | m_barset->append(4.0); | |
|
273 | ||
|
274 | QCOMPARE(m_barset->at(0), 1.0); | |
|
275 | QCOMPARE(m_barset->at(1), 2.0); | |
|
276 | QCOMPARE(m_barset->at(2), 3.0); | |
|
277 | QCOMPARE(m_barset->at(3), 4.0); | |
|
278 | } | |
|
279 | ||
|
280 | void tst_QBarSet::atOperator_data() | |
|
281 | { | |
|
282 | ||
|
283 | } | |
|
284 | ||
|
285 | void tst_QBarSet::atOperator() | |
|
286 | { | |
|
287 | QCOMPARE(m_barset->count(), 0); | |
|
288 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
289 | ||
|
290 | m_barset->append(1.0); | |
|
291 | m_barset->append(2.0); | |
|
292 | m_barset->append(3.0); | |
|
293 | m_barset->append(4.0); | |
|
294 | ||
|
295 | QCOMPARE(m_barset->operator [](0), 1.0); | |
|
296 | QCOMPARE(m_barset->operator [](1), 2.0); | |
|
297 | QCOMPARE(m_barset->operator [](2), 3.0); | |
|
298 | QCOMPARE(m_barset->operator [](3), 4.0); | |
|
299 | } | |
|
300 | ||
|
301 | void tst_QBarSet::count_data() | |
|
302 | { | |
|
303 | ||
|
304 | } | |
|
305 | ||
|
306 | void tst_QBarSet::count() | |
|
307 | { | |
|
308 | QCOMPARE(m_barset->count(), 0); | |
|
309 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
310 | ||
|
311 | m_barset->append(1.0); | |
|
312 | QCOMPARE(m_barset->count(),1); | |
|
313 | m_barset->append(2.0); | |
|
314 | QCOMPARE(m_barset->count(),2); | |
|
315 | m_barset->append(3.0); | |
|
316 | QCOMPARE(m_barset->count(),3); | |
|
317 | m_barset->append(4.0); | |
|
318 | QCOMPARE(m_barset->count(),4); | |
|
319 | } | |
|
320 | ||
|
321 | void tst_QBarSet::sum_data() | |
|
322 | { | |
|
323 | ||
|
324 | } | |
|
325 | ||
|
326 | void tst_QBarSet::sum() | |
|
327 | { | |
|
328 | QCOMPARE(m_barset->count(), 0); | |
|
329 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
|
330 | ||
|
331 | m_barset->append(1.0); | |
|
332 | QCOMPARE(m_barset->sum(),1.0); | |
|
333 | m_barset->append(2.0); | |
|
334 | QCOMPARE(m_barset->sum(),3.0); | |
|
335 | m_barset->append(3.0); | |
|
336 | QCOMPARE(m_barset->sum(),6.0); | |
|
337 | m_barset->append(4.0); | |
|
338 | QCOMPARE(m_barset->sum(),10.0); | |
|
339 | } | |
|
340 | ||
|
341 | ||
|
342 | QTEST_MAIN(tst_QBarSet) | |
|
343 | ||
|
344 | #include "tst_qbarset.moc" | |
|
345 |
General Comments 0
You need to be logged in to leave comments.
Login now