Commit a500477a authored by Purves, Murray's avatar Purves, Murray
Browse files

More robust testing for spectrum content

parent aae646ea
Pipeline #16176 passed with stages
in 9 minutes and 4 seconds
......@@ -40,8 +40,71 @@ TEST(RadixIO, SpectrumToPCF)
// Test the contents of the two spectra
EXPECT_EQ(1, testSpectrum2->spectrumDataCount());
EXPECT_EQ(testSpectrum1->spectrumDataCount(),
ASSERT_EQ(testSpectrum1->spectrumDataCount(),
testSpectrum2->spectrumDataCount());
float tolerance = 0.001f;
// Spectrum data objects - spectrum1
std::string title1, source1, description1, dateTime1, tag1;
float liveTime1, totalTime1, energyCalOffset1, energyCalGain1,
energyCalQuadraticTerm1, energyCalCubicTerm1, energyCalLowEnergyTerm1,
occupancyFlag1, totalNeutronCount1;
int numberOfChannels1;
std::vector<float> countsByChannel1;
// Spectrum data objects - spectrum2
std::string title2, source2, description2, dateTime2, tag2;
float liveTime2, totalTime2, energyCalOffset2, energyCalGain2,
energyCalQuadraticTerm2, energyCalCubicTerm2, energyCalLowEnergyTerm2,
occupancyFlag2, totalNeutronCount2;
int numberOfChannels2;
std::vector<float> countsByChannel2;
for (size_t i = 0; i < testSpectrum1->spectrumDataCount(); ++i)
{
// Retrieve the data
testSpectrum1->spectrumData(
i, title1, source1, description1, dateTime1, tag1, liveTime1,
totalTime1, energyCalOffset1, energyCalGain1, energyCalQuadraticTerm1,
energyCalCubicTerm1, energyCalLowEnergyTerm1, occupancyFlag1,
totalNeutronCount1, numberOfChannels1, countsByChannel1);
testSpectrum2->spectrumData(
i, title2, source2, description2, dateTime2, tag2, liveTime2,
totalTime2, energyCalOffset2, energyCalGain2, energyCalQuadraticTerm2,
energyCalCubicTerm2, energyCalLowEnergyTerm2, occupancyFlag2,
totalNeutronCount2, numberOfChannels2, countsByChannel2);
// Check the header data
EXPECT_STREQ(title1.c_str(), title2.c_str());
EXPECT_STREQ(source1.c_str(), source2.c_str());
EXPECT_STREQ(description1.c_str(), description2.c_str());
EXPECT_STREQ(dateTime1.c_str(), dateTime2.c_str());
EXPECT_STREQ(tag1.c_str(), tag2.c_str());
EXPECT_NEAR(liveTime1, liveTime2, abs(liveTime1 * tolerance));
EXPECT_NEAR(totalTime1, totalTime2, abs(totalTime1 * tolerance));
EXPECT_NEAR(energyCalOffset1, energyCalOffset2,
abs(energyCalOffset1 * tolerance));
EXPECT_NEAR(energyCalGain1, energyCalGain2,
abs(energyCalGain1 * tolerance));
EXPECT_NEAR(energyCalQuadraticTerm1, energyCalQuadraticTerm2,
abs(energyCalQuadraticTerm1 * tolerance));
EXPECT_NEAR(energyCalCubicTerm1, energyCalCubicTerm2,
abs(energyCalCubicTerm1 * tolerance));
EXPECT_NEAR(energyCalLowEnergyTerm1, energyCalLowEnergyTerm2,
abs(energyCalLowEnergyTerm1 * tolerance));
EXPECT_NEAR(occupancyFlag1, occupancyFlag2,
abs(occupancyFlag1 * tolerance));
EXPECT_NEAR(totalNeutronCount1, totalNeutronCount2,
abs(totalNeutronCount1 * tolerance));
EXPECT_EQ(numberOfChannels1, numberOfChannels2);
EXPECT_EQ(numberOfChannels1, countsByChannel1.size());
EXPECT_EQ(numberOfChannels2, countsByChannel2.size());
// Check the spectrum itself
ASSERT_EQ(countsByChannel1.size(), countsByChannel2.size());
for (size_t j = 0; j < countsByChannel1.size(); ++j)
{
EXPECT_NEAR(countsByChannel1[j], countsByChannel2[j],
abs(countsByChannel1[j] * tolerance));
}
}
}
TEST(RadixIO, SpectrumFromSPE)
......@@ -79,6 +142,69 @@ TEST(RadixIO, SpectrumToSPE)
// Test the contents of the two spectra
EXPECT_EQ(1, testSpectrum2->spectrumDataCount());
EXPECT_EQ(testSpectrum1->spectrumDataCount(),
ASSERT_EQ(testSpectrum1->spectrumDataCount(),
testSpectrum2->spectrumDataCount());
float tolerance = 0.001f;
// Spectrum data objects - spectrum1
std::string title1, source1, description1, dateTime1, tag1;
float liveTime1, totalTime1, energyCalOffset1, energyCalGain1,
energyCalQuadraticTerm1, energyCalCubicTerm1, energyCalLowEnergyTerm1,
occupancyFlag1, totalNeutronCount1;
int numberOfChannels1;
std::vector<float> countsByChannel1;
// Spectrum data objects - spectrum2
std::string title2, source2, description2, dateTime2, tag2;
float liveTime2, totalTime2, energyCalOffset2, energyCalGain2,
energyCalQuadraticTerm2, energyCalCubicTerm2, energyCalLowEnergyTerm2,
occupancyFlag2, totalNeutronCount2;
int numberOfChannels2;
std::vector<float> countsByChannel2;
for (size_t i = 0; i < testSpectrum1->spectrumDataCount(); ++i)
{
// Retrieve the data
testSpectrum1->spectrumData(
i, title1, source1, description1, dateTime1, tag1, liveTime1,
totalTime1, energyCalOffset1, energyCalGain1, energyCalQuadraticTerm1,
energyCalCubicTerm1, energyCalLowEnergyTerm1, occupancyFlag1,
totalNeutronCount1, numberOfChannels1, countsByChannel1);
testSpectrum2->spectrumData(
i, title2, source2, description2, dateTime2, tag2, liveTime2,
totalTime2, energyCalOffset2, energyCalGain2, energyCalQuadraticTerm2,
energyCalCubicTerm2, energyCalLowEnergyTerm2, occupancyFlag2,
totalNeutronCount2, numberOfChannels2, countsByChannel2);
// Check the header data
EXPECT_STREQ(title1.c_str(), title2.c_str());
EXPECT_STREQ(source1.c_str(), source2.c_str());
EXPECT_STREQ(description1.c_str(), description2.c_str());
EXPECT_STREQ(dateTime1.c_str(), dateTime2.c_str());
EXPECT_STREQ(tag1.c_str(), tag2.c_str());
EXPECT_NEAR(liveTime1, liveTime2, abs(liveTime1 * tolerance));
EXPECT_NEAR(totalTime1, totalTime2, abs(totalTime1 * tolerance));
EXPECT_NEAR(energyCalOffset1, energyCalOffset2,
abs(energyCalOffset1 * tolerance));
EXPECT_NEAR(energyCalGain1, energyCalGain2,
abs(energyCalGain1 * tolerance));
EXPECT_NEAR(energyCalQuadraticTerm1, energyCalQuadraticTerm2,
abs(energyCalQuadraticTerm1 * tolerance));
EXPECT_NEAR(energyCalCubicTerm1, energyCalCubicTerm2,
abs(energyCalCubicTerm1 * tolerance));
EXPECT_NEAR(energyCalLowEnergyTerm1, energyCalLowEnergyTerm2,
abs(energyCalLowEnergyTerm1 * tolerance));
EXPECT_NEAR(occupancyFlag1, occupancyFlag2,
abs(occupancyFlag1 * tolerance));
EXPECT_NEAR(totalNeutronCount1, totalNeutronCount2,
abs(totalNeutronCount1 * tolerance));
EXPECT_EQ(numberOfChannels1, numberOfChannels2);
EXPECT_EQ(numberOfChannels1, countsByChannel1.size());
EXPECT_EQ(numberOfChannels2, countsByChannel2.size());
// Check the spectrum itself
ASSERT_EQ(countsByChannel1.size(), countsByChannel2.size());
for (size_t j = 0; j < countsByChannel1.size(); ++j)
{
EXPECT_NEAR(countsByChannel1[j], countsByChannel2[j],
abs(countsByChannel1[j] * tolerance));
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment