File indexing completed on 2024-05-05 03:48:27
0001 /* 0002 File : InterpolationTest.cpp 0003 Project : LabPlot 0004 Description : Tests for numerical interpolation 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2016-2023 Alexander Semke <alexander.semke@web.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "InterpolationTest.h" 0012 #include "backend/core/column/Column.h" 0013 #include "backend/worksheet/plots/cartesian/XYInterpolationCurve.h" 0014 0015 // ############################################################################## 0016 0017 /*! 0018 * use a dataset and the 1d interpolationg grid for x that leads to the value of x that is bigger 0019 * than the maximal value in the data. make sure this case is handled correctly and we get a valid result. 0020 * s.a. https://invent.kde.org/education/labplot/-/issues/841 0021 */ 0022 void InterpolationTest::testRanges() { 0023 // data 0024 QVector<double> xData = {0.0001017011754038652, 0025 0.0004975011506471159, 0026 0.00102695699595614, 0027 0.001966348318553697, 0028 0.2242262396919622, 0029 0.3605485906366224, 0030 0.617114010419536, 0031 1.017363907550924, 0032 10.14814650334548}; 0033 QVector<double> yData = {21.65343311865348, 0034 21.59965712171775, 0035 10.05153706441572, 0036 2.836184922640735, 0037 0.09417257716127328, 0038 0.08249127667969287, 0039 0.06333674921226348, 0040 0.04736857950015065, 0041 0.04597133454545185}; 0042 0043 // data source columns 0044 Column xDataColumn(QStringLiteral("x"), AbstractColumn::ColumnMode::Double); 0045 xDataColumn.replaceValues(0, xData); 0046 0047 Column yDataColumn(QStringLiteral("y"), AbstractColumn::ColumnMode::Double); 0048 yDataColumn.replaceValues(0, yData); 0049 0050 // interpolation curve 0051 XYInterpolationCurve curve(QStringLiteral("interpolation")); 0052 curve.setXDataColumn(&xDataColumn); 0053 curve.setYDataColumn(&yDataColumn); 0054 0055 // prepare the interpolation 0056 // set the number of points to 27 which is leading for the original data to and for the grid points 0057 // defined via x_i = xmin + i * (xmax - xmin) / (npoints - 1) to a values that is bigger than xmax 0058 // because of issues with the representation of float numbers. 0059 auto data = curve.interpolationData(); 0060 data.npoints = 27; 0061 curve.setInterpolationData(data); 0062 0063 // perform the interpolation 0064 curve.recalculate(); 0065 0066 // check the results 0067 const auto& result = curve.result(); 0068 QCOMPARE(result.available, true); 0069 QCOMPARE(result.valid, true); 0070 } 0071 0072 QTEST_MAIN(InterpolationTest)