| 3885 | } |
| 3886 | |
| 3887 | void FitTest::testHistogramExponentialML() { |
| 3888 | Spreadsheet spreadsheet(QStringLiteral("test"), false); |
| 3889 | AsciiFilter filter; |
| 3890 | |
| 3891 | const QString& fileName = QFINDTESTDATA(QLatin1String("data/Exponential.dat")); |
| 3892 | |
| 3893 | auto properties = filter.properties(); |
| 3894 | properties.headerEnabled = false; |
| 3895 | filter.setProperties(properties); |
| 3896 | filter.readDataFromFile(fileName, &spreadsheet, AbstractFileFilter::ImportMode::Replace); |
| 3897 | |
| 3898 | QCOMPARE(spreadsheet.rowCount(), 100); |
| 3899 | QCOMPARE(spreadsheet.columnCount(), 1); |
| 3900 | |
| 3901 | Worksheet worksheet(QStringLiteral("test"), false); |
| 3902 | auto* plot = new CartesianPlot(QStringLiteral("plot")); |
| 3903 | worksheet.addChild(plot); |
| 3904 | |
| 3905 | auto* hist = new Histogram(QStringLiteral("Histogram")); |
| 3906 | plot->addChild(hist); |
| 3907 | hist->setDataColumn(spreadsheet.column(0)); |
| 3908 | |
| 3909 | // Do the fit |
| 3910 | plot->addHistogramFit(hist, nsl_sf_stats_exponential); |
| 3911 | |
| 3912 | auto fit = dynamic_cast<XYFitCurve*>(plot->child<XYFitCurve>(0)); |
| 3913 | QVERIFY(fit != nullptr); |
| 3914 | |
| 3915 | QCOMPARE(fit->name(), i18n("Distribution Fit to '%1'", hist->name())); |
| 3916 | // get results |
| 3917 | const XYFitCurve::FitResult& fitResult = fit->fitResult(); |
| 3918 | |
| 3919 | QCOMPARE(fitResult.available, true); |
| 3920 | QCOMPARE(fitResult.valid, true); |
| 3921 | |
| 3922 | WARN(std::setprecision(15) << fitResult.paramValues.at(0)); |
| 3923 | QCOMPARE(fitResult.paramValues.at(0), 41.6543778722); |
| 3924 | WARN(std::setprecision(15) << fitResult.paramValues.at(1)); |
| 3925 | QCOMPARE(fitResult.paramValues.at(1), 1.93906050400681); |
| 3926 | WARN(std::setprecision(15) << fitResult.errorValues.at(1)); |
| 3927 | QCOMPARE(fitResult.errorValues.at(1), 0.195884683568035); |
| 3928 | WARN(std::setprecision(15) << fitResult.paramValues.at(1) - fitResult.marginValues.at(1)); |
| 3929 | QCOMPARE(fitResult.paramValues.at(1) - fitResult.marginValues.at(1), 1.5740096363284); |
| 3930 | WARN(std::setprecision(15) << fitResult.paramValues.at(1) + fitResult.margin2Values.at(1)); |
| 3931 | QCOMPARE(fitResult.paramValues.at(1) + fitResult.margin2Values.at(1), 2.34119114746796); |
| 3932 | WARN(std::setprecision(15) << fitResult.paramValues.at(2)); |
| 3933 | QCOMPARE(fitResult.paramValues.at(2), 5.01032231564491); |
| 3934 | } |
| 3935 | |
| 3936 | void FitTest::testHistogramLaplaceML() { |
| 3937 | Spreadsheet spreadsheet(QStringLiteral("test"), false); |
nothing calls this directly
no test coverage detected