| 3829 | } |
| 3830 | |
| 3831 | void FitTest::testHistogramGaussianML() { |
| 3832 | Spreadsheet spreadsheet(QStringLiteral("test"), false); |
| 3833 | AsciiFilter filter; |
| 3834 | |
| 3835 | const QString& fileName = QFINDTESTDATA(QLatin1String("data/Gaussian.dat")); |
| 3836 | |
| 3837 | auto properties = filter.properties(); |
| 3838 | properties.headerEnabled = false; |
| 3839 | filter.setProperties(properties); |
| 3840 | filter.readDataFromFile(fileName, &spreadsheet, AbstractFileFilter::ImportMode::Replace); |
| 3841 | |
| 3842 | QCOMPARE(spreadsheet.rowCount(), 1000); |
| 3843 | QCOMPARE(spreadsheet.columnCount(), 1); |
| 3844 | |
| 3845 | Worksheet worksheet(QStringLiteral("test"), false); |
| 3846 | auto* plot = new CartesianPlot(QStringLiteral("plot")); |
| 3847 | worksheet.addChild(plot); |
| 3848 | |
| 3849 | auto* hist = new Histogram(QStringLiteral("Histogram")); |
| 3850 | plot->addChild(hist); |
| 3851 | hist->setDataColumn(spreadsheet.column(0)); |
| 3852 | |
| 3853 | // Do the fit |
| 3854 | plot->addHistogramFit(hist, nsl_sf_stats_gaussian); |
| 3855 | |
| 3856 | auto fit = dynamic_cast<XYFitCurve*>(plot->child<XYFitCurve>(0)); |
| 3857 | QVERIFY(fit != nullptr); |
| 3858 | |
| 3859 | QCOMPARE(fit->name(), i18n("Distribution Fit to '%1'", hist->name())); |
| 3860 | // get results |
| 3861 | const XYFitCurve::FitResult& fitResult = fit->fitResult(); |
| 3862 | |
| 3863 | QCOMPARE(fitResult.available, true); |
| 3864 | QCOMPARE(fitResult.valid, true); |
| 3865 | |
| 3866 | WARN(std::setprecision(15) << fitResult.paramValues.at(0)); |
| 3867 | QCOMPARE(fitResult.paramValues.at(0), 210.380459328); |
| 3868 | WARN(std::setprecision(15) << fitResult.paramValues.at(1)); |
| 3869 | QCOMPARE(fitResult.paramValues.at(1), 0.999776858937); |
| 3870 | WARN(std::setprecision(15) << fitResult.errorValues.at(1)); |
| 3871 | QCOMPARE(fitResult.errorValues.at(1), 0.0223507017166885); |
| 3872 | WARN(std::setprecision(15) << fitResult.paramValues.at(1) - fitResult.marginValues.at(1)); |
| 3873 | QCOMPARE(fitResult.paramValues.at(1) - fitResult.marginValues.at(1), 0.955917043549699); |
| 3874 | WARN(std::setprecision(15) << fitResult.paramValues.at(1) + fitResult.marginValues.at(1)); |
| 3875 | QCOMPARE(fitResult.paramValues.at(1) + fitResult.marginValues.at(1), 1.0436366743251); |
| 3876 | |
| 3877 | WARN(std::setprecision(15) << fitResult.paramValues.at(2)); |
| 3878 | QCOMPARE(fitResult.paramValues.at(2), -0.0294045302042); |
| 3879 | WARN(std::setprecision(15) << fitResult.errorValues.at(2)); |
| 3880 | QCOMPARE(fitResult.errorValues.at(2), 0.0316157202617); |
| 3881 | WARN(std::setprecision(15) << fitResult.paramValues.at(2) - fitResult.marginValues.at(2)); |
| 3882 | QCOMPARE(fitResult.paramValues.at(2) - fitResult.marginValues.at(2), -0.0914455198610062); |
| 3883 | WARN(std::setprecision(15) << fitResult.paramValues.at(2) + fitResult.marginValues.at(2)); |
| 3884 | QCOMPARE(fitResult.paramValues.at(2) + fitResult.marginValues.at(2), 0.0326364594526431); |
| 3885 | } |
| 3886 | |
| 3887 | void FitTest::testHistogramExponentialML() { |
| 3888 | Spreadsheet spreadsheet(QStringLiteral("test"), false); |
nothing calls this directly
no test coverage detected