From 23997ebfa0bae1b18560ad048d4f7b386bf4da7e Mon Sep 17 00:00:00 2001 From: acpaquette Date: Fri, 12 Jan 2024 13:40:33 -0700 Subject: [PATCH] Updated BundleResults Serialization test --- isis/tests/BundleResultsTests.cpp | 152 +++++++++++++++--------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/isis/tests/BundleResultsTests.cpp b/isis/tests/BundleResultsTests.cpp index c5433a8e31..3d03fe7a15 100644 --- a/isis/tests/BundleResultsTests.cpp +++ b/isis/tests/BundleResultsTests.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "BundleControlPoint.h" #include "IsisBundleObservation.h" @@ -45,7 +46,7 @@ namespace Isis { * * @param xmlFile The xml file to construct the tester from. */ - BundleResultsXmlHandlerTester(FileName xmlFile) : BundleResults() { + BundleResultsXmlHandlerTester(QXmlStreamReader *reader, FileName xmlFile) : BundleResults() { m_file.setFileName(xmlFile.expanded()); @@ -55,14 +56,13 @@ namespace Isis { _FILEINFO_); } - QXmlStreamReader reader(&m_file); - while (!reader.atEnd()) { - reader.readNext(); - } - if (reader.hasError()) { - throw IException(IException::Unknown, - QString("Failed to parse xml file, [%1]").arg(m_file.fileName()), - _FILEINFO_); + if (reader->readNextStartElement()) { + if (reader->name() == "bundleResults") { + readBundleResults(reader); + } + else { + reader->raiseError(QObject::tr("Incorrect file")); + } } } @@ -70,9 +70,9 @@ namespace Isis { * Destroys the tester object */ ~BundleResultsXmlHandlerTester() { - if (m_file.exists()) { - m_file.remove(); - } + // if (m_file.exists()) { + // m_file.remove(); + // } } QFile m_file; @@ -589,7 +589,8 @@ TEST(BundleResults, NoOutputNet) { TEST_F(BundleResultsPopulated, Serialization) { - QString saveFile = tempDir.path() + "/BundleResultsTestData.xml"; + QString saveFile = "/Users/acpaquette/BundleResultsTestData.xml"; + // QString saveFile = tempDir.path() + "/BundleResultsTestData.xml"; QFile qXmlFile(saveFile); qXmlFile.open(QIODevice::ReadWrite); QXmlStreamWriter writer(&qXmlFile); @@ -607,70 +608,69 @@ TEST_F(BundleResultsPopulated, Serialization) { } QXmlStreamReader reader(&xml); + BundleResultsXmlHandlerTester newResults(&reader, saveFile); - if (reader.readNextStartElement()) { - if (reader.name() == "bundleResults"){ - while(reader.readNextStartElement()){ - if(reader.name() == "generalStatisticsValues") { - while(reader.readNextStartElement()) { - if (reader.name() == "numberFixedPoints") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberFixedPoints()); - } - if (reader.name() == "numberHeldImages") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberHeldImages()); - } - if (reader.name() == "numberIgnoredPoints") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberIgnoredPoints()); - } - if (reader.name() == "numberRejectedObservations") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberRejectedObservations()); - } - if (reader.name() == "numberObservations") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberObservations()); - } - if (reader.name() == "numberImageObservations") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberImageObservations()); - } - if (reader.name() == "numberLidarImageObservations") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberLidarImageObservations()); - } - if (reader.name() == "numberImageParameters") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberImageParameters()); - } - if (reader.name() == "numberConstrainedPointParameters") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberConstrainedPointParameters()); - } - if (reader.name() == "numberConstrainedImageParameters") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberConstrainedImageParameters()); - } - if (reader.name() == "numberConstrainedTargetParameters") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberConstrainedTargetParameters()); - } - if (reader.name() == "numberLidarRangeConstraintEquations") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberLidarRangeConstraintEquations()); - } - if (reader.name() == "numberUnknownParameters") { - EXPECT_EQ(reader.readElementText().toInt(), results.numberUnknownParameters()); - } - if (reader.name() == "degreesOfFreedom") { - EXPECT_EQ(reader.readElementText().toInt(), results.degreesOfFreedom()); - } - } - } - else { - reader.skipCurrentElement(); - } - } - } - else { - reader.raiseError(QObject::tr("Incorrect file")); - } - } - if (reader.hasError()) { - throw IException(IException::Unknown, - QString("Failed to parse xml file, [%1]").arg(xml.fileName()), - _FILEINFO_); - } + EXPECT_EQ(newResults.numberFixedPoints(), results.numberFixedPoints()); + EXPECT_EQ(newResults.numberHeldImages(), results.numberHeldImages()); + EXPECT_EQ(newResults.numberIgnoredPoints(), results.numberIgnoredPoints()); + EXPECT_EQ(newResults.numberRejectedObservations(), results.numberRejectedObservations()); + EXPECT_EQ(newResults.numberObservations(), results.numberObservations()); + EXPECT_EQ(newResults.numberImageObservations(), results.numberImageObservations()); + EXPECT_EQ(newResults.numberLidarImageObservations(), results.numberLidarImageObservations()); + EXPECT_EQ(newResults.numberImageParameters(), results.numberImageParameters()); + EXPECT_EQ(newResults.numberConstrainedPointParameters(), results.numberConstrainedPointParameters()); + EXPECT_EQ(newResults.numberConstrainedImageParameters(), results.numberConstrainedImageParameters()); + EXPECT_EQ(newResults.numberConstrainedTargetParameters(), results.numberConstrainedTargetParameters()); + EXPECT_EQ(newResults.numberLidarRangeConstraintEquations(), results.numberLidarRangeConstraintEquations()); + EXPECT_EQ(newResults.numberUnknownParameters(), results.numberUnknownParameters()); + EXPECT_EQ(newResults.degreesOfFreedom(), results.degreesOfFreedom()); + + // The Statistics class handles saving itself, so just make sure we have the correct amount + EXPECT_EQ(newResults.rmsImageSampleResiduals().size(), results.rmsImageSampleResiduals().size()); + EXPECT_EQ(newResults.rmsImageLineResiduals().size(), results.rmsImageLineResiduals().size()); + EXPECT_EQ(newResults.rmsImageResiduals().size(), results.rmsImageResiduals().size()); + EXPECT_EQ(newResults.rmsLidarImageSampleResiduals().size(), results.rmsLidarImageSampleResiduals().size()); + EXPECT_EQ(newResults.rmsLidarImageLineResiduals().size(), results.rmsLidarImageLineResiduals().size()); + EXPECT_EQ(newResults.rmsLidarImageResiduals().size(), results.rmsLidarImageResiduals().size()); + EXPECT_EQ(newResults.minSigmaCoord1Distance().meters(), results.minSigmaCoord1Distance().meters()); + EXPECT_EQ(newResults.maxSigmaCoord1Distance().meters(), results.maxSigmaCoord1Distance().meters()); + EXPECT_EQ(newResults.minSigmaCoord2Distance().meters(), results.minSigmaCoord2Distance().meters()); + EXPECT_EQ(newResults.maxSigmaCoord2Distance().meters(), results.maxSigmaCoord2Distance().meters()); + EXPECT_EQ(newResults.minSigmaCoord3Distance().meters(), results.minSigmaCoord3Distance().meters()); + EXPECT_EQ(newResults.maxSigmaCoord3Distance().meters(), results.maxSigmaCoord3Distance().meters()); + EXPECT_EQ(newResults.minSigmaCoord1PointId().toStdString(), results.minSigmaCoord1PointId().toStdString()); + EXPECT_EQ(newResults.maxSigmaCoord1PointId().toStdString(), results.maxSigmaCoord1PointId().toStdString()); + EXPECT_EQ(newResults.minSigmaCoord2PointId().toStdString(), results.minSigmaCoord2PointId().toStdString()); + EXPECT_EQ(newResults.maxSigmaCoord2PointId().toStdString(), results.maxSigmaCoord2PointId().toStdString()); + EXPECT_EQ(newResults.minSigmaCoord3PointId().toStdString(), results.minSigmaCoord3PointId().toStdString()); + EXPECT_EQ(newResults.maxSigmaCoord3PointId().toStdString(), results.maxSigmaCoord3PointId().toStdString()); + EXPECT_EQ(newResults.rmsRx(), results.rmsRx()); + EXPECT_EQ(newResults.rmsRy(), results.rmsRy()); + EXPECT_EQ(newResults.rmsRxy(), results.rmsRxy()); + EXPECT_EQ(newResults.rejectionLimit(), results.rejectionLimit()); + EXPECT_EQ(newResults.sigma0(), results.sigma0()); + EXPECT_EQ(newResults.elapsedTime(), results.elapsedTime()); + EXPECT_EQ(newResults.elapsedTimeErrorProp(), results.elapsedTimeErrorProp()); + EXPECT_EQ(newResults.iterations(), results.iterations()); + EXPECT_EQ(newResults.converged(), results.converged()); + + EXPECT_EQ(newResults.numberMaximumLikelihoodModels(), results.numberMaximumLikelihoodModels()); + + // Reset the MLE index so we can compare them one by one + newResults.printMaximumLikelihoodTierInformation(); + results.printMaximumLikelihoodTierInformation(); + + EXPECT_EQ(newResults.maximumLikelihoodMedianR2Residuals(), results.maximumLikelihoodMedianR2Residuals()); + + newResults.incrementMaximumLikelihoodModelIndex(); + results.incrementMaximumLikelihoodModelIndex(); + EXPECT_EQ(newResults.maximumLikelihoodMedianR2Residuals(), results.maximumLikelihoodMedianR2Residuals()); + + newResults.incrementMaximumLikelihoodModelIndex(); + results.incrementMaximumLikelihoodModelIndex(); + EXPECT_EQ(newResults.maximumLikelihoodMedianR2Residuals(), results.maximumLikelihoodMedianR2Residuals()); + + EXPECT_EQ(newResults.coordTypeReports(), results.coordTypeReports()); // // The Statistics class handles saving itself, so just make sure we have the correct amount // EXPECT_EQ(newResults.rmsImageSampleResiduals().size(), results.rmsImageSampleResiduals().size());