Commit 094bc49e authored by Purves, Murray's avatar Purves, Murray
Browse files

Adding tests for conversion between PCF and SPE

parent 61f7f1b6
Pipeline #16177 failed with stages
in 7 minutes and 31 seconds
......@@ -77,22 +77,22 @@ TEST(RadixIO, SpectrumToPCF)
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(liveTime1, liveTime2, fabs(liveTime1 * tolerance));
EXPECT_NEAR(totalTime1, totalTime2, fabs(totalTime1 * tolerance));
EXPECT_NEAR(energyCalOffset1, energyCalOffset2,
abs(energyCalOffset1 * tolerance));
fabs(energyCalOffset1 * tolerance));
EXPECT_NEAR(energyCalGain1, energyCalGain2,
abs(energyCalGain1 * tolerance));
fabs(energyCalGain1 * tolerance));
EXPECT_NEAR(energyCalQuadraticTerm1, energyCalQuadraticTerm2,
abs(energyCalQuadraticTerm1 * tolerance));
fabs(energyCalQuadraticTerm1 * tolerance));
EXPECT_NEAR(energyCalCubicTerm1, energyCalCubicTerm2,
abs(energyCalCubicTerm1 * tolerance));
fabs(energyCalCubicTerm1 * tolerance));
EXPECT_NEAR(energyCalLowEnergyTerm1, energyCalLowEnergyTerm2,
abs(energyCalLowEnergyTerm1 * tolerance));
fabs(energyCalLowEnergyTerm1 * tolerance));
EXPECT_NEAR(occupancyFlag1, occupancyFlag2,
abs(occupancyFlag1 * tolerance));
fabs(occupancyFlag1 * tolerance));
EXPECT_NEAR(totalNeutronCount1, totalNeutronCount2,
abs(totalNeutronCount1 * tolerance));
fabs(totalNeutronCount1 * tolerance));
EXPECT_EQ(numberOfChannels1, numberOfChannels2);
EXPECT_EQ(numberOfChannels1, countsByChannel1.size());
EXPECT_EQ(numberOfChannels2, countsByChannel2.size());
......@@ -102,7 +102,7 @@ TEST(RadixIO, SpectrumToPCF)
for (size_t j = 0; j < countsByChannel1.size(); ++j)
{
EXPECT_NEAR(countsByChannel1[j], countsByChannel2[j],
abs(countsByChannel1[j] * tolerance));
fabs(countsByChannel1[j] * tolerance));
}
}
}
......@@ -179,22 +179,22 @@ TEST(RadixIO, SpectrumToSPE)
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(liveTime1, liveTime2, fabs(liveTime1 * tolerance));
EXPECT_NEAR(totalTime1, totalTime2, fabs(totalTime1 * tolerance));
EXPECT_NEAR(energyCalOffset1, energyCalOffset2,
abs(energyCalOffset1 * tolerance));
fabs(energyCalOffset1 * tolerance));
EXPECT_NEAR(energyCalGain1, energyCalGain2,
abs(energyCalGain1 * tolerance));
fabs(energyCalGain1 * tolerance));
EXPECT_NEAR(energyCalQuadraticTerm1, energyCalQuadraticTerm2,
abs(energyCalQuadraticTerm1 * tolerance));
fabs(energyCalQuadraticTerm1 * tolerance));
EXPECT_NEAR(energyCalCubicTerm1, energyCalCubicTerm2,
abs(energyCalCubicTerm1 * tolerance));
fabs(energyCalCubicTerm1 * tolerance));
EXPECT_NEAR(energyCalLowEnergyTerm1, energyCalLowEnergyTerm2,
abs(energyCalLowEnergyTerm1 * tolerance));
fabs(energyCalLowEnergyTerm1 * tolerance));
EXPECT_NEAR(occupancyFlag1, occupancyFlag2,
abs(occupancyFlag1 * tolerance));
fabs(occupancyFlag1 * tolerance));
EXPECT_NEAR(totalNeutronCount1, totalNeutronCount2,
abs(totalNeutronCount1 * tolerance));
fabs(totalNeutronCount1 * tolerance));
EXPECT_EQ(numberOfChannels1, numberOfChannels2);
EXPECT_EQ(numberOfChannels1, countsByChannel1.size());
EXPECT_EQ(numberOfChannels2, countsByChannel2.size());
......@@ -204,7 +204,181 @@ TEST(RadixIO, SpectrumToSPE)
for (size_t j = 0; j < countsByChannel1.size(); ++j)
{
EXPECT_NEAR(countsByChannel1[j], countsByChannel2[j],
abs(countsByChannel1[j] * tolerance));
fabs(countsByChannel1[j] * tolerance));
}
}
}
TEST(RadixIO, PCFToSPE)
{
// Read in a test spectrum
std::string testReadPCFFile = radix::to_native_path(
std::string(dirname(__FILE__) + "/data/detective-ex100.pcf"));
Spectrum::SP testSpectrum1 = std::make_shared<Spectrum>();
SpectrumPCFStream<Spectrum::SP> testStream1(testSpectrum1);
ASSERT_TRUE(testStream1.read_from(testReadPCFFile));
// Write the spectrum back out to a file
std::string testWriteSPEFile = "test.spe";
SpectrumSPEStream<Spectrum::SP> testWriteStream(testSpectrum1);
ASSERT_TRUE(testWriteStream.write_to(testWriteSPEFile));
// Read it again and ensure the round trip is successful
Spectrum::SP testSpectrum2 = std::make_shared<Spectrum>();
SpectrumSPEStream<Spectrum::SP> testStream2(testSpectrum2);
ASSERT_TRUE(testStream2.read_from(testWriteSPEFile));
// Test the contents of the two spectra
EXPECT_EQ(1, testSpectrum2->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, fabs(liveTime1 * tolerance));
EXPECT_NEAR(totalTime1, totalTime2, fabs(totalTime1 * tolerance));
EXPECT_NEAR(energyCalOffset1, energyCalOffset2, fabs(tolerance));
EXPECT_NEAR(energyCalGain1, energyCalGain2,
fabs(energyCalGain1 * tolerance));
EXPECT_NEAR(energyCalQuadraticTerm1, energyCalQuadraticTerm2,
fabs(energyCalQuadraticTerm1 * tolerance));
EXPECT_NEAR(energyCalCubicTerm1, energyCalCubicTerm2,
fabs(energyCalCubicTerm1 * tolerance));
EXPECT_NEAR(energyCalLowEnergyTerm1, energyCalLowEnergyTerm2,
fabs(energyCalLowEnergyTerm1 * tolerance));
EXPECT_NEAR(occupancyFlag1, occupancyFlag2,
fabs(occupancyFlag1 * tolerance));
EXPECT_NEAR(totalNeutronCount1, totalNeutronCount2,
fabs(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(int(countsByChannel1[j]), int(countsByChannel2[j]), 1);
}
}
}
TEST(RadixIO, SPEToPCF)
{
// Read in a test spectrum
std::string testReadSPEFile = radix::to_native_path(
std::string(dirname(__FILE__) + "/data/235F-single.spe"));
Spectrum::SP testSpectrum1 = std::make_shared<Spectrum>();
SpectrumSPEStream<Spectrum::SP> testStream1(testSpectrum1);
ASSERT_TRUE(testStream1.read_from(testReadSPEFile));
// Write the spectrum back out to a file
std::string testWritePCFFile = "test.pcf";
SpectrumPCFStream<Spectrum::SP> testWriteStream(testSpectrum1);
ASSERT_TRUE(testWriteStream.write_to(testWritePCFFile));
// Read it again and ensure the round trip is successful
Spectrum::SP testSpectrum2 = std::make_shared<Spectrum>();
SpectrumPCFStream<Spectrum::SP> testStream2(testSpectrum2);
ASSERT_TRUE(testStream2.read_from(testWritePCFFile));
// Test the contents of the two spectra
EXPECT_EQ(1, testSpectrum2->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, fabs(liveTime1 * tolerance));
EXPECT_NEAR(totalTime1, totalTime2, fabs(totalTime1 * tolerance));
EXPECT_NEAR(energyCalOffset1, energyCalOffset2,
fabs(energyCalOffset1 * tolerance));
EXPECT_NEAR(energyCalGain1, energyCalGain2,
fabs(energyCalGain1 * tolerance));
EXPECT_NEAR(energyCalQuadraticTerm1, energyCalQuadraticTerm2,
fabs(energyCalQuadraticTerm1 * tolerance));
EXPECT_NEAR(energyCalCubicTerm1, energyCalCubicTerm2,
fabs(energyCalCubicTerm1 * tolerance));
EXPECT_NEAR(energyCalLowEnergyTerm1, energyCalLowEnergyTerm2,
fabs(energyCalLowEnergyTerm1 * tolerance));
EXPECT_NEAR(occupancyFlag1, occupancyFlag2,
fabs(occupancyFlag1 * tolerance));
EXPECT_NEAR(totalNeutronCount1, totalNeutronCount2,
fabs(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],
fabs(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