File indexing completed on 2024-09-08 06:35:22
0001 /* 0002 File : SpreadsheetGenerateDataTest.cpp 0003 Project : LabPlot 0004 Description : Tests for the generation of data in spreadsheet 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2023 Alexander Semke <alexander.semke@web.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "SpreadsheetGenerateDataTest.h" 0012 #include "backend/spreadsheet/Spreadsheet.h" 0013 #include "kdefrontend/spreadsheet/EquidistantValuesDialog.h" 0014 0015 void SpreadsheetGenerateDataTest::initTestCase() { 0016 qRegisterMetaType<const AbstractAspect*>("const AbstractAspect*"); 0017 qRegisterMetaType<const AbstractColumn*>("const AbstractColumn*"); 0018 QLocale::setDefault(QLocale(QLocale::C)); 0019 } 0020 0021 // ********************************************************** 0022 // **************** Equidistant values ********************** 0023 // ********************************************************** 0024 0025 // ********************************************************** 0026 // ********************* Fixed number *********************** 0027 // ********************************************************** 0028 0029 /*! 0030 * generate equidistant double values, total number of values is fixed. 0031 */ 0032 void SpreadsheetGenerateDataTest::testFixedNumberDouble() { 0033 Spreadsheet sheet(QStringLiteral("test"), false); 0034 sheet.setColumnCount(1); 0035 sheet.setRowCount(1); 0036 auto* column = sheet.column(0); 0037 column->setColumnMode(AbstractColumn::ColumnMode::Double); 0038 0039 EquidistantValuesDialog dlg(&sheet); 0040 dlg.setColumns(QVector<Column*>{column}); 0041 dlg.setType(EquidistantValuesDialog::Type::FixedNumber); 0042 dlg.setNumber(5); 0043 dlg.setFromValue(1); 0044 dlg.setToValue(5); 0045 dlg.generate(); 0046 0047 // checks 0048 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double); 0049 QCOMPARE(sheet.rowCount(), 5); 0050 QCOMPARE(column->rowCount(), 5); 0051 QCOMPARE(column->valueAt(0), 1.); 0052 QCOMPARE(column->valueAt(1), 2.); 0053 QCOMPARE(column->valueAt(2), 3.); 0054 QCOMPARE(column->valueAt(3), 4.); 0055 QCOMPARE(column->valueAt(4), 5.); 0056 } 0057 0058 /*! 0059 * generate equidistant integer values, total number of values is fixed. 0060 */ 0061 void SpreadsheetGenerateDataTest::testFixedNumberInt() { 0062 Spreadsheet sheet(QStringLiteral("test"), false); 0063 sheet.setColumnCount(1); 0064 sheet.setRowCount(1); 0065 auto* column = sheet.column(0); 0066 column->setColumnMode(AbstractColumn::ColumnMode::Integer); 0067 0068 EquidistantValuesDialog dlg(&sheet); 0069 dlg.setColumns(QVector<Column*>{column}); 0070 dlg.setType(EquidistantValuesDialog::Type::FixedNumber); 0071 dlg.setNumber(5); 0072 dlg.setFromValue(1); 0073 dlg.setToValue(5); 0074 dlg.generate(); 0075 0076 // checks 0077 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Integer); 0078 QCOMPARE(sheet.rowCount(), 5); 0079 QCOMPARE(column->rowCount(), 5); 0080 QCOMPARE(column->integerAt(0), 1); 0081 QCOMPARE(column->integerAt(1), 2); 0082 QCOMPARE(column->integerAt(2), 3); 0083 QCOMPARE(column->integerAt(3), 4); 0084 QCOMPARE(column->integerAt(4), 5); 0085 } 0086 0087 /*! 0088 * generate equidistant big int values, total number of values is fixed. 0089 */ 0090 void SpreadsheetGenerateDataTest::testFixedNumberBigInt() { 0091 Spreadsheet sheet(QStringLiteral("test"), false); 0092 sheet.setColumnCount(1); 0093 sheet.setRowCount(1); 0094 auto* column = sheet.column(0); 0095 column->setColumnMode(AbstractColumn::ColumnMode::BigInt); 0096 0097 EquidistantValuesDialog dlg(&sheet); 0098 dlg.setColumns(QVector<Column*>{column}); 0099 dlg.setType(EquidistantValuesDialog::Type::FixedNumber); 0100 dlg.setNumber(5); 0101 dlg.setFromValue(1); 0102 dlg.setToValue(5); 0103 dlg.generate(); 0104 0105 // checks 0106 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::BigInt); 0107 QCOMPARE(sheet.rowCount(), 5); 0108 QCOMPARE(column->rowCount(), 5); 0109 QCOMPARE(column->bigIntAt(0), 1); 0110 QCOMPARE(column->bigIntAt(1), 2); 0111 QCOMPARE(column->bigIntAt(2), 3); 0112 QCOMPARE(column->bigIntAt(3), 4); 0113 QCOMPARE(column->bigIntAt(4), 5); 0114 } 0115 0116 /*! 0117 * generate equidistant DateTime values, total number of values is fixed. 0118 */ 0119 void SpreadsheetGenerateDataTest::testFixedNumberDateTime() { 0120 Spreadsheet sheet(QStringLiteral("test"), false); 0121 sheet.setColumnCount(1); 0122 sheet.setRowCount(1); 0123 auto* column = sheet.column(0); 0124 column->setColumnMode(AbstractColumn::ColumnMode::DateTime); 0125 0126 EquidistantValuesDialog dlg(&sheet); 0127 dlg.setColumns(QVector<Column*>{column}); 0128 dlg.setType(EquidistantValuesDialog::Type::FixedNumber); 0129 dlg.setNumber(5); 0130 0131 auto dateTime = QDateTime::fromString(QStringLiteral("2023-05-01T00:00:00Z"), Qt::ISODate); 0132 dlg.setFromDateTime(dateTime.toMSecsSinceEpoch()); 0133 dlg.setToDateTime(dateTime.addSecs(4).toMSecsSinceEpoch()); 0134 dlg.generate(); 0135 0136 // checks 0137 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::DateTime); 0138 QCOMPARE(sheet.rowCount(), 5); 0139 QCOMPARE(column->rowCount(), 5); 0140 QCOMPARE(column->dateTimeAt(0), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:00Z"), Qt::ISODate)); 0141 QCOMPARE(column->dateTimeAt(1), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:01Z"), Qt::ISODate)); 0142 QCOMPARE(column->dateTimeAt(2), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:02Z"), Qt::ISODate)); 0143 QCOMPARE(column->dateTimeAt(3), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:03Z"), Qt::ISODate)); 0144 QCOMPARE(column->dateTimeAt(4), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:04Z"), Qt::ISODate)); 0145 } 0146 0147 /*! 0148 * two columns (double and datetime) provided, generate equidistant values for both, total number of values is fixed. 0149 */ 0150 void SpreadsheetGenerateDataTest::testFixedNumberDoubleDateTime() { 0151 Spreadsheet sheet(QStringLiteral("test"), false); 0152 sheet.setColumnCount(2); 0153 sheet.setRowCount(1); 0154 auto* column1 = sheet.column(0); 0155 column1->setColumnMode(AbstractColumn::ColumnMode::Double); 0156 auto* column2 = sheet.column(1); 0157 column2->setColumnMode(AbstractColumn::ColumnMode::DateTime); 0158 0159 EquidistantValuesDialog dlg(&sheet); 0160 dlg.setColumns(QVector<Column*>{column1, column2}); 0161 dlg.setType(EquidistantValuesDialog::Type::FixedNumber); 0162 dlg.setNumber(5); 0163 dlg.setFromValue(1); 0164 dlg.setToValue(5); 0165 auto dateTime = QDateTime::fromString(QStringLiteral("2023-05-01T00:00:00Z"), Qt::ISODate); 0166 dlg.setFromDateTime(dateTime.toMSecsSinceEpoch()); 0167 dlg.setToDateTime(dateTime.addSecs(4).toMSecsSinceEpoch()); 0168 dlg.generate(); 0169 0170 // checks for the numeric column 0171 QCOMPARE(column1->columnMode(), AbstractColumn::ColumnMode::Double); 0172 QCOMPARE(sheet.rowCount(), 5); 0173 QCOMPARE(column1->rowCount(), 5); 0174 QCOMPARE(column1->valueAt(0), 1.); 0175 QCOMPARE(column1->valueAt(1), 2.); 0176 QCOMPARE(column1->valueAt(2), 3.); 0177 QCOMPARE(column1->valueAt(3), 4.); 0178 QCOMPARE(column1->valueAt(4), 5.); 0179 0180 // checks for the DateTime column 0181 QCOMPARE(column2->columnMode(), AbstractColumn::ColumnMode::DateTime); 0182 QCOMPARE(column2->rowCount(), 5); 0183 QCOMPARE(column2->dateTimeAt(0), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:00Z"), Qt::ISODate)); 0184 QCOMPARE(column2->dateTimeAt(1), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:01Z"), Qt::ISODate)); 0185 QCOMPARE(column2->dateTimeAt(2), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:02Z"), Qt::ISODate)); 0186 QCOMPARE(column2->dateTimeAt(3), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:03Z"), Qt::ISODate)); 0187 QCOMPARE(column2->dateTimeAt(4), QDateTime::fromString(QStringLiteral("2023-05-01T00:00:04Z"), Qt::ISODate)); 0188 } 0189 0190 // ********************************************************** 0191 // ******************** Fixed increment ********************* 0192 // ********************************************************** 0193 0194 /*! 0195 * generate equidistant double values, the increment is fixed. 0196 */ 0197 void SpreadsheetGenerateDataTest::testFixedIncrementDouble() { 0198 Spreadsheet sheet(QStringLiteral("test"), false); 0199 sheet.setColumnCount(1); 0200 sheet.setRowCount(1); 0201 auto* column = sheet.column(0); 0202 column->setColumnMode(AbstractColumn::ColumnMode::Double); 0203 0204 EquidistantValuesDialog dlg(&sheet); 0205 dlg.setColumns(QVector<Column*>{column}); 0206 dlg.setType(EquidistantValuesDialog::Type::FixedIncrement); 0207 dlg.setIncrement(0.2); 0208 dlg.setFromValue(1); 0209 dlg.setToValue(1.8); 0210 dlg.generate(); 0211 0212 // checks 0213 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double); 0214 QCOMPARE(sheet.rowCount(), 5); 0215 QCOMPARE(column->rowCount(), 5); 0216 QCOMPARE(column->valueAt(0), 1.); 0217 QCOMPARE(column->valueAt(1), 1.2); 0218 QCOMPARE(column->valueAt(2), 1.4); 0219 QCOMPARE(column->valueAt(3), 1.6); 0220 QCOMPARE(column->valueAt(4), 1.8); 0221 } 0222 0223 /*! 0224 * generate equidistant integer values, the increment is fixed. 0225 */ 0226 void SpreadsheetGenerateDataTest::testFixedIncrementInt() { 0227 Spreadsheet sheet(QStringLiteral("test"), false); 0228 sheet.setColumnCount(1); 0229 sheet.setRowCount(1); 0230 auto* column = sheet.column(0); 0231 column->setColumnMode(AbstractColumn::ColumnMode::Integer); 0232 0233 EquidistantValuesDialog dlg(&sheet); 0234 dlg.setColumns(QVector<Column*>{column}); 0235 dlg.setType(EquidistantValuesDialog::Type::FixedIncrement); 0236 dlg.setIncrement(1); 0237 dlg.setFromValue(1); 0238 dlg.setToValue(5); 0239 dlg.generate(); 0240 0241 // checks 0242 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Integer); 0243 QCOMPARE(sheet.rowCount(), 5); 0244 QCOMPARE(column->rowCount(), 5); 0245 QCOMPARE(column->integerAt(0), 1); 0246 QCOMPARE(column->integerAt(1), 2); 0247 QCOMPARE(column->integerAt(2), 3); 0248 QCOMPARE(column->integerAt(3), 4); 0249 QCOMPARE(column->integerAt(4), 5); 0250 } 0251 0252 /*! 0253 * generate equidistant big int values, the increment is fixed. 0254 */ 0255 void SpreadsheetGenerateDataTest::testFixedIncrementBigInt() { 0256 Spreadsheet sheet(QStringLiteral("test"), false); 0257 sheet.setColumnCount(1); 0258 sheet.setRowCount(1); 0259 auto* column = sheet.column(0); 0260 column->setColumnMode(AbstractColumn::ColumnMode::BigInt); 0261 0262 EquidistantValuesDialog dlg(&sheet); 0263 dlg.setColumns(QVector<Column*>{column}); 0264 dlg.setType(EquidistantValuesDialog::Type::FixedIncrement); 0265 dlg.setIncrement(1); 0266 dlg.setFromValue(1); 0267 dlg.setToValue(5); 0268 dlg.generate(); 0269 0270 // checks 0271 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::BigInt); 0272 QCOMPARE(sheet.rowCount(), 5); 0273 QCOMPARE(column->rowCount(), 5); 0274 QCOMPARE(column->bigIntAt(0), 1); 0275 QCOMPARE(column->bigIntAt(1), 2); 0276 QCOMPARE(column->bigIntAt(2), 3); 0277 QCOMPARE(column->bigIntAt(3), 4); 0278 QCOMPARE(column->bigIntAt(4), 5); 0279 } 0280 0281 /*! 0282 * generate equidistant DateTime values, the increment is fixed. 0283 */ 0284 void SpreadsheetGenerateDataTest::testFixedIncrementDateTime() { 0285 Spreadsheet sheet(QStringLiteral("test"), false); 0286 sheet.setColumnCount(1); 0287 sheet.setRowCount(1); 0288 auto* column = sheet.column(0); 0289 column->setColumnMode(AbstractColumn::ColumnMode::DateTime); 0290 0291 EquidistantValuesDialog dlg(&sheet); 0292 dlg.setColumns(QVector<Column*>{column}); 0293 dlg.setType(EquidistantValuesDialog::Type::FixedIncrement); 0294 dlg.setIncrementDateTimeUnit(EquidistantValuesDialog::DateTimeUnit::Year); 0295 auto dateTime = QDateTime::fromString(QStringLiteral("2023-05-01T00:00:00Z"), Qt::ISODate); 0296 dlg.setFromDateTime(dateTime.toMSecsSinceEpoch()); 0297 dlg.setToDateTime(dateTime.addYears(4).toMSecsSinceEpoch()); 0298 dlg.generate(); 0299 0300 // checks 0301 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::DateTime); 0302 QCOMPARE(sheet.rowCount(), 5); 0303 QCOMPARE(column->rowCount(), 5); 0304 QCOMPARE(column->dateTimeAt(0).date().year(), 2023); 0305 QCOMPARE(column->dateTimeAt(1).date().year(), 2024); 0306 QCOMPARE(column->dateTimeAt(2).date().year(), 2025); 0307 QCOMPARE(column->dateTimeAt(3).date().year(), 2026); 0308 QCOMPARE(column->dateTimeAt(4).date().year(), 2027); 0309 } 0310 0311 // ********************************************************** 0312 // **************** Fixed number and increment ************** 0313 // ********************************************************** 0314 0315 /*! 0316 * generate equidistant double values, total number of values and the increment are fixed. 0317 */ 0318 void SpreadsheetGenerateDataTest::testFixedNumberIncrementDouble() { 0319 Spreadsheet sheet(QStringLiteral("test"), false); 0320 sheet.setColumnCount(1); 0321 sheet.setRowCount(1); 0322 auto* column = sheet.column(0); 0323 column->setColumnMode(AbstractColumn::ColumnMode::Double); 0324 0325 EquidistantValuesDialog dlg(&sheet); 0326 dlg.setColumns(QVector<Column*>{column}); 0327 dlg.setType(EquidistantValuesDialog::Type::FixedNumberIncrement); 0328 dlg.setNumber(5); 0329 dlg.setIncrement(10); 0330 dlg.setFromValue(0.); 0331 // dlg.setToValue(5); 0332 dlg.generate(); 0333 0334 // checks 0335 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double); 0336 QCOMPARE(sheet.rowCount(), 5); 0337 QCOMPARE(column->rowCount(), 5); 0338 QCOMPARE(column->valueAt(0), 0.); 0339 QCOMPARE(column->valueAt(1), 10.); 0340 QCOMPARE(column->valueAt(2), 20.); 0341 QCOMPARE(column->valueAt(3), 30.); 0342 QCOMPARE(column->valueAt(4), 40.); 0343 } 0344 0345 /*! 0346 * generate equidistant integer values, the increment is fixed. 0347 */ 0348 void SpreadsheetGenerateDataTest::testFixedNumberIncrementInt() { 0349 Spreadsheet sheet(QStringLiteral("test"), false); 0350 sheet.setColumnCount(1); 0351 sheet.setRowCount(1); 0352 auto* column = sheet.column(0); 0353 column->setColumnMode(AbstractColumn::ColumnMode::Integer); 0354 0355 EquidistantValuesDialog dlg(&sheet); 0356 dlg.setColumns(QVector<Column*>{column}); 0357 dlg.setType(EquidistantValuesDialog::Type::FixedNumberIncrement); 0358 dlg.setNumber(5); 0359 dlg.setIncrement(1); 0360 dlg.setFromValue(1); 0361 dlg.generate(); 0362 0363 // checks 0364 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Integer); 0365 QCOMPARE(sheet.rowCount(), 5); 0366 QCOMPARE(column->rowCount(), 5); 0367 QCOMPARE(column->integerAt(0), 1); 0368 QCOMPARE(column->integerAt(1), 2); 0369 QCOMPARE(column->integerAt(2), 3); 0370 QCOMPARE(column->integerAt(3), 4); 0371 QCOMPARE(column->integerAt(4), 5); 0372 } 0373 0374 /*! 0375 * generate equidistant big int values, the increment is fixed. 0376 */ 0377 void SpreadsheetGenerateDataTest::testFixedNumberIncrementBigInt() { 0378 Spreadsheet sheet(QStringLiteral("test"), false); 0379 sheet.setColumnCount(1); 0380 sheet.setRowCount(1); 0381 auto* column = sheet.column(0); 0382 column->setColumnMode(AbstractColumn::ColumnMode::BigInt); 0383 0384 EquidistantValuesDialog dlg(&sheet); 0385 dlg.setColumns(QVector<Column*>{column}); 0386 dlg.setType(EquidistantValuesDialog::Type::FixedNumberIncrement); 0387 dlg.setNumber(5); 0388 dlg.setIncrement(1); 0389 dlg.setFromValue(1); 0390 dlg.generate(); 0391 0392 // checks 0393 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::BigInt); 0394 QCOMPARE(sheet.rowCount(), 5); 0395 QCOMPARE(column->rowCount(), 5); 0396 QCOMPARE(column->bigIntAt(0), 1); 0397 QCOMPARE(column->bigIntAt(1), 2); 0398 QCOMPARE(column->bigIntAt(2), 3); 0399 QCOMPARE(column->bigIntAt(3), 4); 0400 QCOMPARE(column->bigIntAt(4), 5); 0401 } 0402 0403 /*! 0404 * generate equidistant DateTime values, the increment is fixed. 0405 */ 0406 void SpreadsheetGenerateDataTest::testFixedNumberIncrementDateTime() { 0407 Spreadsheet sheet(QStringLiteral("test"), false); 0408 sheet.setColumnCount(1); 0409 sheet.setRowCount(1); 0410 auto* column = sheet.column(0); 0411 column->setColumnMode(AbstractColumn::ColumnMode::DateTime); 0412 0413 EquidistantValuesDialog dlg(&sheet); 0414 dlg.setColumns(QVector<Column*>{column}); 0415 dlg.setType(EquidistantValuesDialog::Type::FixedNumberIncrement); 0416 dlg.setNumber(5); 0417 dlg.setIncrementDateTimeUnit(EquidistantValuesDialog::DateTimeUnit::Year); 0418 auto dateTime = QDateTime::fromString(QStringLiteral("2023-05-01T00:00:00Z"), Qt::ISODate); 0419 dlg.setFromDateTime(dateTime.toMSecsSinceEpoch()); 0420 dlg.generate(); 0421 0422 // checks 0423 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::DateTime); 0424 QCOMPARE(sheet.rowCount(), 5); 0425 QCOMPARE(column->rowCount(), 5); 0426 QCOMPARE(column->dateTimeAt(0).date().year(), 2023); 0427 QCOMPARE(column->dateTimeAt(1).date().year(), 2024); 0428 QCOMPARE(column->dateTimeAt(2).date().year(), 2025); 0429 QCOMPARE(column->dateTimeAt(3).date().year(), 2026); 0430 QCOMPARE(column->dateTimeAt(4).date().year(), 2027); 0431 } 0432 0433 // ********************************************************** 0434 // ***************** Column mode conversion ***************** 0435 // ********************************************************** 0436 0437 /*! 0438 * generate equidistant big int values, total number of values is fixed, the initial int column mode needs to be adjusted. 0439 */ 0440 void SpreadsheetGenerateDataTest::testFixedNumberIntToBigInt() { 0441 Spreadsheet sheet(QStringLiteral("test"), false); 0442 sheet.setColumnCount(1); 0443 sheet.setRowCount(1); 0444 auto* column = sheet.column(0); 0445 column->setColumnMode(AbstractColumn::ColumnMode::Integer); 0446 0447 EquidistantValuesDialog dlg(&sheet); 0448 dlg.setColumns(QVector<Column*>{column}); 0449 dlg.setType(EquidistantValuesDialog::Type::FixedNumber); 0450 dlg.setNumber(5); 0451 dlg.setFromValue(2147483647.); 0452 dlg.setToValue(2147483651.); 0453 dlg.generate(); 0454 0455 // checks 0456 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::BigInt); 0457 QCOMPARE(sheet.rowCount(), 5); 0458 QCOMPARE(column->rowCount(), 5); 0459 QCOMPARE(column->bigIntAt(0), 2147483647); 0460 QCOMPARE(column->bigIntAt(1), 2147483648); 0461 QCOMPARE(column->bigIntAt(2), 2147483649); 0462 QCOMPARE(column->bigIntAt(3), 2147483650); 0463 QCOMPARE(column->bigIntAt(4), 2147483651); 0464 } 0465 0466 /*! 0467 * generate equidistant double values, total number of values is fixed, the initial int column mode needs to be adjusted. 0468 */ 0469 void SpreadsheetGenerateDataTest::testFixedNumberIntToDouble() { 0470 Spreadsheet sheet(QStringLiteral("test"), false); 0471 sheet.setColumnCount(1); 0472 sheet.setRowCount(1); 0473 auto* column = sheet.column(0); 0474 column->setColumnMode(AbstractColumn::ColumnMode::Integer); 0475 0476 EquidistantValuesDialog dlg(&sheet); 0477 dlg.setColumns(QVector<Column*>{column}); 0478 dlg.setType(EquidistantValuesDialog::Type::FixedNumber); 0479 dlg.setNumber(5); 0480 dlg.setFromValue(1); 0481 dlg.setToValue(1.8); 0482 dlg.generate(); 0483 0484 // checks 0485 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double); 0486 QCOMPARE(sheet.rowCount(), 5); 0487 QCOMPARE(column->rowCount(), 5); 0488 QCOMPARE(column->valueAt(0), 1.); 0489 QCOMPARE(column->valueAt(1), 1.2); 0490 QCOMPARE(column->valueAt(2), 1.4); 0491 QCOMPARE(column->valueAt(3), 1.6); 0492 QCOMPARE(column->valueAt(4), 1.8); 0493 } 0494 0495 /*! 0496 * generate equidistant double values, total number of values is fixed, the initial big int column mode needs to be adjusted. 0497 */ 0498 void SpreadsheetGenerateDataTest::testFixedNumberBigIntToDouble() { 0499 Spreadsheet sheet(QStringLiteral("test"), false); 0500 sheet.setColumnCount(1); 0501 sheet.setRowCount(1); 0502 auto* column = sheet.column(0); 0503 column->setColumnMode(AbstractColumn::ColumnMode::BigInt); 0504 0505 EquidistantValuesDialog dlg(&sheet); 0506 dlg.setColumns(QVector<Column*>{column}); 0507 dlg.setType(EquidistantValuesDialog::Type::FixedNumber); 0508 dlg.setNumber(5); 0509 dlg.setFromValue(1); 0510 dlg.setToValue(1.8); 0511 dlg.generate(); 0512 0513 // checks 0514 QCOMPARE(column->columnMode(), AbstractColumn::ColumnMode::Double); 0515 QCOMPARE(sheet.rowCount(), 5); 0516 QCOMPARE(column->rowCount(), 5); 0517 QCOMPARE(column->valueAt(0), 1.); 0518 QCOMPARE(column->valueAt(1), 1.2); 0519 QCOMPARE(column->valueAt(2), 1.4); 0520 QCOMPARE(column->valueAt(3), 1.6); 0521 QCOMPARE(column->valueAt(4), 1.8); 0522 } 0523 0524 QTEST_MAIN(SpreadsheetGenerateDataTest)