@@ -1,435 +1,427 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarset.h> |
|
22 | #include <qbarset.h> | |
23 | #include <qgroupedbarseries.h> |
|
23 | #include <qgroupedbarseries.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | class tst_QBarSet : public QObject |
|
28 | class tst_QBarSet : public QObject | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 |
|
31 | |||
32 | public slots: |
|
32 | public slots: | |
33 | void initTestCase(); |
|
33 | void initTestCase(); | |
34 | void cleanupTestCase(); |
|
34 | void cleanupTestCase(); | |
35 | void init(); |
|
35 | void init(); | |
36 | void cleanup(); |
|
36 | void cleanup(); | |
37 |
|
37 | |||
38 | private slots: |
|
38 | private slots: | |
39 | void qbarset_data(); |
|
39 | void qbarset_data(); | |
40 | void qbarset(); |
|
40 | void qbarset(); | |
41 | void label_data(); |
|
41 | void label_data(); | |
42 | void label(); |
|
42 | void label(); | |
43 | void append_data(); |
|
43 | void append_data(); | |
44 | void append(); |
|
44 | void append(); | |
45 | void appendOperator_data(); |
|
45 | void appendOperator_data(); | |
46 | void appendOperator(); |
|
46 | void appendOperator(); | |
47 | void insert_data(); |
|
47 | void insert_data(); | |
48 | void insert(); |
|
48 | void insert(); | |
49 | void remove_data(); |
|
49 | void remove_data(); | |
50 | void remove(); |
|
50 | void remove(); | |
51 | void replace_data(); |
|
51 | void replace_data(); | |
52 | void replace(); |
|
52 | void replace(); | |
53 | void at_data(); |
|
53 | void at_data(); | |
54 | void at(); |
|
54 | void at(); | |
55 | void atOperator_data(); |
|
55 | void atOperator_data(); | |
56 | void atOperator(); |
|
56 | void atOperator(); | |
57 | void count_data(); |
|
57 | void count_data(); | |
58 | void count(); |
|
58 | void count(); | |
59 | void sum_data(); |
|
59 | void sum_data(); | |
60 | void sum(); |
|
60 | void sum(); | |
61 | void customize(); |
|
61 | void customize(); | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | QBarSet* m_barset; |
|
64 | QBarSet* m_barset; | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | void tst_QBarSet::initTestCase() |
|
67 | void tst_QBarSet::initTestCase() | |
68 | { |
|
68 | { | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void tst_QBarSet::cleanupTestCase() |
|
71 | void tst_QBarSet::cleanupTestCase() | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void tst_QBarSet::init() |
|
75 | void tst_QBarSet::init() | |
76 | { |
|
76 | { | |
77 | m_barset = new QBarSet(QString("label")); |
|
77 | m_barset = new QBarSet(QString("label")); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_QBarSet::cleanup() |
|
80 | void tst_QBarSet::cleanup() | |
81 | { |
|
81 | { | |
82 | delete m_barset; |
|
82 | delete m_barset; | |
83 | m_barset = 0; |
|
83 | m_barset = 0; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void tst_QBarSet::qbarset_data() |
|
86 | void tst_QBarSet::qbarset_data() | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_QBarSet::qbarset() |
|
90 | void tst_QBarSet::qbarset() | |
91 | { |
|
91 | { | |
92 | QBarSet barset(QString("label")); |
|
92 | QBarSet barset(QString("label")); | |
93 | QCOMPARE(barset.label(), QString("label")); |
|
93 | QCOMPARE(barset.label(), QString("label")); | |
94 | QCOMPARE(barset.count(), 0); |
|
94 | QCOMPARE(barset.count(), 0); | |
95 | QVERIFY(qFuzzyIsNull(barset.sum())); |
|
95 | QVERIFY(qFuzzyIsNull(barset.sum())); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void tst_QBarSet::label_data() |
|
98 | void tst_QBarSet::label_data() | |
99 | { |
|
99 | { | |
100 | QTest::addColumn<QString> ("label"); |
|
100 | QTest::addColumn<QString> ("label"); | |
101 | QTest::addColumn<QString> ("result"); |
|
101 | QTest::addColumn<QString> ("result"); | |
102 | QTest::newRow("label0") << QString("label0") << QString("label0"); |
|
102 | QTest::newRow("label0") << QString("label0") << QString("label0"); | |
103 | QTest::newRow("label1") << QString("label1") << QString("label1"); |
|
103 | QTest::newRow("label1") << QString("label1") << QString("label1"); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void tst_QBarSet::label() |
|
106 | void tst_QBarSet::label() | |
107 | { |
|
107 | { | |
108 | QFETCH(QString, label); |
|
108 | QFETCH(QString, label); | |
109 | QFETCH(QString, result); |
|
109 | QFETCH(QString, result); | |
110 |
|
110 | |||
111 | QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged())); |
|
111 | QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged())); | |
112 | m_barset->setLabel(label); |
|
112 | m_barset->setLabel(label); | |
113 | QCOMPARE(m_barset->label(), result); |
|
113 | QCOMPARE(m_barset->label(), result); | |
114 | QVERIFY(labelSpy.count() == 1); |
|
114 | QVERIFY(labelSpy.count() == 1); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void tst_QBarSet::append_data() |
|
117 | void tst_QBarSet::append_data() | |
118 | { |
|
118 | { | |
119 | QTest::addColumn<int> ("count"); |
|
119 | QTest::addColumn<int> ("count"); | |
120 | QTest::newRow("0") << 0; |
|
120 | QTest::newRow("0") << 0; | |
121 | QTest::newRow("5") << 5; |
|
121 | QTest::newRow("5") << 5; | |
122 | QTest::newRow("100") << 100; |
|
122 | QTest::newRow("100") << 100; | |
123 | QTest::newRow("1000") << 1000; |
|
123 | QTest::newRow("1000") << 1000; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void tst_QBarSet::append() |
|
126 | void tst_QBarSet::append() | |
127 | { |
|
127 | { | |
128 | QFETCH(int, count); |
|
128 | QFETCH(int, count); | |
129 |
|
129 | |||
130 | QCOMPARE(m_barset->count(), 0); |
|
130 | QCOMPARE(m_barset->count(), 0); | |
131 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
131 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
132 |
|
132 | |||
133 | QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int))); |
|
133 | QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int))); | |
134 | QSignalSpy countSpy(m_barset, SIGNAL(countChanged(int))); |
|
|||
135 |
|
134 | |||
136 | qreal sum(0.0); |
|
135 | qreal sum(0.0); | |
137 | qreal value(0.0); |
|
136 | qreal value(0.0); | |
138 |
|
137 | |||
139 | for (int i=0; i<count; i++) { |
|
138 | for (int i=0; i<count; i++) { | |
140 | m_barset->append(value); |
|
139 | m_barset->append(value); | |
141 | QCOMPARE(m_barset->at(i).y(), value); |
|
140 | QCOMPARE(m_barset->at(i).y(), value); | |
142 | sum += value; |
|
141 | sum += value; | |
143 | value += 1.0; |
|
142 | value += 1.0; | |
144 | } |
|
143 | } | |
145 |
|
144 | |||
146 | QCOMPARE(m_barset->count(), count); |
|
145 | QCOMPARE(m_barset->count(), count); | |
147 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
146 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
148 |
|
147 | |||
149 | QCOMPARE(valueSpy.count(), count); |
|
148 | QCOMPARE(valueSpy.count(), count); | |
150 | QCOMPARE(countSpy.count(), count); |
|
|||
151 | } |
|
149 | } | |
152 |
|
150 | |||
153 | void tst_QBarSet::appendOperator_data() |
|
151 | void tst_QBarSet::appendOperator_data() | |
154 | { |
|
152 | { | |
155 | append_data(); |
|
153 | append_data(); | |
156 | } |
|
154 | } | |
157 |
|
155 | |||
158 | void tst_QBarSet::appendOperator() |
|
156 | void tst_QBarSet::appendOperator() | |
159 | { |
|
157 | { | |
160 | QFETCH(int, count); |
|
158 | QFETCH(int, count); | |
161 |
|
159 | |||
162 | QCOMPARE(m_barset->count(), 0); |
|
160 | QCOMPARE(m_barset->count(), 0); | |
163 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
161 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
164 |
|
162 | |||
165 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
163 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); | |
166 | QSignalSpy countSpy(m_barset, SIGNAL(countChanged(int))); |
|
|||
167 |
|
164 | |||
168 | qreal sum(0.0); |
|
165 | qreal sum(0.0); | |
169 | qreal value(0.0); |
|
166 | qreal value(0.0); | |
170 |
|
167 | |||
171 | for (int i=0; i<count; i++) { |
|
168 | for (int i=0; i<count; i++) { | |
172 | *m_barset << value; |
|
169 | *m_barset << value; | |
173 | QCOMPARE(m_barset->at(i).y(), value); |
|
170 | QCOMPARE(m_barset->at(i).y(), value); | |
174 | sum += value; |
|
171 | sum += value; | |
175 | value += 1.0; |
|
172 | value += 1.0; | |
176 | } |
|
173 | } | |
177 |
|
174 | |||
178 | QCOMPARE(m_barset->count(), count); |
|
175 | QCOMPARE(m_barset->count(), count); | |
179 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
176 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
180 | QCOMPARE(valueSpy.count(), count); |
|
177 | QCOMPARE(valueSpy.count(), count); | |
181 | QCOMPARE(countSpy.count(), count); |
|
|||
182 | } |
|
178 | } | |
183 |
|
179 | |||
184 | void tst_QBarSet::insert_data() |
|
180 | void tst_QBarSet::insert_data() | |
185 | { |
|
181 | { | |
186 | } |
|
182 | } | |
187 |
|
183 | |||
188 | void tst_QBarSet::insert() |
|
184 | void tst_QBarSet::insert() | |
189 | { |
|
185 | { | |
190 | QCOMPARE(m_barset->count(), 0); |
|
186 | QCOMPARE(m_barset->count(), 0); | |
191 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
187 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
192 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
188 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); | |
193 | QSignalSpy countSpy(m_barset, SIGNAL(countChanged(int))); |
|
|||
194 |
|
189 | |||
195 | m_barset->insert(0, 1.0); // 1.0 |
|
190 | m_barset->insert(0, 1.0); // 1.0 | |
196 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
191 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
197 | QCOMPARE(m_barset->count(), 1); |
|
192 | QCOMPARE(m_barset->count(), 1); | |
198 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); |
|
193 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); | |
199 |
|
194 | |||
200 | m_barset->insert(0, 2.0); // 2.0 1.0 |
|
195 | m_barset->insert(0, 2.0); // 2.0 1.0 | |
201 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
196 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
202 | QCOMPARE(m_barset->at(1).y(), 1.0); |
|
197 | QCOMPARE(m_barset->at(1).y(), 1.0); | |
203 | QCOMPARE(m_barset->count(), 2); |
|
198 | QCOMPARE(m_barset->count(), 2); | |
204 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); |
|
199 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); | |
205 |
|
200 | |||
206 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 |
|
201 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 | |
207 | QCOMPARE(m_barset->at(1).y(), 3.0); |
|
202 | QCOMPARE(m_barset->at(1).y(), 3.0); | |
208 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
203 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
209 | QCOMPARE(m_barset->at(2).y(), 1.0); |
|
204 | QCOMPARE(m_barset->at(2).y(), 1.0); | |
210 | QCOMPARE(m_barset->count(), 3); |
|
205 | QCOMPARE(m_barset->count(), 3); | |
211 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); |
|
206 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); | |
212 | QCOMPARE(valueSpy.count(), 3); |
|
207 | QCOMPARE(valueSpy.count(), 3); | |
213 | QCOMPARE(countSpy.count(), 3); |
|
|||
214 | } |
|
208 | } | |
215 |
|
209 | |||
216 | void tst_QBarSet::remove_data() |
|
210 | void tst_QBarSet::remove_data() | |
217 | { |
|
211 | { | |
218 | } |
|
212 | } | |
219 |
|
213 | |||
220 | void tst_QBarSet::remove() |
|
214 | void tst_QBarSet::remove() | |
221 | { |
|
215 | { | |
222 | QCOMPARE(m_barset->count(), 0); |
|
216 | QCOMPARE(m_barset->count(), 0); | |
223 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
217 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
224 |
|
218 | |||
225 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int))); |
|
219 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int))); | |
226 | QSignalSpy countSpy(m_barset, SIGNAL(countChanged(int))); |
|
|||
227 |
|
220 | |||
228 | m_barset->append(1.0); |
|
221 | m_barset->append(1.0); | |
229 | m_barset->append(2.0); |
|
222 | m_barset->append(2.0); | |
230 | m_barset->append(3.0); |
|
223 | m_barset->append(3.0); | |
231 | m_barset->append(4.0); |
|
224 | m_barset->append(4.0); | |
232 |
|
225 | |||
233 | QCOMPARE(m_barset->count(), 4); |
|
226 | QCOMPARE(m_barset->count(), 4); | |
234 | QCOMPARE(m_barset->sum(), 10.0); |
|
227 | QCOMPARE(m_barset->sum(), 10.0); | |
235 |
|
228 | |||
236 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
229 | m_barset->remove(2); // 1.0 2.0 4.0 | |
237 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
230 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
238 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
231 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
239 | QCOMPARE(m_barset->at(2).y(), 4.0); |
|
232 | QCOMPARE(m_barset->at(2).y(), 4.0); | |
240 | QCOMPARE(m_barset->count(), 3); |
|
233 | QCOMPARE(m_barset->count(), 3); | |
241 | QCOMPARE(m_barset->sum(), 7.0); |
|
234 | QCOMPARE(m_barset->sum(), 7.0); | |
242 |
|
235 | |||
243 | m_barset->remove(0); // 2.0 4.0 |
|
236 | m_barset->remove(0); // 2.0 4.0 | |
244 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
237 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
245 | QCOMPARE(m_barset->at(1).y(), 4.0); |
|
238 | QCOMPARE(m_barset->at(1).y(), 4.0); | |
246 | QCOMPARE(m_barset->count(), 2); |
|
239 | QCOMPARE(m_barset->count(), 2); | |
247 | QCOMPARE(m_barset->sum(), 6.0); |
|
240 | QCOMPARE(m_barset->sum(), 6.0); | |
248 |
|
241 | |||
249 | QCOMPARE(valueSpy.count(), 2); |
|
242 | QCOMPARE(valueSpy.count(), 2); | |
250 | QCOMPARE(countSpy.count(), 6); |
|
|||
251 | } |
|
243 | } | |
252 |
|
244 | |||
253 | void tst_QBarSet::replace_data() |
|
245 | void tst_QBarSet::replace_data() | |
254 | { |
|
246 | { | |
255 |
|
247 | |||
256 | } |
|
248 | } | |
257 |
|
249 | |||
258 | void tst_QBarSet::replace() |
|
250 | void tst_QBarSet::replace() | |
259 | { |
|
251 | { | |
260 | QCOMPARE(m_barset->count(), 0); |
|
252 | QCOMPARE(m_barset->count(), 0); | |
261 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
253 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
262 | QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int))); |
|
254 | QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int))); | |
263 |
|
255 | |||
264 | m_barset->append(1.0); |
|
256 | m_barset->append(1.0); | |
265 | m_barset->append(2.0); |
|
257 | m_barset->append(2.0); | |
266 | m_barset->append(3.0); |
|
258 | m_barset->append(3.0); | |
267 | m_barset->append(4.0); |
|
259 | m_barset->append(4.0); | |
268 |
|
260 | |||
269 | QCOMPARE(m_barset->count(), 4); |
|
261 | QCOMPARE(m_barset->count(), 4); | |
270 | QCOMPARE(m_barset->sum(), 10.0); |
|
262 | QCOMPARE(m_barset->sum(), 10.0); | |
271 |
|
263 | |||
272 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
264 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 | |
273 | QCOMPARE(m_barset->count(), 4); |
|
265 | QCOMPARE(m_barset->count(), 4); | |
274 | QCOMPARE(m_barset->sum(), 14.0); |
|
266 | QCOMPARE(m_barset->sum(), 14.0); | |
275 | QCOMPARE(m_barset->at(0).y(), 5.0); |
|
267 | QCOMPARE(m_barset->at(0).y(), 5.0); | |
276 |
|
268 | |||
277 | m_barset->replace(3, 6.0); |
|
269 | m_barset->replace(3, 6.0); | |
278 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
270 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
279 | QCOMPARE(m_barset->sum(), 16.0); |
|
271 | QCOMPARE(m_barset->sum(), 16.0); | |
280 | QCOMPARE(m_barset->at(0).y(), 5.0); |
|
272 | QCOMPARE(m_barset->at(0).y(), 5.0); | |
281 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
273 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
282 | QCOMPARE(m_barset->at(2).y(), 3.0); |
|
274 | QCOMPARE(m_barset->at(2).y(), 3.0); | |
283 | QCOMPARE(m_barset->at(3).y(), 6.0); |
|
275 | QCOMPARE(m_barset->at(3).y(), 6.0); | |
284 |
|
276 | |||
285 | QVERIFY(valueSpy.count() == 2); |
|
277 | QVERIFY(valueSpy.count() == 2); | |
286 | } |
|
278 | } | |
287 |
|
279 | |||
288 | void tst_QBarSet::at_data() |
|
280 | void tst_QBarSet::at_data() | |
289 | { |
|
281 | { | |
290 |
|
282 | |||
291 | } |
|
283 | } | |
292 |
|
284 | |||
293 | void tst_QBarSet::at() |
|
285 | void tst_QBarSet::at() | |
294 | { |
|
286 | { | |
295 | QCOMPARE(m_barset->count(), 0); |
|
287 | QCOMPARE(m_barset->count(), 0); | |
296 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
288 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
297 |
|
289 | |||
298 | m_barset->append(1.0); |
|
290 | m_barset->append(1.0); | |
299 | m_barset->append(2.0); |
|
291 | m_barset->append(2.0); | |
300 | m_barset->append(3.0); |
|
292 | m_barset->append(3.0); | |
301 | m_barset->append(4.0); |
|
293 | m_barset->append(4.0); | |
302 |
|
294 | |||
303 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
295 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
304 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
296 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
305 | QCOMPARE(m_barset->at(2).y(), 3.0); |
|
297 | QCOMPARE(m_barset->at(2).y(), 3.0); | |
306 | QCOMPARE(m_barset->at(3).y(), 4.0); |
|
298 | QCOMPARE(m_barset->at(3).y(), 4.0); | |
307 | } |
|
299 | } | |
308 |
|
300 | |||
309 | void tst_QBarSet::atOperator_data() |
|
301 | void tst_QBarSet::atOperator_data() | |
310 | { |
|
302 | { | |
311 |
|
303 | |||
312 | } |
|
304 | } | |
313 |
|
305 | |||
314 | void tst_QBarSet::atOperator() |
|
306 | void tst_QBarSet::atOperator() | |
315 | { |
|
307 | { | |
316 | QCOMPARE(m_barset->count(), 0); |
|
308 | QCOMPARE(m_barset->count(), 0); | |
317 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
309 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
318 |
|
310 | |||
319 | m_barset->append(1.0); |
|
311 | m_barset->append(1.0); | |
320 | m_barset->append(2.0); |
|
312 | m_barset->append(2.0); | |
321 | m_barset->append(3.0); |
|
313 | m_barset->append(3.0); | |
322 | m_barset->append(4.0); |
|
314 | m_barset->append(4.0); | |
323 |
|
315 | |||
324 | QCOMPARE(m_barset->operator [](0).y(), 1.0); |
|
316 | QCOMPARE(m_barset->operator [](0).y(), 1.0); | |
325 | QCOMPARE(m_barset->operator [](1).y(), 2.0); |
|
317 | QCOMPARE(m_barset->operator [](1).y(), 2.0); | |
326 | QCOMPARE(m_barset->operator [](2).y(), 3.0); |
|
318 | QCOMPARE(m_barset->operator [](2).y(), 3.0); | |
327 | QCOMPARE(m_barset->operator [](3).y(), 4.0); |
|
319 | QCOMPARE(m_barset->operator [](3).y(), 4.0); | |
328 | } |
|
320 | } | |
329 |
|
321 | |||
330 | void tst_QBarSet::count_data() |
|
322 | void tst_QBarSet::count_data() | |
331 | { |
|
323 | { | |
332 |
|
324 | |||
333 | } |
|
325 | } | |
334 |
|
326 | |||
335 | void tst_QBarSet::count() |
|
327 | void tst_QBarSet::count() | |
336 | { |
|
328 | { | |
337 | QCOMPARE(m_barset->count(), 0); |
|
329 | QCOMPARE(m_barset->count(), 0); | |
338 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
330 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
339 |
|
331 | |||
340 | m_barset->append(1.0); |
|
332 | m_barset->append(1.0); | |
341 | QCOMPARE(m_barset->count(),1); |
|
333 | QCOMPARE(m_barset->count(),1); | |
342 | m_barset->append(2.0); |
|
334 | m_barset->append(2.0); | |
343 | QCOMPARE(m_barset->count(),2); |
|
335 | QCOMPARE(m_barset->count(),2); | |
344 | m_barset->append(3.0); |
|
336 | m_barset->append(3.0); | |
345 | QCOMPARE(m_barset->count(),3); |
|
337 | QCOMPARE(m_barset->count(),3); | |
346 | m_barset->append(4.0); |
|
338 | m_barset->append(4.0); | |
347 | QCOMPARE(m_barset->count(),4); |
|
339 | QCOMPARE(m_barset->count(),4); | |
348 | } |
|
340 | } | |
349 |
|
341 | |||
350 | void tst_QBarSet::sum_data() |
|
342 | void tst_QBarSet::sum_data() | |
351 | { |
|
343 | { | |
352 |
|
344 | |||
353 | } |
|
345 | } | |
354 |
|
346 | |||
355 | void tst_QBarSet::sum() |
|
347 | void tst_QBarSet::sum() | |
356 | { |
|
348 | { | |
357 | QCOMPARE(m_barset->count(), 0); |
|
349 | QCOMPARE(m_barset->count(), 0); | |
358 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
350 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
359 |
|
351 | |||
360 | m_barset->append(1.0); |
|
352 | m_barset->append(1.0); | |
361 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); |
|
353 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); | |
362 | m_barset->append(2.0); |
|
354 | m_barset->append(2.0); | |
363 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); |
|
355 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); | |
364 | m_barset->append(3.0); |
|
356 | m_barset->append(3.0); | |
365 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); |
|
357 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); | |
366 | m_barset->append(4.0); |
|
358 | m_barset->append(4.0); | |
367 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); |
|
359 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); | |
368 | } |
|
360 | } | |
369 |
|
361 | |||
370 | void tst_QBarSet::customize() |
|
362 | void tst_QBarSet::customize() | |
371 | { |
|
363 | { | |
372 | // Create sets |
|
364 | // Create sets | |
373 | QBarSet *set1 = new QBarSet("set1"); |
|
365 | QBarSet *set1 = new QBarSet("set1"); | |
374 | QBarSet *set2 = new QBarSet("set2"); |
|
366 | QBarSet *set2 = new QBarSet("set2"); | |
375 |
|
367 | |||
376 | // Append set1 to series |
|
368 | // Append set1 to series | |
377 | QGroupedBarSeries *series = new QGroupedBarSeries(); |
|
369 | QGroupedBarSeries *series = new QGroupedBarSeries(); | |
378 | bool success = series->append(set1); |
|
370 | bool success = series->append(set1); | |
379 | QVERIFY(success); |
|
371 | QVERIFY(success); | |
380 |
|
372 | |||
381 | // Add series to the chart |
|
373 | // Add series to the chart | |
382 | QChartView view(new QChart()); |
|
374 | QChartView view(new QChart()); | |
383 | view.resize(200, 200); |
|
375 | view.resize(200, 200); | |
384 | view.chart()->addSeries(series); |
|
376 | view.chart()->addSeries(series); | |
385 | view.show(); |
|
377 | view.show(); | |
386 | QTest::qWaitForWindowShown(&view); |
|
378 | QTest::qWaitForWindowShown(&view); | |
387 |
|
379 | |||
388 | // Test adding data to the sets |
|
380 | // Test adding data to the sets | |
389 | *set1 << 1 << 2 << 1 << 3; |
|
381 | *set1 << 1 << 2 << 1 << 3; | |
390 | *set2 << 2 << 1 << 3 << 1; |
|
382 | *set2 << 2 << 1 << 3 << 1; | |
391 |
|
383 | |||
392 | // Test pen |
|
384 | // Test pen | |
393 | QVERIFY(set1->pen() != QPen()); |
|
385 | QVERIFY(set1->pen() != QPen()); | |
394 | QVERIFY(set2->pen() == QPen()); |
|
386 | QVERIFY(set2->pen() == QPen()); | |
395 | QPen pen(QColor(128,128,128,128)); |
|
387 | QPen pen(QColor(128,128,128,128)); | |
396 | set1->setPen(pen); |
|
388 | set1->setPen(pen); | |
397 | QVERIFY(set1->pen() == pen); |
|
389 | QVERIFY(set1->pen() == pen); | |
398 | QVERIFY(set2->pen() == QPen()); |
|
390 | QVERIFY(set2->pen() == QPen()); | |
399 |
|
391 | |||
400 | // Test brush |
|
392 | // Test brush | |
401 | QVERIFY(set1->brush() != QBrush()); |
|
393 | QVERIFY(set1->brush() != QBrush()); | |
402 | QVERIFY(set2->brush() == QBrush()); |
|
394 | QVERIFY(set2->brush() == QBrush()); | |
403 | QBrush brush(QColor(128,128,128,128)); |
|
395 | QBrush brush(QColor(128,128,128,128)); | |
404 | set1->setBrush(brush); |
|
396 | set1->setBrush(brush); | |
405 | QVERIFY(set1->brush() == brush); |
|
397 | QVERIFY(set1->brush() == brush); | |
406 | QVERIFY(set2->brush() == QBrush()); |
|
398 | QVERIFY(set2->brush() == QBrush()); | |
407 |
|
399 | |||
408 | // Test label brush |
|
400 | // Test label brush | |
409 | QVERIFY(set1->labelBrush() != QBrush()); |
|
401 | QVERIFY(set1->labelBrush() != QBrush()); | |
410 | QVERIFY(set2->labelBrush() == QBrush()); |
|
402 | QVERIFY(set2->labelBrush() == QBrush()); | |
411 | set1->setLabelBrush(brush); |
|
403 | set1->setLabelBrush(brush); | |
412 | QVERIFY(set1->labelBrush() == brush); |
|
404 | QVERIFY(set1->labelBrush() == brush); | |
413 | QVERIFY(set2->labelBrush() == QBrush()); |
|
405 | QVERIFY(set2->labelBrush() == QBrush()); | |
414 |
|
406 | |||
415 | // Test label font |
|
407 | // Test label font | |
416 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the |
|
408 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the | |
417 | // same for the set added to the series (depending on the QChart's theme configuration) |
|
409 | // same for the set added to the series (depending on the QChart's theme configuration) | |
418 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); |
|
410 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); | |
419 | QVERIFY(set2->labelFont() == QFont()); |
|
411 | QVERIFY(set2->labelFont() == QFont()); | |
420 | QFont font; |
|
412 | QFont font; | |
421 | font.setBold(true); |
|
413 | font.setBold(true); | |
422 | font.setItalic(true); |
|
414 | font.setItalic(true); | |
423 | set1->setLabelFont(font); |
|
415 | set1->setLabelFont(font); | |
424 | QVERIFY(set1->labelFont() == font); |
|
416 | QVERIFY(set1->labelFont() == font); | |
425 | QVERIFY(set2->labelFont() == QFont()); |
|
417 | QVERIFY(set2->labelFont() == QFont()); | |
426 |
|
418 | |||
427 | // Test adding data to the sets |
|
419 | // Test adding data to the sets | |
428 | *set1 << 1 << 2 << 1 << 3; |
|
420 | *set1 << 1 << 2 << 1 << 3; | |
429 | *set2 << 2 << 1 << 3 << 1; |
|
421 | *set2 << 2 << 1 << 3 << 1; | |
430 | } |
|
422 | } | |
431 |
|
423 | |||
432 | QTEST_MAIN(tst_QBarSet) |
|
424 | QTEST_MAIN(tst_QBarSet) | |
433 |
|
425 | |||
434 | #include "tst_qbarset.moc" |
|
426 | #include "tst_qbarset.moc" | |
435 |
|
427 |
General Comments 0
You need to be logged in to leave comments.
Login now