| 19 | // ############################################################################## |
| 20 | |
| 21 | void SmoothTest::testPercentile() { |
| 22 | // data |
| 23 | QVector<int> xData{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; |
| 24 | QVector<double> yData{47.7, 44., 43., 44.96, 45., 43.73, 38., 47.1, 44., 38.3}; |
| 25 | // p=0.5, d=5 (check with LibreOffice and Origin 2020a) |
| 26 | QVector<double> result50_5{47.7, 44, 44.96, 44, 43.73, 44.96, 44, 43.73, 44, 38.3}; |
| 27 | |
| 28 | // data source columns |
| 29 | Column xDataColumn(QStringLiteral("x"), AbstractColumn::ColumnMode::Integer); |
| 30 | xDataColumn.replaceInteger(0, xData); |
| 31 | |
| 32 | Column yDataColumn(QStringLiteral("y"), AbstractColumn::ColumnMode::Double); |
| 33 | yDataColumn.replaceValues(0, yData); |
| 34 | |
| 35 | XYSmoothCurve smoothCurve(QStringLiteral("smooth")); |
| 36 | smoothCurve.setXDataColumn(&xDataColumn); |
| 37 | smoothCurve.setYDataColumn(&yDataColumn); |
| 38 | |
| 39 | // prepare the smooth |
| 40 | XYSmoothCurve::SmoothData smoothData = smoothCurve.smoothData(); |
| 41 | smoothData.type = nsl_smooth_type_percentile; |
| 42 | // default |
| 43 | // smoothData.points = 5; |
| 44 | // smoothData.percentile = 0.5; |
| 45 | smoothCurve.setSmoothData(smoothData); |
| 46 | |
| 47 | // perform the smooth |
| 48 | smoothCurve.recalculate(); |
| 49 | const auto& smoothResult = smoothCurve.result(); |
| 50 | |
| 51 | // check the results |
| 52 | QCOMPARE(smoothResult.available, true); |
| 53 | QCOMPARE(smoothResult.valid, true); |
| 54 | |
| 55 | const auto* resultXDataColumn{smoothCurve.xColumn()}; |
| 56 | const auto* resultYDataColumn{smoothCurve.yColumn()}; |
| 57 | |
| 58 | const int np{resultXDataColumn->rowCount()}; |
| 59 | QCOMPARE(np, 10); |
| 60 | |
| 61 | for (int i = 0; i < np; i++) { |
| 62 | QCOMPARE(resultXDataColumn->valueAt(i), (double)i + 1); |
| 63 | QCOMPARE(resultYDataColumn->valueAt(i), result50_5.at(i)); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | QTEST_MAIN(SmoothTest) |
nothing calls this directly
no test coverage detected