| 4110 | } |
| 4111 | |
| 4112 | void FitTest::testHistogramBinomialML() { |
| 4113 | Spreadsheet spreadsheet(QStringLiteral("test"), false); |
| 4114 | AsciiFilter filter; |
| 4115 | |
| 4116 | const QString& fileName = QFINDTESTDATA(QLatin1String("data/Binomial.dat")); |
| 4117 | |
| 4118 | auto properties = filter.properties(); |
| 4119 | properties.headerEnabled = false; |
| 4120 | filter.setProperties(properties); |
| 4121 | filter.readDataFromFile(fileName, &spreadsheet, AbstractFileFilter::ImportMode::Replace); |
| 4122 | |
| 4123 | QCOMPARE(spreadsheet.rowCount(), 100); |
| 4124 | QCOMPARE(spreadsheet.columnCount(), 1); |
| 4125 | |
| 4126 | Worksheet worksheet(QStringLiteral("test"), false); |
| 4127 | auto* plot = new CartesianPlot(QStringLiteral("plot")); |
| 4128 | worksheet.addChild(plot); |
| 4129 | |
| 4130 | auto* hist = new Histogram(QStringLiteral("Histogram")); |
| 4131 | plot->addChild(hist); |
| 4132 | hist->setDataColumn(spreadsheet.column(0)); |
| 4133 | |
| 4134 | // Do the fit |
| 4135 | plot->addHistogramFit(hist, nsl_sf_stats_binomial); |
| 4136 | |
| 4137 | auto fit = dynamic_cast<XYFitCurve*>(plot->child<XYFitCurve>(0)); |
| 4138 | QVERIFY(fit != nullptr); |
| 4139 | |
| 4140 | QCOMPARE(fit->name(), i18n("Distribution Fit to '%1'", hist->name())); |
| 4141 | // get results |
| 4142 | const XYFitCurve::FitResult& fitResult = fit->fitResult(); |
| 4143 | |
| 4144 | QCOMPARE(fitResult.available, true); |
| 4145 | QCOMPARE(fitResult.valid, true); |
| 4146 | |
| 4147 | WARN(std::setprecision(15) << fitResult.paramValues.at(0)); |
| 4148 | QCOMPARE(fitResult.paramValues.at(0), 270.); |
| 4149 | WARN(std::setprecision(15) << fitResult.paramValues.at(1)); |
| 4150 | QCOMPARE(fitResult.paramValues.at(1), 0.4931); |
| 4151 | WARN(std::setprecision(15) << fitResult.errorValues.at(1)); |
| 4152 | QCOMPARE(fitResult.errorValues.at(1), 0.0499952387733072); |
| 4153 | WARN(std::setprecision(15) << fitResult.paramValues.at(1) - fitResult.marginValues.at(1)); |
| 4154 | QCOMPARE(fitResult.paramValues.at(1) - fitResult.marginValues.at(1), 0.482953993308348); |
| 4155 | WARN(std::setprecision(15) << fitResult.paramValues.at(1) + fitResult.margin2Values.at(1)); |
| 4156 | QCOMPARE(fitResult.paramValues.at(1) + fitResult.margin2Values.at(1), 0.503287947118723); |
| 4157 | |
| 4158 | QCOMPARE(fitResult.paramValues.at(2), spreadsheet.rowCount()); |
| 4159 | } |
| 4160 | |
| 4161 | QTEST_MAIN(FitTest) |
nothing calls this directly
no test coverage detected