File indexing completed on 2024-04-28 15:14:07
0001 /*************************************************************************** 0002 File : IntegrationTest.cpp 0003 Project : LabPlot 0004 Description : Tests for numerical integration 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2018 Stefan Gerlach (stefan.gerlach@uni.kn) 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 * This program is distributed in the hope that it will be useful, * 0017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0019 * GNU General Public License for more details. * 0020 * * 0021 * You should have received a copy of the GNU General Public License * 0022 * along with this program; if not, write to the Free Software * 0023 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0024 * Boston, MA 02110-1301 USA * 0025 * * 0026 ***************************************************************************/ 0027 0028 #include "IntegrationTest.h" 0029 #include "backend/core/column/Column.h" 0030 #include "backend/worksheet/plots/cartesian/XYIntegrationCurve.h" 0031 0032 //############################################################################## 0033 0034 void IntegrationTest::testLinear() { 0035 // data 0036 QVector<int> xData = {1,2,3,4}; 0037 QVector<double> yData = {1.,2.,3.,4.}; 0038 0039 //data source columns 0040 Column xDataColumn("x", AbstractColumn::ColumnMode::Integer); 0041 xDataColumn.replaceInteger(0, xData); 0042 0043 Column yDataColumn("y", AbstractColumn::ColumnMode::Numeric); 0044 yDataColumn.replaceValues(0, yData); 0045 0046 XYIntegrationCurve integrationCurve("integration"); 0047 integrationCurve.setXDataColumn(&xDataColumn); 0048 integrationCurve.setYDataColumn(&yDataColumn); 0049 0050 //prepare the integration 0051 XYIntegrationCurve::IntegrationData integrationData = integrationCurve.integrationData(); 0052 integrationCurve.setIntegrationData(integrationData); 0053 0054 //perform the integration 0055 integrationCurve.recalculate(); 0056 const XYIntegrationCurve::IntegrationResult& integrationResult = integrationCurve.integrationResult(); 0057 0058 //check the results 0059 QCOMPARE(integrationResult.available, true); 0060 QCOMPARE(integrationResult.valid, true); 0061 0062 const AbstractColumn* resultXDataColumn = integrationCurve.xColumn(); 0063 const AbstractColumn* resultYDataColumn = integrationCurve.yColumn(); 0064 0065 const int np = resultXDataColumn->rowCount(); 0066 QCOMPARE(np, 4); 0067 0068 for (int i = 0; i < np; i++) 0069 QCOMPARE(resultXDataColumn->valueAt(i), (double)i + 1); 0070 0071 QCOMPARE(resultYDataColumn->valueAt(0), 0.); 0072 QCOMPARE(resultYDataColumn->valueAt(1), 1.5); 0073 QCOMPARE(resultYDataColumn->valueAt(2), 4.); 0074 QCOMPARE(resultYDataColumn->valueAt(3), 7.5); 0075 } 0076 0077 QTEST_MAIN(IntegrationTest)