| 3756 | } |
| 3757 | |
| 3758 | void FitTest::testHistogramFit() { |
| 3759 | Project project; |
| 3760 | project.load(QFINDTESTDATA(QLatin1String("data/TestHistogramFit.lml"))); |
| 3761 | |
| 3762 | auto* aspect = project.child<AbstractAspect>(0); |
| 3763 | QVERIFY(aspect != nullptr); |
| 3764 | QCOMPARE(aspect->name(), QLatin1String("Spreadsheet")); |
| 3765 | QVERIFY(aspect->type() == AspectType::Spreadsheet); |
| 3766 | aspect = project.child<AbstractAspect>(1); |
| 3767 | QVERIFY(aspect != nullptr); |
| 3768 | |
| 3769 | QCOMPARE(aspect->name(), QLatin1String("Worksheet - Spreadsheet")); |
| 3770 | QVERIFY(aspect->type() == AspectType::Worksheet); |
| 3771 | auto w = dynamic_cast<Worksheet*>(aspect); |
| 3772 | if (!w) |
| 3773 | return; |
| 3774 | |
| 3775 | auto plot = dynamic_cast<CartesianPlot*>(aspect->child<CartesianPlot>(0)); |
| 3776 | QVERIFY(plot != nullptr); |
| 3777 | |
| 3778 | QCOMPARE(plot->name(), QLatin1String("Plot - Spreadsheet")); |
| 3779 | auto hist = dynamic_cast<Histogram*>(plot->child<Histogram>(0)); |
| 3780 | QVERIFY(hist != nullptr); |
| 3781 | |
| 3782 | QCOMPARE(hist->name(), QLatin1String("2")); |
| 3783 | // Do the fit |
| 3784 | plot->addHistogramFit(hist, nsl_sf_stats_gaussian); |
| 3785 | |
| 3786 | auto fit = dynamic_cast<XYFitCurve*>(plot->child<XYFitCurve>(0)); |
| 3787 | QVERIFY(fit != nullptr); |
| 3788 | |
| 3789 | QCOMPARE(fit->name(), i18n("Distribution Fit to '%1'", hist->name())); |
| 3790 | // get results |
| 3791 | const XYFitCurve::FitResult& fitResult = fit->fitResult(); |
| 3792 | |
| 3793 | QCOMPARE(fitResult.available, true); |
| 3794 | QCOMPARE(fitResult.valid, true); |
| 3795 | |
| 3796 | // ML results |
| 3797 | DEBUG(std::setprecision(15) << fitResult.paramValues.at(0)); |
| 3798 | QCOMPARE(fitResult.paramValues.at(0), 1.); |
| 3799 | DEBUG(std::setprecision(15) << fitResult.paramValues.at(1)); |
| 3800 | QCOMPARE(fitResult.paramValues.at(1), 0.999776858937); |
| 3801 | DEBUG(std::setprecision(15) << fitResult.paramValues.at(2)); |
| 3802 | QCOMPARE(fitResult.paramValues.at(2), -0.0294045302042); |
| 3803 | |
| 3804 | /* LM results |
| 3805 | DEBUG(std::setprecision(15) << fitResult.paramValues.at(0)); |
| 3806 | QCOMPARE(fitResult.paramValues.at(0), 0.999829585605626); |
| 3807 | DEBUG(std::setprecision(15) << fitResult.errorValues.at(0)); |
| 3808 | QCOMPARE(fitResult.errorValues.at(0), 0.0313884775124071); |
| 3809 | DEBUG(std::setprecision(15) << fitResult.paramValues.at(1)); |
| 3810 | QCOMPARE(fitResult.paramValues.at(1), 0.988871409810129); |
| 3811 | DEBUG(std::setprecision(15) << fitResult.errorValues.at(1)); |
| 3812 | QCOMPARE(fitResult.errorValues.at(1), 0.0358652107488108); |
| 3813 | DEBUG(std::setprecision(15) << fitResult.paramValues.at(2)); |
| 3814 | QCOMPARE(fitResult.paramValues.at(2), -0.138053471452345); |
| 3815 | DEBUG(std::setprecision(15) << fitResult.errorValues.at(2)); |
nothing calls this directly
no test coverage detected