Skip to content

Commit

Permalink
Updated BundleResults Serialization test
Browse files Browse the repository at this point in the history
  • Loading branch information
acpaquette committed Jan 12, 2024
1 parent e2dcece commit 23997eb
Showing 1 changed file with 76 additions and 76 deletions.
152 changes: 76 additions & 76 deletions isis/tests/BundleResultsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QString>
#include <QtDebug>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>

#include "BundleControlPoint.h"
#include "IsisBundleObservation.h"
Expand Down Expand Up @@ -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());

Expand All @@ -55,24 +56,23 @@ 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"));
}
}
}

/**
* Destroys the tester object
*/
~BundleResultsXmlHandlerTester() {
if (m_file.exists()) {
m_file.remove();
}
// if (m_file.exists()) {
// m_file.remove();
// }
}

QFile m_file;
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down

0 comments on commit 23997eb

Please sign in to comment.