File indexing completed on 2024-05-12 16:35:57
0001 /* This file is part of the KDE project 0002 Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #define KS_colMax 10 0021 #define KS_rowMax 10 0022 0023 #include "TestPointStorage.h" 0024 0025 #include "PointStorage.h" 0026 0027 #include <QTest> 0028 0029 using namespace Calligra::Sheets; 0030 0031 void PointStorageTest::testInsertion() 0032 { 0033 PointStorage<int> storage; 0034 // int counter = 1; 0035 // for ( int col = 1; col <= 5; ++col ) 0036 // for ( int row = 1; row <= 5; ++row ) 0037 // cout << qPrintable( QString( "storage.insert( %1, %2, %3 );" ).arg(col,2).arg(row,2).arg(counter++,2) ) << endl; storage.insert( 1, 1, 1 ); 0038 storage.insert(1, 1, 1); 0039 storage.insert(1, 2, 2); 0040 storage.insert(1, 3, 3); 0041 storage.insert(1, 4, 4); 0042 storage.insert(1, 5, 5); 0043 storage.insert(2, 1, 6); 0044 storage.insert(2, 2, 7); 0045 storage.insert(2, 3, 8); 0046 storage.insert(2, 4, 9); 0047 storage.insert(2, 5, 10); 0048 storage.insert(3, 1, 11); 0049 storage.insert(3, 2, 12); 0050 storage.insert(3, 3, 13); 0051 storage.insert(3, 4, 14); 0052 storage.insert(3, 5, 15); 0053 storage.insert(4, 1, 16); 0054 storage.insert(4, 2, 17); 0055 storage.insert(4, 3, 18); 0056 storage.insert(4, 4, 19); 0057 storage.insert(4, 5, 20); 0058 storage.insert(5, 1, 21); 0059 storage.insert(5, 2, 22); 0060 storage.insert(5, 3, 23); 0061 storage.insert(5, 4, 24); 0062 storage.insert(5, 5, 25); 0063 // overwrite 0064 int old = storage.insert(5, 5, 30); 0065 QCOMPARE(old, 25); 0066 // ( 1, 6,11,16,21) 0067 // ( 2, 7,12,17,22) 0068 // ( 3, 8,13,18,23) 0069 // ( 4, 9,14,19,24) 0070 // ( 5,10,15,20,25) 0071 // qDebug() << endl << qPrintable( storage.dump() ); 0072 0073 QVector<int> data(QVector<int>() << 1 << 6 << 11 << 16 << 21 0074 << 2 << 7 << 12 << 17 << 22 0075 << 3 << 8 << 13 << 18 << 23 0076 << 4 << 9 << 14 << 19 << 24 0077 << 5 << 10 << 15 << 20 << 30); 0078 QVector<int> rows(QVector<int>() << 0 << 5 << 10 << 15 << 20); 0079 QVector<int> cols(QVector<int>() << 1 << 2 << 3 << 4 << 5 0080 << 1 << 2 << 3 << 4 << 5 0081 << 1 << 2 << 3 << 4 << 5 0082 << 1 << 2 << 3 << 4 << 5 0083 << 1 << 2 << 3 << 4 << 5); 0084 QCOMPARE(storage.m_data, data); 0085 QCOMPARE(storage.m_rows, rows); 0086 QCOMPARE(storage.m_cols, cols); 0087 // qDebug() << "data result: " << storage.m_data; 0088 // qDebug() << "data expect: " << data; 0089 // qDebug() << "rows result: " << storage.m_rows; 0090 // qDebug() << "rows expect: " << rows; 0091 // qDebug() << "cols result: " << storage.m_cols; 0092 // qDebug() << "cols expect: " << cols; 0093 0094 0095 // reverse filling 0096 storage.clear(); 0097 storage.insert(2, 2, 4); 0098 storage.insert(1, 2, 3); 0099 storage.insert(2, 1, 2); 0100 storage.insert(1, 1, 1); 0101 // ( 1, 2) 0102 // ( 3, 4) 0103 0104 data = QVector<int>() << 1 << 2 << 3 << 4; 0105 rows = QVector<int>() << 0 << 2; 0106 cols = QVector<int>() << 1 << 2 << 1 << 2; 0107 QCOMPARE(storage.m_data, data); 0108 QCOMPARE(storage.m_rows, rows); 0109 QCOMPARE(storage.m_cols, cols); 0110 } 0111 0112 void PointStorageTest::testLookup() 0113 { 0114 PointStorage<int> storage; 0115 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0116 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0117 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0118 // ( 1, 2, , , 3) 0119 // ( 4, 5, 6, , ) 0120 // ( , 7, 8, , 9) 0121 // ( , , ,10, ) 0122 // (11, , , ,12) 0123 0124 QCOMPARE(storage.lookup(1, 1), 1); 0125 QCOMPARE(storage.lookup(1, 2), 4); 0126 QCOMPARE(storage.lookup(1, 3), 0); 0127 QCOMPARE(storage.lookup(1, 4), 0); 0128 QCOMPARE(storage.lookup(1, 5), 11); 0129 QCOMPARE(storage.lookup(2, 1), 2); 0130 QCOMPARE(storage.lookup(2, 2), 5); 0131 QCOMPARE(storage.lookup(2, 3), 7); 0132 QCOMPARE(storage.lookup(2, 4), 0); 0133 QCOMPARE(storage.lookup(2, 5), 0); 0134 QCOMPARE(storage.lookup(3, 1), 0); 0135 QCOMPARE(storage.lookup(3, 2), 6); 0136 QCOMPARE(storage.lookup(3, 3), 8); 0137 QCOMPARE(storage.lookup(3, 4), 0); 0138 QCOMPARE(storage.lookup(3, 5), 0); 0139 QCOMPARE(storage.lookup(4, 1), 0); 0140 QCOMPARE(storage.lookup(4, 2), 0); 0141 QCOMPARE(storage.lookup(4, 3), 0); 0142 QCOMPARE(storage.lookup(4, 4), 10); 0143 QCOMPARE(storage.lookup(4, 5), 0); 0144 QCOMPARE(storage.lookup(5, 1), 3); 0145 QCOMPARE(storage.lookup(5, 2), 0); 0146 QCOMPARE(storage.lookup(5, 3), 9); 0147 QCOMPARE(storage.lookup(5, 4), 0); 0148 QCOMPARE(storage.lookup(5, 5), 12); 0149 0150 0151 // empty row checking 0152 storage.clear(); 0153 storage.insert(1, 1, 1); 0154 // ( 1) 0155 0156 QCOMPARE(storage.lookup(1, 1), 1); 0157 QCOMPARE(storage.lookup(2, 1), 0); 0158 QCOMPARE(storage.lookup(1, 2), 0); 0159 QCOMPARE(storage.lookup(2, 2), 0); 0160 } 0161 0162 void PointStorageTest::testDeletion() 0163 { 0164 PointStorage<int> storage; 0165 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0166 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0167 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0168 // ( 1, 2, , , 3) 0169 // ( 4, 5, 6, , ) 0170 // ( , 7, 8, , 9) 0171 // ( , , ,10, ) 0172 // (11, , , ,12) 0173 int old = storage.take(4, 4); 0174 QCOMPARE(old, 10); 0175 old = storage.take(5, 1); 0176 QCOMPARE(old, 3); 0177 old = storage.take(2, 2); 0178 QCOMPARE(old, 5); 0179 // ( 1, 2, , , ) 0180 // ( 4, , 6, , ) 0181 // ( , 7, 8, , 9) 0182 // ( , , , , ) 0183 // (11, , , ,12) 0184 0185 const QVector<int> data(QVector<int>() << 1 << 2 << 4 << 6 << 7 << 8 << 9 << 11 << 12); 0186 const QVector<int> rows(QVector<int>() << 0 << 2 << 4 << 7 << 7); 0187 const QVector<int> cols(QVector<int>() << 1 << 2 << 1 << 3 << 2 << 3 << 5 << 1 << 5); 0188 QCOMPARE(storage.m_data, data); 0189 QCOMPARE(storage.m_rows, rows); 0190 QCOMPARE(storage.m_cols, cols); 0191 0192 0193 // empty row checking 0194 storage.clear(); 0195 storage.insert(1, 1, 1); 0196 // ( 1) 0197 0198 old = storage.take(2, 2); 0199 QCOMPARE(old, 0); 0200 old = storage.take(1, 2); 0201 QCOMPARE(old, 0); 0202 0203 old = storage.take(2, 1); 0204 QCOMPARE(old, 0); 0205 old = storage.take(1, 1); 0206 QCOMPARE(old, 1); 0207 QCOMPARE(storage.lookup(1, 1), 0); 0208 QCOMPARE(storage.lookup(2, 1), 0); 0209 QCOMPARE(storage.lookup(1, 2), 0); 0210 QCOMPARE(storage.lookup(2, 2), 0); 0211 } 0212 0213 void PointStorageTest::testInsertColumns() 0214 { 0215 PointStorage<int> storage; 0216 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0217 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0218 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0219 // ( 1, 2, , , 3) 0220 // ( 4, 5, 6, , ) 0221 // ( , 7, 8, , 9) 0222 // ( , , ,10, ) 0223 // (11, , , ,12) 0224 0225 QVector< QPair<QPoint, int> > old; 0226 old = storage.insertColumns(2, 2); // in the middle 0227 QVERIFY(old.count() == 0); 0228 0229 old = storage.insertColumns(9, 1); // beyond the current end 0230 QVERIFY(old.count() == 0); 0231 // ( 1, , , 2, , , 3) 0232 // ( 4, , , 5, 6, , ) 0233 // ( , , , 7, 8, , 9) 0234 // ( , , , , ,10, ) 0235 // (11, , , , , ,12) 0236 0237 QVector<int> data(QVector<int>() << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12); 0238 QVector<int> rows(QVector<int>() << 0 << 3 << 6 << 9 << 10); 0239 QVector<int> cols(QVector<int>() << 1 << 4 << 7 << 1 << 4 << 5 << 4 << 5 << 7 << 6 << 1 << 7); 0240 QCOMPARE(storage.m_data, data); 0241 QCOMPARE(storage.m_rows, rows); 0242 QCOMPARE(storage.m_cols, cols); 0243 0244 old = storage.insertColumns(6, 4); // shift the last column out of range 0245 QVERIFY(old.count() == 3); 0246 QVERIFY(old.contains(qMakePair(QPoint(7, 1), 3))); 0247 QVERIFY(old.contains(qMakePair(QPoint(7, 3), 9))); 0248 QVERIFY(old.contains(qMakePair(QPoint(7, 5), 12))); 0249 // ( 1, , , 2, , , , , , ) 0250 // ( 4, , , 5, 6, , , , , ) 0251 // ( , , , 7, 8, , , , , ) 0252 // ( , , , , , , , , ,10) 0253 // (11, , , , , , , , , ) 0254 0255 data = QVector<int>() << 1 << 2 << 4 << 5 << 6 << 7 << 8 << 10 << 11; 0256 rows = QVector<int>() << 0 << 2 << 5 << 7 << 8; 0257 cols = QVector<int>() << 1 << 4 << 1 << 4 << 5 << 4 << 5 << 10 << 1; 0258 QCOMPARE(storage.m_data, data); 0259 QCOMPARE(storage.m_rows, rows); 0260 QCOMPARE(storage.m_cols, cols); 0261 0262 0263 // empty row checking 0264 storage.clear(); 0265 storage.insert(1, 1, 1); 0266 // ( 1) 0267 0268 old = storage.insertColumns(1, 1); 0269 QVERIFY(old.count() == 0); 0270 // ( , 1) 0271 0272 data = QVector<int>() << 1; 0273 rows = QVector<int>() << 0; 0274 cols = QVector<int>() << 2; 0275 QCOMPARE(storage.m_data, data); 0276 QCOMPARE(storage.m_rows, rows); 0277 QCOMPARE(storage.m_cols, cols); 0278 } 0279 0280 void PointStorageTest::testDeleteColumns() 0281 { 0282 PointStorage<int> storage; 0283 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0284 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0285 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0286 // ( 1, 2, , , 3) 0287 // ( 4, 5, 6, , ) 0288 // ( , 7, 8, , 9) 0289 // ( , , ,10, ) 0290 // (11, , , ,12) 0291 0292 QVector< QPair<QPoint, int> > old; 0293 old = storage.removeColumns(2, 2); // in the middle 0294 QVERIFY(old.count() == 5); 0295 QVERIFY(old.contains(qMakePair(QPoint(2, 1), 2))); 0296 QVERIFY(old.contains(qMakePair(QPoint(2, 2), 5))); 0297 QVERIFY(old.contains(qMakePair(QPoint(3, 2), 6))); 0298 QVERIFY(old.contains(qMakePair(QPoint(2, 3), 7))); 0299 QVERIFY(old.contains(qMakePair(QPoint(3, 3), 8))); 0300 0301 old = storage.removeColumns(3, 1); // beyond the current end 0302 QVERIFY(old.count() == 3); 0303 QVERIFY(old.contains(qMakePair(QPoint(3, 1), 3))); 0304 QVERIFY(old.contains(qMakePair(QPoint(3, 3), 9))); 0305 QVERIFY(old.contains(qMakePair(QPoint(3, 5), 12))); 0306 0307 // ( 1, ) 0308 // ( 4, ) 0309 // ( , ) 0310 // ( ,10) 0311 // (11, ) 0312 0313 const QVector<int> data(QVector<int>() << 1 << 4 << 10 << 11); 0314 const QVector<int> rows(QVector<int>() << 0 << 1 << 2 << 2 << 3); 0315 const QVector<int> cols(QVector<int>() << 1 << 1 << 2 << 1); 0316 QCOMPARE(storage.m_data, data); 0317 QCOMPARE(storage.m_rows, rows); 0318 QCOMPARE(storage.m_cols, cols); 0319 } 0320 0321 void PointStorageTest::testInsertRows() 0322 { 0323 PointStorage<int> storage; 0324 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0325 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0326 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0327 // ( 1, 2, , , 3) 0328 // ( 4, 5, 6, , ) 0329 // ( , 7, 8, , 9) 0330 // ( , , ,10, ) 0331 // (11, , , ,12) 0332 0333 QVector< QPair<QPoint, int> > old; 0334 old = storage.insertRows(2, 2); // in the middle 0335 QVERIFY(old.count() == 0); 0336 0337 old = storage.insertRows(9, 1); // beyond the current end 0338 QVERIFY(old.count() == 0); 0339 0340 // ( 1, 2, , , 3) 0341 // ( , , , , ) 0342 // ( , , , , ) 0343 // ( 4, 5, 6, , ) 0344 // ( , 7, 8, , 9) 0345 // ( , , ,10, ) 0346 // (11, , , ,12) 0347 0348 QVector<int> data(QVector<int>() << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12); 0349 QVector<int> rows(QVector<int>() << 0 << 3 << 3 << 3 << 6 << 9 << 10); 0350 QVector<int> cols(QVector<int>() << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5); 0351 QCOMPARE(storage.m_data, data); 0352 QCOMPARE(storage.m_rows, rows); 0353 QCOMPARE(storage.m_cols, cols); 0354 0355 0356 old = storage.insertRows(6, 4); // shift the last row out of range 0357 QVERIFY(old.count() == 2); 0358 QVERIFY(old.contains(qMakePair(QPoint(1, 7), 11))); 0359 QVERIFY(old.contains(qMakePair(QPoint(5, 7), 12))); 0360 // ( 1, 2, , , 3) 0361 // ( , , , , ) 0362 // ( , , , , ) 0363 // ( 4, 5, 6, , ) 0364 // ( , 7, 8, , 9) 0365 // ( , , , , ) 0366 // ( , , , , ) 0367 // ( , , , , ) 0368 // ( , , , , ) 0369 // ( , , ,10, ) 0370 0371 data = QVector<int>() << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10; 0372 rows = QVector<int>() << 0 << 3 << 3 << 3 << 6 << 9 << 9 << 9 << 9 << 9; 0373 cols = QVector<int>() << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4; 0374 QCOMPARE(storage.m_data, data); 0375 QCOMPARE(storage.m_rows, rows); 0376 QCOMPARE(storage.m_cols, cols); 0377 0378 0379 // first row checking 0380 storage.clear(); 0381 storage.insert(1, 1, 1); 0382 // ( 1) 0383 0384 old = storage.insertRows(1, 1); 0385 QVERIFY(old.count() == 0); 0386 // ( ) 0387 // ( 1) 0388 0389 data = QVector<int>() << 1; 0390 rows = QVector<int>() << 0 << 0; 0391 cols = QVector<int>() << 1; 0392 QCOMPARE(storage.m_data, data); 0393 QCOMPARE(storage.m_rows, rows); 0394 QCOMPARE(storage.m_cols, cols); 0395 } 0396 0397 void PointStorageTest::testDeleteRows() 0398 { 0399 PointStorage<int> storage; 0400 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0401 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0402 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0403 // ( 1, 2, , , 3) 0404 // ( 4, 5, 6, , ) 0405 // ( , 7, 8, , 9) 0406 // ( , , ,10, ) 0407 // (11, , , ,12) 0408 0409 QVector< QPair<QPoint, int> > old; 0410 old = storage.removeRows(2, 2); // in the middle 0411 QVERIFY(old.count() == 6); 0412 QVERIFY(old.contains(qMakePair(QPoint(1, 2), 4))); 0413 QVERIFY(old.contains(qMakePair(QPoint(2, 2), 5))); 0414 QVERIFY(old.contains(qMakePair(QPoint(3, 2), 6))); 0415 QVERIFY(old.contains(qMakePair(QPoint(2, 3), 7))); 0416 QVERIFY(old.contains(qMakePair(QPoint(3, 3), 8))); 0417 QVERIFY(old.contains(qMakePair(QPoint(5, 3), 9))); 0418 0419 old = storage.removeRows(3, 1); // at the current end 0420 QVERIFY(old.count() == 2); 0421 QVERIFY(old.contains(qMakePair(QPoint(1, 3), 11))); 0422 QVERIFY(old.contains(qMakePair(QPoint(5, 3), 12))); 0423 // ( 1, 2, , , 3) 0424 // ( , , ,10, ) 0425 0426 const QVector<int> data(QVector<int>() << 1 << 2 << 3 << 10); 0427 const QVector<int> rows(QVector<int>() << 0 << 3); 0428 const QVector<int> cols(QVector<int>() << 1 << 2 << 5 << 4); 0429 QCOMPARE(storage.m_data, data); 0430 QCOMPARE(storage.m_rows, rows); 0431 QCOMPARE(storage.m_cols, cols); 0432 } 0433 0434 void PointStorageTest::testShiftLeft() 0435 { 0436 PointStorage<int> storage; 0437 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0438 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0439 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0440 // ( 1, 2, , , 3) 0441 // ( 4, 5, 6, , ) 0442 // ( , 7, 8, , 9) 0443 // ( , , ,10, ) 0444 // (11, , , ,12) 0445 0446 QVector< QPair<QPoint, int> > old; 0447 old = storage.removeShiftLeft(QRect(2, 2, 2, 2)); 0448 QVERIFY(old.count() == 4); 0449 QVERIFY(old.contains(qMakePair(QPoint(2, 2), 5))); 0450 QVERIFY(old.contains(qMakePair(QPoint(3, 2), 6))); 0451 QVERIFY(old.contains(qMakePair(QPoint(2, 3), 7))); 0452 QVERIFY(old.contains(qMakePair(QPoint(3, 3), 8))); 0453 0454 old = storage.removeShiftLeft(QRect(5, 5, 1, 1)); 0455 QVERIFY(old.count() == 1); 0456 QVERIFY(old.contains(qMakePair(QPoint(5, 5), 12))); 0457 // ( 1, 2, , , 3) 0458 // ( 4, , , , ) 0459 // ( , , 9, , ) 0460 // ( , , ,10, ) 0461 // (11, , , , ) 0462 0463 const QVector<int> data(QVector<int>() << 1 << 2 << 3 << 4 << 9 << 10 << 11); 0464 const QVector<int> rows(QVector<int>() << 0 << 3 << 4 << 5 << 6); 0465 const QVector<int> cols(QVector<int>() << 1 << 2 << 5 << 1 << 3 << 4 << 1); 0466 QCOMPARE(storage.m_data, data); 0467 QCOMPARE(storage.m_rows, rows); 0468 QCOMPARE(storage.m_cols, cols); 0469 } 0470 0471 void PointStorageTest::testShiftRight() 0472 { 0473 PointStorage<int> storage; 0474 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0475 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0476 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0477 // ( 1, 2, , , 3) 0478 // ( 4, 5, 6, , ) 0479 // ( , 7, 8, , 9) 0480 // ( , , ,10, ) 0481 // (11, , , ,12) 0482 0483 QVector< QPair<QPoint, int> > old; 0484 old = storage.insertShiftRight(QRect(2, 2, 2, 2)); 0485 QVERIFY(old.count() == 0); 0486 0487 old = storage.insertShiftRight(QRect(5, 5, 1, 1)); 0488 QVERIFY(old.count() == 0); 0489 // ( 1, 2, , , 3, , ) 0490 // ( 4, , , 5, 6, , ) 0491 // ( , , , 7, 8, , 9) 0492 // ( , , ,10, , , ) 0493 // (11, , , , ,12, ) 0494 0495 QVector<int> data(QVector<int>() << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12); 0496 QVector<int> rows(QVector<int>() << 0 << 3 << 6 << 9 << 10); 0497 QVector<int> cols(QVector<int>() << 1 << 2 << 5 << 1 << 4 << 5 << 4 << 5 << 7 << 4 << 1 << 6); 0498 QCOMPARE(storage.m_data, data); 0499 QCOMPARE(storage.m_rows, rows); 0500 QCOMPARE(storage.m_cols, cols); 0501 0502 0503 old = storage.insertShiftRight(QRect(4, 2, 6, 1)); // shift the 6 out of range 0504 QVERIFY(old.count() == 1); 0505 QVERIFY(old.contains(qMakePair(QPoint(5, 2), 6))); 0506 // ( 1, 2, , , 3, , , , , ) 0507 // ( 4, , , , , , , , , 5) 0508 // ( , , , 7, 8, , 9, , , ) 0509 // ( , , ,10, , , , , , ) 0510 // (11, , , , ,12, , , , ) 0511 0512 data = QVector<int>() << 1 << 2 << 3 << 4 << 5 << 7 << 8 << 9 << 10 << 11 << 12; 0513 rows = QVector<int>() << 0 << 3 << 5 << 8 << 9; 0514 cols = QVector<int>() << 1 << 2 << 5 << 1 << 10 << 4 << 5 << 7 << 4 << 1 << 6; 0515 QCOMPARE(storage.m_data, data); 0516 QCOMPARE(storage.m_rows, rows); 0517 QCOMPARE(storage.m_cols, cols); 0518 } 0519 0520 void PointStorageTest::testShiftUp() 0521 { 0522 PointStorage<int> storage; 0523 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0524 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0525 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0526 // ( 1, 2, , , 3) 0527 // ( 4, 5, 6, , ) 0528 // ( , 7, 8, , 9) 0529 // ( , , ,10, ) 0530 // (11, , , ,12) 0531 0532 QRect rect; 0533 QVector< QPair<QPoint, int> > old; 0534 rect = QRect(2, 2, 2, 1); 0535 old = storage.removeShiftUp(rect); 0536 // qDebug() << "moved two filled cells up onto filled cells:"<<rect<< endl << qPrintable( storage.dump() ); 0537 QVERIFY(old.count() == 2); 0538 QVERIFY(old.contains(qMakePair(QPoint(2, 2), 5))); 0539 QVERIFY(old.contains(qMakePair(QPoint(3, 2), 6))); 0540 0541 rect = QRect(5, 5, 1, 1); 0542 old = storage.removeShiftUp(rect); // shift data from 6,5 -> 5,5 0543 // qDebug() << "moved 1 cell from non-existent row onto filled cell:"<<rect << endl << qPrintable( storage.dump() ); 0544 QVERIFY(old.count() == 1); 0545 QVERIFY(old.contains(qMakePair(QPoint(5, 5), 12))); 0546 // ( 1, 2, , , 3) 0547 // ( 4, 7, 8, , ) 0548 // ( , , , , 9) 0549 // ( , , ,10, ) 0550 // (11, , , , ) 0551 0552 QVector<int> data(QVector<int>() << 1 << 2 << 3 << 4 << 7 << 8 << 9 << 10 << 11); 0553 QVector<int> rows(QVector<int>() << 0 << 3 << 6 << 7 << 8); 0554 QVector<int> cols(QVector<int>() << 1 << 2 << 5 << 1 << 2 << 3 << 5 << 4 << 1); 0555 QCOMPARE(storage.m_data, data); 0556 QCOMPARE(storage.m_rows, rows); 0557 QCOMPARE(storage.m_cols, cols); 0558 0559 rect = QRect(1, 4, 1, 1); 0560 old = storage.removeShiftUp(rect); 0561 // qDebug() << "moved 1 filled cell onto unfilled cell:"<<rect << endl << qPrintable( storage.dump() ); 0562 QCOMPARE(old.count(), 0); 0563 0564 0565 // first row 0566 storage.clear(); 0567 storage.m_data << 1 << 2 << 3 << 4; 0568 storage.m_rows << 0 << 1 << 3; 0569 storage.m_cols << 1 << 1 << 2 << 2; 0570 // ( 1, ) 0571 // ( 2, 3) 0572 // ( , 4) 0573 // qDebug() << "start:" << endl << qPrintable( storage.dump() ); 0574 0575 old = storage.removeShiftUp(QRect(1, 1, 2, 2)); 0576 // qDebug() << "moved 1 filled, 1 unfilled two rows up onto 1 row:"<<QRect(1, 1, 2, 2) << endl << qPrintable( storage.dump() ); 0577 qDebug() << old; 0578 QVERIFY(old.count() == 3); 0579 QVERIFY(old.contains(qMakePair(QPoint(1, 1), 1))); 0580 QVERIFY(old.contains(qMakePair(QPoint(1, 2), 2))); 0581 QVERIFY(old.contains(qMakePair(QPoint(2, 2), 3))); 0582 // ( , 4) 0583 QCOMPARE(storage.rows(), 1); 0584 QCOMPARE(storage.columns(), 2); 0585 0586 data = QVector<int>() << 4; 0587 rows = QVector<int>() << 0; 0588 cols = QVector<int>() << 2; 0589 QCOMPARE(storage.m_data, data); 0590 QCOMPARE(storage.m_rows, rows); 0591 QCOMPARE(storage.m_cols, cols); 0592 } 0593 0594 void PointStorageTest::testShiftDown() 0595 { 0596 PointStorage<int> storage; 0597 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0598 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0599 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0600 // ( 1, 2, , , 3) 0601 // ( 4, 5, 6, , ) 0602 // ( , 7, 8, , 9) 0603 // ( , , ,10, ) 0604 // (11, , , ,12) 0605 0606 QVector< QPair<QPoint, int> > old; 0607 old = storage.insertShiftDown(QRect(2, 2, 2, 2)); 0608 QVERIFY(old.count() == 0); 0609 0610 old = storage.insertShiftDown(QRect(5, 5, 1, 1)); 0611 QVERIFY(old.count() == 0); 0612 // ( 1, 2, , , 3) 0613 // ( 4, , , , ) 0614 // ( , , , , 9) 0615 // ( , 5, 6,10, ) 0616 // (11, 7, 8, , ) 0617 // ( , , , ,12) 0618 0619 QVector<int> data(QVector<int>() << 1 << 2 << 3 << 4 << 9 << 5 << 6 << 10 << 11 << 7 << 8 << 12); 0620 QVector<int> rows(QVector<int>() << 0 << 3 << 4 << 5 << 8 << 11); 0621 QVector<int> cols(QVector<int>() << 1 << 2 << 5 << 1 << 5 << 2 << 3 << 4 << 1 << 2 << 3 << 5); 0622 QCOMPARE(storage.m_data, data); 0623 QCOMPARE(storage.m_rows, rows); 0624 QCOMPARE(storage.m_cols, cols); 0625 0626 0627 old = storage.insertShiftDown(QRect(2, 4, 1, 6)); // shift the 7 out of range 0628 QVERIFY(old.count() == 1); 0629 QVERIFY(old.contains(qMakePair(QPoint(2, 5), 7))); 0630 // ( 1, 2, , , 3) 0631 // ( 4, , , , ) 0632 // ( , , , , 9) 0633 // ( , , 6,10, ) 0634 // (11, , 8, , ) 0635 // ( , , , ,12) 0636 // ( , , , , ) 0637 // ( , , , , ) 0638 // ( , , , , ) 0639 // ( , , , , ) 0640 // ( , 5, , , ) 0641 0642 data = QVector<int>() << 1 << 2 << 3 << 4 << 9 << 6 << 10 << 11 << 8 << 12 << 5; 0643 rows = QVector<int>() << 0 << 3 << 4 << 5 << 7 << 9 << 10 << 10 << 10 << 10; 0644 cols = QVector<int>() << 1 << 2 << 5 << 1 << 5 << 3 << 4 << 1 << 3 << 5 << 2; 0645 QCOMPARE(storage.m_data, data); 0646 QCOMPARE(storage.m_rows, rows); 0647 QCOMPARE(storage.m_cols, cols); 0648 0649 0650 // first row 0651 storage.clear(); 0652 storage.m_data << 1 << 2 << 3 << 4; 0653 storage.m_rows << 0 << 1 << 3; 0654 storage.m_cols << 1 << 1 << 2 << 2; 0655 // ( 1, ) 0656 // ( 2, 3) 0657 // ( , 4) 0658 0659 old = storage.insertShiftDown(QRect(1, 1, 2, 2)); 0660 QVERIFY(old.count() == 0); 0661 // ( , ) 0662 // ( , ) 0663 // ( 1, ) 0664 // ( 2, 3) 0665 // ( , 4) 0666 0667 data = QVector<int>() << 1 << 2 << 3 << 4; 0668 rows = QVector<int>() << 0 << 0 << 0 << 1 << 3; 0669 cols = QVector<int>() << 1 << 1 << 2 << 2; 0670 QCOMPARE(storage.m_data, data); 0671 QCOMPARE(storage.m_rows, rows); 0672 QCOMPARE(storage.m_cols, cols); 0673 } 0674 0675 void PointStorageTest::testShiftDownUp() 0676 { 0677 PointStorage<int> storage; 0678 for (int row = 1; row < 6; ++row) { 0679 for (int col = 1; col < 6; ++col) { 0680 storage.m_data << (row * col); 0681 storage.m_cols << col; 0682 } 0683 storage.m_rows << (5 *(row - 1)); 0684 } 0685 // qDebug() << "Origin:" << endl << qPrintable(storage.dump()); 0686 // ( 1, 2, 3, 4, 5) 0687 // ( 2, 4, 6, 8,10) 0688 // ( 3, 6, 8,12,15) 0689 // ( 4, 8,12,16,20) 0690 // ( 5,10,15,20,25) 0691 0692 QVector<int> data(QVector<int>() << 1 << 2 << 3 << 4 << 5 << 2 << 4 << 6 << 8 << 10 << 3 << 6 << 9 << 12 << 15 << 4 << 8 << 12 << 16 << 20 << 5 << 10 << 15 << 20 << 25); 0693 QVector<int> rows(QVector<int>() << 0 << 5 << 10 << 15 << 20); 0694 QVector<int> cols(QVector<int>() << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5); 0695 QCOMPARE(storage.m_data, data); 0696 QCOMPARE(storage.m_rows, rows); 0697 QCOMPARE(storage.m_cols, cols); 0698 0699 QVector< QPair<QPoint, int> > old; 0700 old = storage.insertShiftDown(QRect(3, 2, 2, 2)); 0701 QVERIFY(old.count() == 0); 0702 0703 // qDebug() << endl << qPrintable(storage.dump()); 0704 // ( 1, 2, 3, 4, 5) 0705 // ( 2, 4, , ,10) 0706 // ( 3, 6, , ,15) 0707 // ( 4, 8, 6, 8,20) 0708 // ( 5,10, 9,12,25) 0709 // ( , ,12,16, ) 0710 // ( , ,15,20, ) 0711 0712 data = QVector<int>() << 1 << 2 << 3 << 4 << 5 << 2 << 4 << 10 << 3 << 6 << 15 << 4 << 8 << 6 << 8 << 20 << 5 << 10 << 9 << 12 << 25 << 12 << 16 << 15 << 20; 0713 cols = QVector<int>() << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 5 << 1 << 2 << 5 << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5 << 3 << 4 << 3 << 4; 0714 rows = QVector<int>() << 0 << 5 << 8 << 11 << 16 << 21 << 23; 0715 QCOMPARE(storage.m_data, data); 0716 QCOMPARE(storage.m_rows, rows); 0717 QCOMPARE(storage.m_cols, cols); 0718 0719 old = storage.removeShiftUp(QRect(3, 2, 2, 2)); 0720 QVERIFY(old.count() == 0); 0721 0722 data = QVector<int>() << 1 << 2 << 3 << 4 << 5 << 2 << 4 << 6 << 8 << 10 << 3 << 6 << 9 << 12 << 15 << 4 << 8 << 12 << 16 << 20 << 5 << 10 << 15 << 20 << 25; 0723 rows = QVector<int>() << 0 << 5 << 10 << 15 << 20; 0724 cols = QVector<int>() << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5 << 1 << 2 << 3 << 4 << 5; 0725 QCOMPARE(storage.m_data, data); 0726 QCOMPARE(storage.m_rows, rows); 0727 QCOMPARE(storage.m_cols, cols); 0728 } 0729 0730 void PointStorageTest::testFirstInColumn() 0731 { 0732 PointStorage<int> storage; 0733 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0734 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0735 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0736 // ( 1, 2, , , 3) 0737 // ( 4, 5, 6, , ) 0738 // ( , 7, 8, , 9) 0739 // ( , , ,10, ) 0740 // (11, , , ,12) 0741 0742 int newRow = 0; 0743 QCOMPARE(storage.firstInColumn(1, &newRow), 1); 0744 QCOMPARE(newRow, 1); 0745 QCOMPARE(storage.firstInColumn(2, &newRow), 2); 0746 QCOMPARE(newRow, 1); 0747 QCOMPARE(storage.firstInColumn(3, &newRow), 6); 0748 QCOMPARE(newRow, 2); 0749 QCOMPARE(storage.firstInColumn(4, &newRow), 10); 0750 QCOMPARE(newRow, 4); 0751 QCOMPARE(storage.firstInColumn(5, &newRow), 3); 0752 QCOMPARE(newRow, 1); 0753 0754 storage.clear(); 0755 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 11 << 12; 0756 storage.m_rows << 0 << 3 << 6 << 9 << 9; 0757 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 1 << 5; 0758 // ( 1, 2, , , 3) 0759 // ( 4, 5, 6, , ) 0760 // ( , 7, 8, , 9) 0761 // ( , , , , ) 0762 // (11, , , ,12) 0763 0764 QCOMPARE(storage.firstInColumn(4, &newRow), 0); 0765 QCOMPARE(newRow, 0); 0766 QCOMPARE(storage.firstInColumn(5, &newRow), 3); 0767 QCOMPARE(newRow, 1); 0768 } 0769 0770 void PointStorageTest::testFirstInRow() 0771 { 0772 PointStorage<int> storage; 0773 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0774 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0775 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0776 // ( 1, 2, , , 3) 0777 // ( 4, 5, 6, , ) 0778 // ( , 7, 8, , 9) 0779 // ( , , ,10, ) 0780 // (11, , , ,12) 0781 0782 int newCol = 0; 0783 QCOMPARE(storage.firstInRow(1, &newCol), 1); 0784 QCOMPARE(newCol, 1); 0785 QCOMPARE(storage.firstInRow(2, &newCol), 4); 0786 QCOMPARE(newCol, 1); 0787 QCOMPARE(storage.firstInRow(3, &newCol), 7); 0788 QCOMPARE(newCol, 2); 0789 QCOMPARE(storage.firstInRow(4, &newCol), 10); 0790 QCOMPARE(newCol, 4); 0791 QCOMPARE(storage.firstInRow(5, &newCol), 11); 0792 QCOMPARE(newCol, 1); 0793 0794 storage.clear(); 0795 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 11 << 12; 0796 storage.m_rows << 0 << 3 << 6 << 9 << 9; 0797 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 1 << 5; 0798 // ( 1, 2, , , 3) 0799 // ( 4, 5, 6, , ) 0800 // ( , 7, 8, , 9) 0801 // ( , , , , ) 0802 // (11, , , ,12) 0803 0804 QCOMPARE(storage.firstInRow(4, &newCol), 0); 0805 QCOMPARE(newCol, 0); 0806 QCOMPARE(storage.firstInRow(5, &newCol), 11); 0807 QCOMPARE(newCol, 1); 0808 0809 0810 storage.clear(); 0811 storage.m_data << 1; 0812 storage.m_rows << 0 << 0; 0813 storage.m_cols << 1; 0814 // ( ) 0815 // ( 1) 0816 0817 QCOMPARE(storage.firstInRow(1, &newCol), 0); 0818 QCOMPARE(newCol, 0); 0819 QCOMPARE(storage.firstInRow(2, &newCol), 1); 0820 QCOMPARE(newCol, 1); 0821 } 0822 0823 void PointStorageTest::testLastInColumn() 0824 { 0825 PointStorage<int> storage; 0826 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0827 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0828 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0829 // ( 1, 2, , , 3) 0830 // ( 4, 5, 6, , ) 0831 // ( , 7, 8, , 9) 0832 // ( , , ,10, ) 0833 // (11, , , ,12) 0834 0835 int newRow = 0; 0836 QCOMPARE(storage.lastInColumn(1, &newRow), 11); 0837 QCOMPARE(newRow, 5); 0838 QCOMPARE(storage.lastInColumn(2, &newRow), 7); 0839 QCOMPARE(newRow, 3); 0840 QCOMPARE(storage.lastInColumn(3, &newRow), 8); 0841 QCOMPARE(newRow, 3); 0842 QCOMPARE(storage.lastInColumn(4, &newRow), 10); 0843 QCOMPARE(newRow, 4); 0844 QCOMPARE(storage.lastInColumn(5, &newRow), 12); 0845 QCOMPARE(newRow, 5); 0846 QCOMPARE(storage.lastInColumn(6, &newRow), 0); 0847 QCOMPARE(newRow, 0); 0848 } 0849 0850 void PointStorageTest::testLastInRow() 0851 { 0852 PointStorage<int> storage; 0853 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0854 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0855 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0856 // ( 1, 2, , , 3) 0857 // ( 4, 5, 6, , ) 0858 // ( , 7, 8, , 9) 0859 // ( , , ,10, ) 0860 // (11, , , ,12) 0861 0862 int newCol = 0; 0863 QCOMPARE(storage.lastInRow(1, &newCol), 3); 0864 QCOMPARE(newCol, 5); 0865 QCOMPARE(storage.lastInRow(2, &newCol), 6); 0866 QCOMPARE(newCol, 3); 0867 QCOMPARE(storage.lastInRow(3, &newCol), 9); 0868 QCOMPARE(newCol, 5); 0869 QCOMPARE(storage.lastInRow(4, &newCol), 10); 0870 QCOMPARE(newCol, 4); 0871 QCOMPARE(storage.lastInRow(5, &newCol), 12); 0872 QCOMPARE(newCol, 5); 0873 QCOMPARE(storage.lastInRow(6, &newCol), 0); 0874 QCOMPARE(newCol, 0); 0875 } 0876 0877 void PointStorageTest::testNextInColumn() 0878 { 0879 PointStorage<int> storage; 0880 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0881 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0882 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0883 // ( 1, 2, , , 3) 0884 // ( 4, 5, 6, , ) 0885 // ( , 7, 8, , 9) 0886 // ( , , ,10, ) 0887 // (11, , , ,12) 0888 0889 int newRow = 0; 0890 QCOMPARE(storage.nextInColumn(1, 3, &newRow), 11); 0891 QCOMPARE(newRow, 5); 0892 QCOMPARE(storage.nextInColumn(2, 3, &newRow), 0); 0893 QCOMPARE(newRow, 0); 0894 QCOMPARE(storage.nextInColumn(3, 3, &newRow), 0); 0895 QCOMPARE(newRow, 0); 0896 QCOMPARE(storage.nextInColumn(4, 3, &newRow), 10); 0897 QCOMPARE(newRow, 4); 0898 QCOMPARE(storage.nextInColumn(5, 3, &newRow), 12); 0899 QCOMPARE(newRow, 5); 0900 QCOMPARE(storage.nextInColumn(6, 3, &newRow), 0); 0901 QCOMPARE(newRow, 0); 0902 0903 0904 // 0905 storage.clear(); 0906 storage.m_data << 1 << 2 << 3 << 4; 0907 storage.m_rows << 0 << 0 << 0 << 1 << 2; 0908 storage.m_cols << 1 << 1 << 1 << 2; 0909 // ( , ) 0910 // ( , ) 0911 // ( 1, ) 0912 // ( 2, ) 0913 // ( 3, 4) 0914 0915 QCOMPARE(storage.nextInColumn(1, 1, &newRow), 1); 0916 QCOMPARE(newRow, 3); 0917 QCOMPARE(storage.nextInColumn(2, 1, &newRow), 4); 0918 QCOMPARE(newRow, 5); 0919 QCOMPARE(storage.nextInColumn(1, 7, &newRow), 0); 0920 QCOMPARE(newRow, 0); 0921 QCOMPARE(storage.nextInColumn(2, 5, &newRow), 0); 0922 QCOMPARE(newRow, 0); 0923 } 0924 0925 void PointStorageTest::testNextInRow() 0926 { 0927 PointStorage<int> storage; 0928 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0929 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0930 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0931 // ( 1, 2, , , 3) 0932 // ( 4, 5, 6, , ) 0933 // ( , 7, 8, , 9) 0934 // ( , , ,10, ) 0935 // (11, , , ,12) 0936 0937 int newCol = 0; 0938 QCOMPARE(storage.nextInRow(3, 1, &newCol), 3); 0939 QCOMPARE(newCol, 5); 0940 QCOMPARE(storage.nextInRow(3, 2, &newCol), 0); 0941 QCOMPARE(newCol, 0); 0942 QCOMPARE(storage.nextInRow(3, 3, &newCol), 9); 0943 QCOMPARE(newCol, 5); 0944 QCOMPARE(storage.nextInRow(3, 4, &newCol), 10); 0945 QCOMPARE(newCol, 4); 0946 QCOMPARE(storage.nextInRow(3, 5, &newCol), 12); 0947 QCOMPARE(newCol, 5); 0948 QCOMPARE(storage.nextInRow(3, 6, &newCol), 0); 0949 QCOMPARE(newCol, 0); 0950 } 0951 0952 void PointStorageTest::testPrevInColumn() 0953 { 0954 PointStorage<int> storage; 0955 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0956 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0957 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0958 // ( 1, 2, , , 3) 0959 // ( 4, 5, 6, , ) 0960 // ( , 7, 8, , 9) 0961 // ( , , ,10, ) 0962 // (11, , , ,12) 0963 0964 int newRow = 0; 0965 QCOMPARE(storage.prevInColumn(1, 3, &newRow), 4); 0966 QCOMPARE(newRow, 2); 0967 QCOMPARE(storage.prevInColumn(2, 3, &newRow), 5); 0968 QCOMPARE(newRow, 2); 0969 QCOMPARE(storage.prevInColumn(3, 3, &newRow), 6); 0970 QCOMPARE(newRow, 2); 0971 QCOMPARE(storage.prevInColumn(4, 3, &newRow), 0); 0972 QCOMPARE(newRow, 0); 0973 QCOMPARE(storage.prevInColumn(5, 3, &newRow), 3); 0974 QCOMPARE(newRow, 1); 0975 QCOMPARE(storage.prevInColumn(6, 3, &newRow), 0); 0976 QCOMPARE(newRow, 0); 0977 QCOMPARE(storage.prevInColumn(3, 7, &newRow), 8); 0978 QCOMPARE(newRow, 3); 0979 } 0980 0981 void PointStorageTest::testPrevInRow() 0982 { 0983 PointStorage<int> storage; 0984 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 0985 storage.m_rows << 0 << 3 << 6 << 9 << 10; 0986 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 0987 // ( 1, 2, , , 3) 0988 // ( 4, 5, 6, , ) 0989 // ( , 7, 8, , 9) 0990 // ( , , ,10, ) 0991 // (11, , , ,12) 0992 0993 int newCol = 0; 0994 QCOMPARE(storage.prevInRow(3, 1, &newCol), 2); 0995 QCOMPARE(newCol, 2); 0996 QCOMPARE(storage.prevInRow(3, 2, &newCol), 5); 0997 QCOMPARE(newCol, 2); 0998 QCOMPARE(storage.prevInRow(3, 3, &newCol), 7); 0999 QCOMPARE(newCol, 2); 1000 QCOMPARE(storage.prevInRow(3, 4, &newCol), 0); 1001 QCOMPARE(newCol, 0); 1002 QCOMPARE(storage.prevInRow(3, 5, &newCol), 11); 1003 QCOMPARE(newCol, 1); 1004 QCOMPARE(storage.prevInRow(3, 6, &newCol), 0); 1005 QCOMPARE(newCol, 0); 1006 } 1007 1008 void PointStorageTest::testIteration() 1009 { 1010 PointStorage<int> storage; 1011 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 1012 storage.m_rows << 0 << 3 << 6 << 9 << 10; 1013 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 1014 // ( 1, 2, , , 3) 1015 // ( 4, 5, 6, , ) 1016 // ( , 7, 8, , 9) 1017 // ( , , ,10, ) 1018 // (11, , , ,12) 1019 1020 QCOMPARE(storage.data(0), 1); 1021 QCOMPARE(storage.data(1), 2); 1022 QCOMPARE(storage.data(2), 3); 1023 QCOMPARE(storage.data(3), 4); 1024 QCOMPARE(storage.data(4), 5); 1025 QCOMPARE(storage.data(5), 6); 1026 QCOMPARE(storage.data(6), 7); 1027 QCOMPARE(storage.data(7), 8); 1028 QCOMPARE(storage.data(8), 9); 1029 QCOMPARE(storage.data(9), 10); 1030 QCOMPARE(storage.data(10), 11); 1031 QCOMPARE(storage.data(11), 12); 1032 1033 QCOMPARE(storage.col(0), 1); 1034 QCOMPARE(storage.col(1), 2); 1035 QCOMPARE(storage.col(2), 5); 1036 QCOMPARE(storage.col(3), 1); 1037 QCOMPARE(storage.col(4), 2); 1038 QCOMPARE(storage.col(5), 3); 1039 QCOMPARE(storage.col(6), 2); 1040 QCOMPARE(storage.col(7), 3); 1041 QCOMPARE(storage.col(8), 5); 1042 QCOMPARE(storage.col(9), 4); 1043 QCOMPARE(storage.col(10), 1); 1044 QCOMPARE(storage.col(11), 5); 1045 1046 QCOMPARE(storage.row(0), 1); 1047 QCOMPARE(storage.row(1), 1); 1048 QCOMPARE(storage.row(2), 1); 1049 QCOMPARE(storage.row(3), 2); 1050 QCOMPARE(storage.row(4), 2); 1051 QCOMPARE(storage.row(5), 2); 1052 QCOMPARE(storage.row(6), 3); 1053 QCOMPARE(storage.row(7), 3); 1054 QCOMPARE(storage.row(8), 3); 1055 QCOMPARE(storage.row(9), 4); 1056 QCOMPARE(storage.row(10), 5); 1057 QCOMPARE(storage.row(11), 5); 1058 } 1059 1060 void PointStorageTest::testColumnIteration() 1061 { 1062 PointStorage<int> storage; 1063 storage.insert(1, 1, 27); 1064 1065 int row = -1; 1066 QCOMPARE(storage.firstInColumn(1, &row), 27); 1067 QCOMPARE(row, 1); 1068 row = -1; 1069 // QCOMPARE(storage.nextInColumn(1, 0, &row), 27); 1070 // QCOMPARE(row, 1); 1071 QCOMPARE(storage.nextInColumn(1, 1, &row), 0); 1072 QCOMPARE(row, 0); 1073 1074 storage.insert(1, 5, 5); 1075 1076 QCOMPARE(storage.nextInColumn(1, 1, &row), 5); 1077 QCOMPARE(row, 5); 1078 QCOMPARE(storage.nextInColumn(5, 1, &row), 0); 1079 QCOMPARE(row, 0); 1080 row = -1; 1081 QCOMPARE(storage.nextInColumn(6, 1, &row), 0); 1082 QCOMPARE(row, 0); 1083 1084 // reverse iteration 1085 QCOMPARE(storage.lastInColumn(1, &row), 5); 1086 QCOMPARE(row, 5); 1087 row = -1; 1088 // QCOMPARE(storage.prevInColumn(1, KS_rowMax + 1, &row), 5); 1089 // QCOMPARE(row, 5); 1090 QCOMPARE(storage.prevInColumn(1, 6, &row), 5); 1091 QCOMPARE(row, 5); 1092 QCOMPARE(storage.prevInColumn(1, 5, &row), 27); 1093 QCOMPARE(row, 1); 1094 QCOMPARE(storage.prevInColumn(1, 1, &row), 0); 1095 QCOMPARE(row, 0); 1096 } 1097 1098 void PointStorageTest::testRowIteration() 1099 { 1100 PointStorage<int> storage; 1101 storage.insert(1, 1, 27); 1102 1103 int col = -1; 1104 QCOMPARE(storage.firstInRow(1, &col), 27); 1105 QCOMPARE(col, 1); 1106 col = -1; 1107 QCOMPARE(storage.nextInRow(1, 1, &col), 0); 1108 QCOMPARE(col, 0); 1109 1110 storage.insert(5, 1, 5); 1111 // qDebug() << qPrintable(storage.dump()); 1112 QCOMPARE(storage.nextInRow(1, 1, &col), 5); 1113 QCOMPARE(col, 5); 1114 QCOMPARE(storage.nextInRow(1, 5, &col), 0); 1115 QCOMPARE(col, 0); 1116 col = -1; 1117 QCOMPARE(storage.nextInRow(1, 6, &col), 0); 1118 QCOMPARE(col, 0); 1119 1120 // reverse iteration 1121 QCOMPARE(storage.lastInRow(1, &col), 5); 1122 QCOMPARE(col, 5); 1123 col = -1; 1124 // QCOMPARE(storage.prevInRow(KS_colMax + 1, 1, &col), 5); 1125 // QCOMPARE(col, 5); 1126 QCOMPARE(storage.prevInRow(6, 1, &col), 5); 1127 QCOMPARE(col, 5); 1128 QCOMPARE(storage.prevInRow(5, 1, &col), 27); 1129 QCOMPARE(col, 1); 1130 QCOMPARE(storage.prevInRow(1, 1, &col), 0); 1131 QCOMPARE(col, 0); 1132 } 1133 1134 void PointStorageTest::testDimension() 1135 { 1136 PointStorage<int> storage; 1137 QCOMPARE(storage.rows(), 0); 1138 QCOMPARE(storage.columns(), 0); 1139 storage.insert(1, 1, 27); 1140 QCOMPARE(storage.rows(), 1); 1141 QCOMPARE(storage.columns(), 1); 1142 storage.insert(3, 1, 27); 1143 QCOMPARE(storage.rows(), 1); 1144 QCOMPARE(storage.columns(), 3); 1145 storage.insert(3, 9, 27); 1146 QCOMPARE(storage.rows(), 9); 1147 QCOMPARE(storage.columns(), 3); 1148 storage.insert(9, 9, 27); 1149 QCOMPARE(storage.rows(), 9); 1150 QCOMPARE(storage.columns(), 9); 1151 storage.insert(10, 9, 27); 1152 QCOMPARE(storage.rows(), 9); 1153 QCOMPARE(storage.columns(), 10); 1154 storage.insert(10, 10, 27); 1155 QCOMPARE(storage.rows(), 10); 1156 QCOMPARE(storage.columns(), 10); 1157 } 1158 1159 void PointStorageTest::testSubStorage() 1160 { 1161 // #if 0 1162 PointStorage<int> storage; 1163 storage.m_data << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 1164 storage.m_rows << 0 << 3 << 6 << 9 << 10; 1165 storage.m_cols << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 1166 // ( 1, 2, , , 3) 1167 // ( 4, 5, 6, , ) 1168 // ( , 7, 8, , 9) 1169 // ( , , ,10, ) 1170 // (11, , , ,12) 1171 1172 PointStorage<int> subStorage; 1173 subStorage = storage.subStorage(Region(QRect(1, 1, 5, 5))); // all 1174 // ( 1, 2, , , 3) 1175 // ( 4, 5, 6, , ) 1176 // ( , 7, 8, , 9) 1177 // ( , , ,10, ) 1178 // (11, , , ,12) 1179 1180 QVector<int> data = QVector<int>() << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; 1181 QVector<int> rows = QVector<int>() << 0 << 3 << 6 << 9 << 10; 1182 QVector<int> cols = QVector<int>() << 1 << 2 << 5 << 1 << 2 << 3 << 2 << 3 << 5 << 4 << 1 << 5; 1183 QCOMPARE(subStorage.m_data, data); 1184 QCOMPARE(subStorage.m_rows, rows); 1185 QCOMPARE(subStorage.m_cols, cols); 1186 1187 subStorage = storage.subStorage(Region(QRect(1, 1, 3, 3))); // upper left 1188 // ( 1, 2, ) 1189 // ( 4, 5, 6) 1190 // ( , 7, 8) 1191 1192 data = QVector<int>() << 1 << 2 << 4 << 5 << 6 << 7 << 8; 1193 rows = QVector<int>() << 0 << 2 << 5; 1194 cols = QVector<int>() << 1 << 2 << 1 << 2 << 3 << 2 << 3; 1195 QCOMPARE(subStorage.m_data, data); 1196 QCOMPARE(subStorage.m_rows, rows); 1197 QCOMPARE(subStorage.m_cols, cols); 1198 1199 subStorage = storage.subStorage(Region(QRect(4, 4, 5, 5))); // lower right 1200 // ( , , , , ) 1201 // ( , , , , ) 1202 // ( , , , , ) 1203 // ( , , ,10, ) 1204 // ( , , , ,12) 1205 1206 data = QVector<int>() << 10 << 12; 1207 rows = QVector<int>() << 0 << 0 << 0 << 0 << 1; 1208 cols = QVector<int>() << 4 << 5; 1209 QCOMPARE(subStorage.m_data, data); 1210 QCOMPARE(subStorage.m_rows, rows); 1211 QCOMPARE(subStorage.m_cols, cols); 1212 // #endif 1213 } 1214 1215 QTEST_MAIN(PointStorageTest)