From e73b1698f63bd92ab0f61c61eb813aeb7ae98068 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Fri, 8 Dec 2017 18:37:53 +0100 Subject: [PATCH] Standard code beautification in Core unit tests. --- Tests/UnitTests/Core/Axes/CVectorTest.h | 52 ++-- Tests/UnitTests/Core/Axes/ConstKBinAxisTest.h | 56 ++-- Tests/UnitTests/Core/Axes/CustomBinAxisTest.h | 13 +- Tests/UnitTests/Core/Axes/FixedBinAxisTest.h | 82 +++--- Tests/UnitTests/Core/Axes/Histogram1DTest.h | 70 +++-- Tests/UnitTests/Core/Axes/Histogram2DTest.h | 3 +- Tests/UnitTests/Core/Axes/KVectorTest.h | 186 +++++++----- .../UnitTests/Core/Axes/VariableBinAxisTest.h | 141 +++++---- .../IntensityDataFunctionsTest.h | 127 ++------ .../UnitTests/Core/DataStructure/LLDataTest.h | 271 +++++++++--------- .../DataStructure/OutputDataIteratorTest.h | 17 +- .../Core/DataStructure/OutputDataTest.h | 1 + .../Core/Detector/DetectorMaskTest.h | 26 +- Tests/UnitTests/Core/Detector/PolygonTest.h | 30 +- .../UnitTests/Core/Detector/PrecomputedTest.h | 15 +- .../Core/Detector/RectangularDetectorTest.h | 151 +++++----- .../Core/Detector/RegionOfInterestTest.h | 16 +- .../Core/Detector/SimulationAreaTest.h | 36 ++- .../Core/Detector/SpecialFunctionsTest.h | 116 ++++---- .../Core/Detector/SpecularDetector1DTest.h | 25 +- .../Core/Detector/SphericalDetectorTest.h | 182 ++++++------ .../ExportToPython/PythonFormattingTest.h | 19 +- .../Core/Fresnel/MatrixRTCoefficientsTest.h | 31 +- .../Core/Fresnel/ScalarRTCoefficientsTest.h | 57 ++-- .../Core/Fresnel/SpecularMagneticTest.h | 75 ++--- .../Core/Fresnel/SpecularMatrixTest.h | 16 +- .../Core/Fresnel/SpecularSimulationTest.h | 25 +- .../Numeric0/FormFactorSpecializationTest.h | 75 +++-- .../Core/Numeric1/FormFactorSymmetryTest.h | 53 ++-- Tests/UnitTests/Core/Other/BeamTest.h | 25 +- .../Core/Other/ChiSquaredModuleTest.h | 106 +------ .../Core/Other/CumulativeValueTest.h | 15 +- .../Core/Other/GISASSimulationTest.h | 36 +-- Tests/UnitTests/Core/Other/InstrumentTest.h | 40 ++- .../Core/Other/LayerFillLimitsTest.h | 24 +- Tests/UnitTests/Core/Other/MaterialTest.h | 58 ++-- Tests/UnitTests/Core/Other/OrderedMapTest.h | 31 +- Tests/UnitTests/Core/Other/RelDiffTest.h | 23 +- .../Core/Other/SampleBuilderNoteTest.h | 25 +- .../UnitTests/Core/Other/SampleProviderTest.h | 37 +-- Tests/UnitTests/Core/Other/Shape2DTest.h | 15 +- Tests/UnitTests/Core/Other/TRangeTest.h | 23 +- Tests/UnitTests/Core/Other/ThreadInfoTest.h | 24 +- Tests/UnitTests/Core/Other/ZLimitsTest.h | 36 ++- .../Core/Parameters/DistributionHandlerTest.h | 22 +- .../Core/Parameters/DistributionsTest.h | 92 +++--- .../Core/Parameters/FTDistributionsTest.h | 137 ++++----- .../Core/Parameters/IParameterizedTest.h | 48 ++-- .../Parameters/ParameterDistributionTest.h | 32 ++- .../Core/Parameters/ParameterPatternTest.h | 20 +- .../Core/Parameters/ParameterPoolTest.h | 29 +- .../Core/Parameters/RealParameterTest.h | 19 +- Tests/UnitTests/Core/Sample/CrystalTest.h | 8 +- .../Core/Sample/FormFactorBasicTest.h | 212 +++++++------- .../Core/Sample/FormFactorCoherentSumTest.h | 10 +- Tests/UnitTests/Core/Sample/INodeTest.h | 67 ++--- Tests/UnitTests/Core/Sample/Lattice2DTest.h | 15 +- Tests/UnitTests/Core/Sample/LatticeTest.h | 84 +++--- .../Core/Sample/LayerInterfaceTest.h | 14 +- .../Core/Sample/LayerRoughnessTest.h | 27 +- Tests/UnitTests/Core/Sample/LayerTest.h | 17 +- Tests/UnitTests/Core/Sample/MesoCrystalTest.h | 10 +- Tests/UnitTests/Core/Sample/MultiLayerTest.h | 265 +++++++++-------- .../Core/Sample/ParticleCompositionTest.h | 9 +- .../Core/Sample/ParticleCoreShellTest.h | 33 +-- .../Core/Sample/ParticleDistributionTest.h | 21 +- .../Core/Sample/ParticleLayoutTest.h | 91 +++--- Tests/UnitTests/Core/Sample/ParticleTest.h | 30 +- Tests/UnitTests/Core/Sample/RTTest.h | 75 +++-- Tests/UnitTests/Fit/FitKernel/AttLimitsTest.h | 2 +- Tests/UnitTests/Fit/FitKernel/FitObjectTest.h | 2 +- .../Fit/FitKernel/FitParameterSetTest.h | 2 +- .../Fit/FitKernel/FitParameterTest.h | 2 +- Tests/UnitTests/Fit/FitKernel/FitSuiteTest.h | 6 +- .../Fit/FitKernel/IFitParameterTest.h | 2 +- .../Fit/FitKernel/MinimizerOptionsTest.h | 2 +- .../UnitTests/Fit/FitKernel/MultiOptionTest.h | 2 +- .../Fit/FitKernel/OptionContainerTest.h | 2 +- .../UnitTests/Fit/FitKernel/RealLimitsTest.h | 1 + .../UnitTests/Fit/FitKernel/StringUtilsTest.h | 1 + 80 files changed, 1861 insertions(+), 2035 deletions(-) diff --git a/Tests/UnitTests/Core/Axes/CVectorTest.h b/Tests/UnitTests/Core/Axes/CVectorTest.h index 3ad0f0bbc2d..39062a582a3 100644 --- a/Tests/UnitTests/Core/Axes/CVectorTest.h +++ b/Tests/UnitTests/Core/Axes/CVectorTest.h @@ -1,44 +1,46 @@ -#include "Vectors3D.h" -#include "EigenCore.h" +#include "google_test.h" #include "Complex.h" +#include "EigenCore.h" +#include "Vectors3D.h" class CVectorTest : public ::testing::Test { - protected: - CVectorTest() {} - virtual ~CVectorTest() {} +protected: + ~CVectorTest(); }; +CVectorTest::~CVectorTest() = default; + TEST_F(CVectorTest, TrivialOperations) { - kvector_t vec_k(1.,2.,3.); - EXPECT_EQ( vec_k.complex().z(), complex_t(3.,0.) ); + kvector_t vec_k(1., 2., 3.); + EXPECT_EQ(vec_k.complex().z(), complex_t(3., 0.)); - cvector_t vec_c(complex_t(1.,3.), complex_t(2.,-5.), complex_t(-3.,-4.)); - EXPECT_EQ( -vec_c.z(), complex_t(3.,4.) ); - EXPECT_DOUBLE_EQ( vec_c.mag(), 8. ); + cvector_t vec_c(complex_t(1., 3.), complex_t(2., -5.), complex_t(-3., -4.)); + EXPECT_EQ(-vec_c.z(), complex_t(3., 4.)); + EXPECT_DOUBLE_EQ(vec_c.mag(), 8.); } TEST_F(CVectorTest, BasicArithmetics) { // Dot product with "Eigen" library - Eigen::Vector3cd va(complex_t(1.,0.), complex_t(2.,0.), complex_t(3.,0.)); - Eigen::Vector3cd vc(complex_t(1.,1.), complex_t(2.,-5.), complex_t(3.,4.)); - EXPECT_TRUE(va.dot(vc) == complex_t(14.,3.)); + Eigen::Vector3cd va(complex_t(1., 0.), complex_t(2., 0.), complex_t(3., 0.)); + Eigen::Vector3cd vc(complex_t(1., 1.), complex_t(2., -5.), complex_t(3., 4.)); + EXPECT_TRUE(va.dot(vc) == complex_t(14., 3.)); // Dot product defined in BasicVector3D - cvector_t vec_a(complex_t(1.,0.), complex_t(2.,0.), complex_t(3.,0.)); - cvector_t vec_b(complex_t(2.,0.), complex_t(3.,0.), complex_t(4.,0.)); - cvector_t vec_c(complex_t(1.,1.), complex_t(2.,-5.), complex_t(3.,4.)); - EXPECT_TRUE(vec_a.dot(vec_b) == complex_t(20.,0)); - EXPECT_TRUE(vec_a.dot(vec_c) == complex_t(14.,3.)); - EXPECT_TRUE(vec_c.dot(vec_b) == complex_t(20.,-3.)); - EXPECT_TRUE(vec_a.dot(vec_a) == complex_t(14.,0)); - EXPECT_TRUE(vec_c.dot(vec_c) == complex_t(56.,0)); + cvector_t vec_a(complex_t(1., 0.), complex_t(2., 0.), complex_t(3., 0.)); + cvector_t vec_b(complex_t(2., 0.), complex_t(3., 0.), complex_t(4., 0.)); + cvector_t vec_c(complex_t(1., 1.), complex_t(2., -5.), complex_t(3., 4.)); + EXPECT_TRUE(vec_a.dot(vec_b) == complex_t(20., 0)); + EXPECT_TRUE(vec_a.dot(vec_c) == complex_t(14., 3.)); + EXPECT_TRUE(vec_c.dot(vec_b) == complex_t(20., -3.)); + EXPECT_TRUE(vec_a.dot(vec_a) == complex_t(14., 0)); + EXPECT_TRUE(vec_c.dot(vec_c) == complex_t(56., 0)); // f = f_re + j*f_im - cvector_t vec_e(1.,2.,3.); - cvector_t vec_f(5.,6.,7.); - EXPECT_EQ( vec_e+complex_t(0,1)*vec_f, - cvector_t(complex_t(1.,5.), complex_t(2.,6), complex_t(3,7)) ); + cvector_t vec_e(1., 2., 3.); + cvector_t vec_f(5., 6., 7.); + EXPECT_EQ(vec_e + complex_t(0, 1) * vec_f, + cvector_t(complex_t(1., 5.), complex_t(2., 6), complex_t(3, 7))); } diff --git a/Tests/UnitTests/Core/Axes/ConstKBinAxisTest.h b/Tests/UnitTests/Core/Axes/ConstKBinAxisTest.h index 452704bc4f0..e716066c373 100644 --- a/Tests/UnitTests/Core/Axes/ConstKBinAxisTest.h +++ b/Tests/UnitTests/Core/Axes/ConstKBinAxisTest.h @@ -1,30 +1,30 @@ +#include "google_test.h" #include "ConstKBinAxis.h" #include "DataFormatUtils.h" #include "Units.h" #include <vector> -class ConstKBinAxisTest: public ::testing::Test +class ConstKBinAxisTest : public ::testing::Test { protected: ConstKBinAxisTest() - : m_nbins(10) - , m_start(-5.0*Units::degree) - , m_end(5.0*Units::degree) - , m_axis("name", m_nbins, m_start, m_end) + : m_nbins(10), m_start(-5.0 * Units::degree), m_end(5.0 * Units::degree), + m_axis("name", m_nbins, m_start, m_end) { double start_sin = std::sin(m_start); double end_sin = std::sin(m_end); - double step = (end_sin-start_sin)/m_nbins; + double step = (end_sin - start_sin) / m_nbins; - for(size_t i=0; i<m_nbins; ++i) { - m_centers.push_back( (std::asin(start_sin + step*i) + std::asin(start_sin + step*(i+1)))/2.0 ); + for (size_t i = 0; i < m_nbins; ++i) { + m_centers.push_back( + (std::asin(start_sin + step * i) + std::asin(start_sin + step * (i + 1))) / 2.0); } - for(size_t i=0; i<m_nbins+1; ++i) { - m_boundaries.push_back( std::asin(start_sin + step*i) ); + for (size_t i = 0; i < m_nbins + 1; ++i) { + m_boundaries.push_back(std::asin(start_sin + step * i)); } - } + ~ConstKBinAxisTest(); size_t m_nbins; double m_start; @@ -34,8 +34,10 @@ protected: std::vector<double> m_boundaries; }; +ConstKBinAxisTest::~ConstKBinAxisTest() = default; -//[-5.0, -3.99816897832528, -2.9975609824866662, -1.99786732193833, -0.9987818274427882, 0.0, 0.9987818274427874, 1.9978673219383292, 2.997560982486666, 3.998168978325279, 5.0] +//[-5.0, -3.99816897832528, -2.9975609824866662, -1.99786732193833, -0.9987818274427882, 0.0, +//0.9987818274427874, 1.9978673219383292, 2.997560982486666, 3.998168978325279, 5.0] TEST_F(ConstKBinAxisTest, TypicalAxis) { EXPECT_EQ(m_nbins, m_axis.size()); @@ -45,50 +47,48 @@ TEST_F(ConstKBinAxisTest, TypicalAxis) EXPECT_DOUBLE_EQ(m_start, m_axis.getBinBoundaries().front()); EXPECT_DOUBLE_EQ(m_end, m_axis.getBinBoundaries().back()); - for(size_t i=0; i<m_axis.size(); ++i) { - EXPECT_DOUBLE_EQ( m_centers[i], m_axis[i]); + for (size_t i = 0; i < m_axis.size(); ++i) { + EXPECT_DOUBLE_EQ(m_centers[i], m_axis[i]); } - for(size_t i=0; i<m_axis.size(); ++i) { - EXPECT_DOUBLE_EQ( m_boundaries[i], m_axis.getBin(i).m_lower); - EXPECT_DOUBLE_EQ( m_boundaries[i+1], m_axis.getBin(i).m_upper); + for (size_t i = 0; i < m_axis.size(); ++i) { + EXPECT_DOUBLE_EQ(m_boundaries[i], m_axis.getBin(i).m_lower); + EXPECT_DOUBLE_EQ(m_boundaries[i + 1], m_axis.getBin(i).m_upper); } - } - TEST_F(ConstKBinAxisTest, CheckClone) { - ConstKBinAxis *clone=m_axis.clone(); + ConstKBinAxis* clone = m_axis.clone(); EXPECT_TRUE(m_axis == *clone); delete clone; } - TEST_F(ConstKBinAxisTest, IOStream) { std::ostringstream oss; oss << m_axis; - ConstKBinAxis *result = dynamic_cast<ConstKBinAxis *>(DataFormatUtils::createFixedBinAxis(oss.str())); + ConstKBinAxis* result + = dynamic_cast<ConstKBinAxis*>(DataFormatUtils::createFixedBinAxis(oss.str())); EXPECT_TRUE(m_axis == *result); delete result; } -//[-5.0, -3.99816897832528, -2.9975609824866662, -1.99786732193833, -0.9987818274427882, 0.0, 0.9987818274427874, 1.9978673219383292, 2.997560982486666, 3.998168978325279, 5.0] +//[-5.0, -3.99816897832528, -2.9975609824866662, -1.99786732193833, -0.9987818274427882, 0.0, +//0.9987818274427874, 1.9978673219383292, 2.997560982486666, 3.998168978325279, 5.0] TEST_F(ConstKBinAxisTest, ClippedAxis) { - ConstKBinAxis *clip1 = m_axis.createClippedAxis(Units::deg2rad(-10.0), Units::deg2rad(10.0)); + ConstKBinAxis* clip1 = m_axis.createClippedAxis(Units::deg2rad(-10.0), Units::deg2rad(10.0)); EXPECT_TRUE(*clip1 == m_axis); delete clip1; - ConstKBinAxis *clip2 = m_axis.createClippedAxis(Units::deg2rad(-3.0), Units::deg2rad(3.0)); + ConstKBinAxis* clip2 = m_axis.createClippedAxis(Units::deg2rad(-3.0), Units::deg2rad(3.0)); EXPECT_EQ(clip2->size(), size_t(8)); std::vector<double> boundaries = clip2->getBinBoundaries(); - for(size_t i=0; i<boundaries.size(); ++i) { - EXPECT_EQ(boundaries[i], m_axis.getBin(1+i).m_lower); -// EXPECT_NEAR(boundaries[i], m_axis.getBin(1+i).m_lower, 1e-10); + for (size_t i = 0; i < boundaries.size(); ++i) { + EXPECT_EQ(boundaries[i], m_axis.getBin(1 + i).m_lower); } delete clip2; } diff --git a/Tests/UnitTests/Core/Axes/CustomBinAxisTest.h b/Tests/UnitTests/Core/Axes/CustomBinAxisTest.h index 06720291cd6..b8abd1c37df 100644 --- a/Tests/UnitTests/Core/Axes/CustomBinAxisTest.h +++ b/Tests/UnitTests/Core/Axes/CustomBinAxisTest.h @@ -1,20 +1,22 @@ +#include "google_test.h" #include "CustomBinAxis.h" #include "DataFormatUtils.h" #include "MathConstants.h" #include <vector> -class CusomBinAxisTest: public ::testing::Test +class CusomBinAxisTest : public ::testing::Test { protected: - CusomBinAxisTest() - : m_axis("name", 100, -1.0, 1.0){} + CusomBinAxisTest() : m_axis("name", 100, -1.0, 1.0) {} + ~CusomBinAxisTest(); CustomBinAxis m_axis; }; +CusomBinAxisTest::~CusomBinAxisTest() = default; TEST_F(CusomBinAxisTest, CheckClone) { - CustomBinAxis *clone=m_axis.clone(); + CustomBinAxis* clone = m_axis.clone(); EXPECT_TRUE(m_axis == *clone); delete clone; } @@ -25,7 +27,8 @@ TEST_F(CusomBinAxisTest, IOStream) std::ostringstream oss; oss << m_axis; - CustomBinAxis *result = dynamic_cast<CustomBinAxis *>(DataFormatUtils::createFixedBinAxis(oss.str())); + CustomBinAxis* result + = dynamic_cast<CustomBinAxis*>(DataFormatUtils::createFixedBinAxis(oss.str())); EXPECT_TRUE(m_axis == *result); delete result; } diff --git a/Tests/UnitTests/Core/Axes/FixedBinAxisTest.h b/Tests/UnitTests/Core/Axes/FixedBinAxisTest.h index 53b3661e9bc..b4e419141dd 100644 --- a/Tests/UnitTests/Core/Axes/FixedBinAxisTest.h +++ b/Tests/UnitTests/Core/Axes/FixedBinAxisTest.h @@ -1,14 +1,17 @@ -#include "FixedBinAxis.h" -#include "Exceptions.h" +#include "google_test.h" #include "DataFormatUtils.h" +#include "Exceptions.h" +#include "FixedBinAxis.h" #include <iostream> -class FixedBinAxisTest: public ::testing::Test +class FixedBinAxisTest : public ::testing::Test { protected: - FixedBinAxisTest() {} + ~FixedBinAxisTest(); }; +FixedBinAxisTest::~FixedBinAxisTest() = default; + TEST_F(FixedBinAxisTest, IndexedAccessor) { FixedBinAxis a1("length", 100, 0.0, 10.0); @@ -24,7 +27,7 @@ TEST_F(FixedBinAxisTest, IndexedAccessor) EXPECT_DOUBLE_EQ(-1.0, a2[0]); EXPECT_DOUBLE_EQ(0.0, a2[1]); EXPECT_DOUBLE_EQ(1.0, a2[2]); - ASSERT_THROW( a2[3], Exceptions::OutOfBoundsException); + ASSERT_THROW(a2[3], Exceptions::OutOfBoundsException); } TEST_F(FixedBinAxisTest, VectorOfUnitLength) @@ -39,13 +42,13 @@ TEST_F(FixedBinAxisTest, VectorOfUnitLength) TEST_F(FixedBinAxisTest, FindClosestIndex) { FixedBinAxis v1("name", 2, 0.0, 1.0); - EXPECT_EQ( size_t(2), v1.size()); - EXPECT_EQ( size_t(0), v1.findClosestIndex(0.0)); - EXPECT_EQ( size_t(0), v1.findClosestIndex(0.25)); - EXPECT_EQ( size_t(1), v1.findClosestIndex(0.5)); - EXPECT_EQ( size_t(1), v1.findClosestIndex(0.6)); -// ASSERT_THROW( v1.findClosestIndex(1.0), Exceptions::OutOfBoundsException); - EXPECT_EQ( size_t(1), v1.findClosestIndex(1.0)); + EXPECT_EQ(size_t(2), v1.size()); + EXPECT_EQ(size_t(0), v1.findClosestIndex(0.0)); + EXPECT_EQ(size_t(0), v1.findClosestIndex(0.25)); + EXPECT_EQ(size_t(1), v1.findClosestIndex(0.5)); + EXPECT_EQ(size_t(1), v1.findClosestIndex(0.6)); + // ASSERT_THROW( v1.findClosestIndex(1.0), Exceptions::OutOfBoundsException); + EXPECT_EQ(size_t(1), v1.findClosestIndex(1.0)); FixedBinAxis v2("name", 3, -1.5, 1.5); EXPECT_EQ(size_t(0), v2.findClosestIndex(-1.5)); @@ -54,37 +57,37 @@ TEST_F(FixedBinAxisTest, FindClosestIndex) EXPECT_EQ(size_t(1), v2.findClosestIndex(0.0)); EXPECT_EQ(size_t(2), v2.findClosestIndex(0.5)); EXPECT_EQ(size_t(2), v2.findClosestIndex(1.499)); -// ASSERT_THROW( v2.findClosestIndex(1.5), Exceptions::OutOfBoundsException); + // ASSERT_THROW( v2.findClosestIndex(1.5), Exceptions::OutOfBoundsException); EXPECT_EQ(size_t(2), v2.findClosestIndex(1.5)); } TEST_F(FixedBinAxisTest, CheckBin) { - FixedBinAxis axis("name",20, 0, 10); + FixedBinAxis axis("name", 20, 0, 10); Bin1D bin0 = axis.getBin(0); - EXPECT_DOUBLE_EQ( 0.25, bin0.getMidPoint()); - EXPECT_DOUBLE_EQ( 0.0, bin0.m_lower); - EXPECT_DOUBLE_EQ( 0.5, bin0.m_upper); - EXPECT_DOUBLE_EQ( 0.5, bin0.getBinSize()); + EXPECT_DOUBLE_EQ(0.25, bin0.getMidPoint()); + EXPECT_DOUBLE_EQ(0.0, bin0.m_lower); + EXPECT_DOUBLE_EQ(0.5, bin0.m_upper); + EXPECT_DOUBLE_EQ(0.5, bin0.getBinSize()); Bin1D bin3 = axis.getBin(3); - EXPECT_DOUBLE_EQ( 1.75, bin3.getMidPoint()); - EXPECT_DOUBLE_EQ( 1.5, bin3.m_lower); - EXPECT_DOUBLE_EQ( 2.0, bin3.m_upper); - EXPECT_DOUBLE_EQ( 0.5, bin3.getBinSize()); + EXPECT_DOUBLE_EQ(1.75, bin3.getMidPoint()); + EXPECT_DOUBLE_EQ(1.5, bin3.m_lower); + EXPECT_DOUBLE_EQ(2.0, bin3.m_upper); + EXPECT_DOUBLE_EQ(0.5, bin3.getBinSize()); Bin1D bin10 = axis.getBin(10); - EXPECT_DOUBLE_EQ( 5.25, bin10.getMidPoint()); - EXPECT_DOUBLE_EQ( 5.0, bin10.m_lower); - EXPECT_DOUBLE_EQ( 5.5, bin10.m_upper); + EXPECT_DOUBLE_EQ(5.25, bin10.getMidPoint()); + EXPECT_DOUBLE_EQ(5.0, bin10.m_lower); + EXPECT_DOUBLE_EQ(5.5, bin10.m_upper); Bin1D bin19 = axis.getBin(19); - EXPECT_DOUBLE_EQ( 9.75, bin19.getMidPoint()); - EXPECT_DOUBLE_EQ( 9.5, bin19.m_lower); - EXPECT_DOUBLE_EQ( 10.0, bin19.m_upper); + EXPECT_DOUBLE_EQ(9.75, bin19.getMidPoint()); + EXPECT_DOUBLE_EQ(9.5, bin19.m_lower); + EXPECT_DOUBLE_EQ(10.0, bin19.m_upper); - ASSERT_THROW( axis.getBin(20), Exceptions::OutOfBoundsException); + ASSERT_THROW(axis.getBin(20), Exceptions::OutOfBoundsException); FixedBinAxis axis2("name", 3, -1, 2.0); EXPECT_DOUBLE_EQ(-0.5, axis2.getBin(0).getMidPoint()); @@ -96,21 +99,21 @@ TEST_F(FixedBinAxisTest, CheckEquality) { FixedBinAxis b1("axis", 99, -1.01, 3.3); FixedBinAxis b2("axis", 99, -1.01, 3.3); - EXPECT_TRUE( b1 == b2); + EXPECT_TRUE(b1 == b2); FixedBinAxis b3("axissss", 99, -1.01, 3.3); FixedBinAxis b4("axis", 99, -1.0, 3.3); FixedBinAxis b5("axis", 99, -1.01, 3.29); FixedBinAxis b6("axiss", 98, -1.01, 3.3); - EXPECT_FALSE( b1 == b3); - EXPECT_FALSE( b1 == b4); - EXPECT_FALSE( b1 == b5); - EXPECT_FALSE( b1 == b6); + EXPECT_FALSE(b1 == b3); + EXPECT_FALSE(b1 == b4); + EXPECT_FALSE(b1 == b5); + EXPECT_FALSE(b1 == b6); } TEST_F(FixedBinAxisTest, CheckClone) { FixedBinAxis a1("axis", 99, -1.2, 5.4); - FixedBinAxis *clone=a1.clone(); + FixedBinAxis* clone = a1.clone(); EXPECT_TRUE(a1 == *clone); delete clone; } @@ -122,7 +125,8 @@ TEST_F(FixedBinAxisTest, IOStream) std::ostringstream oss; oss << axis; - FixedBinAxis *result = dynamic_cast<FixedBinAxis *>(DataFormatUtils::createFixedBinAxis(oss.str())); + FixedBinAxis* result + = dynamic_cast<FixedBinAxis*>(DataFormatUtils::createFixedBinAxis(oss.str())); EXPECT_TRUE(axis == *result); delete result; } @@ -139,7 +143,6 @@ TEST_F(FixedBinAxisTest, BinCenters) EXPECT_DOUBLE_EQ(axis.getBinCenter(0), centers[0]); EXPECT_DOUBLE_EQ(axis.getBinCenter(1), centers[1]); EXPECT_DOUBLE_EQ(axis.getBinCenter(2), centers[2]); - } TEST_F(FixedBinAxisTest, BinBoundaries) @@ -153,19 +156,18 @@ TEST_F(FixedBinAxisTest, BinBoundaries) EXPECT_DOUBLE_EQ(1.5, boundaries[3]); } - TEST_F(FixedBinAxisTest, ClippedAxis) { FixedBinAxis axis("name", 4, -1.0, 3.0); - FixedBinAxis *clip1 = axis.createClippedAxis(-0.5, 2.5); + FixedBinAxis* clip1 = axis.createClippedAxis(-0.5, 2.5); EXPECT_EQ(clip1->size(), axis.size()); EXPECT_EQ(clip1->getMin(), axis.getMin()); EXPECT_EQ(clip1->getMax(), axis.getMax()); EXPECT_TRUE(*clip1 == axis); delete clip1; - FixedBinAxis *clip2 = axis.createClippedAxis(0.0, 1.99); + FixedBinAxis* clip2 = axis.createClippedAxis(0.0, 1.99); EXPECT_EQ(clip2->size(), size_t(2)); EXPECT_EQ(clip2->getMin(), 0.0); EXPECT_EQ(clip2->getMax(), 2.0); diff --git a/Tests/UnitTests/Core/Axes/Histogram1DTest.h b/Tests/UnitTests/Core/Axes/Histogram1DTest.h index 53a4995f237..98d1c6dee26 100644 --- a/Tests/UnitTests/Core/Axes/Histogram1DTest.h +++ b/Tests/UnitTests/Core/Axes/Histogram1DTest.h @@ -1,14 +1,16 @@ -#include "Histogram1D.h" +#include "google_test.h" #include "Exceptions.h" +#include "Histogram1D.h" #include <memory> class Histogram1DTest : public ::testing::Test { - protected: - Histogram1DTest(){} - virtual ~Histogram1DTest(){} +protected: + ~Histogram1DTest(); }; +Histogram1DTest::~Histogram1DTest() = default; + TEST_F(Histogram1DTest, FixedBinConstructor) { Histogram1D hist(5, 0.0, 5.0); @@ -19,7 +21,7 @@ TEST_F(Histogram1DTest, FixedBinConstructor) EXPECT_EQ(5.0, hist.getXmax()); EXPECT_EQ(std::string("x-axis"), hist.getXaxis().getName()); EXPECT_THROW(hist.getYaxis(), Exceptions::LogicErrorException); - for(size_t index=0; index<hist.getTotalNumberOfBins(); ++index) { + for (size_t index = 0; index < hist.getTotalNumberOfBins(); ++index) { EXPECT_EQ(index, hist.getGlobalBin(index)); EXPECT_EQ(index, hist.getXaxisIndex(index)); } @@ -32,7 +34,7 @@ TEST_F(Histogram1DTest, FixedBinDefaultContent) // bin centers std::vector<double> bin_centers = {0.5, 1.5, 2.5, 3.5, 4.5}; std::vector<double> centers = hist.getBinCenters(); - for(size_t index=0; index < bin_centers.size(); ++index) { + for (size_t index = 0; index < bin_centers.size(); ++index) { EXPECT_EQ(centers[index], bin_centers[index]); EXPECT_EQ(hist.getXaxisValue(index), bin_centers[index]); EXPECT_EQ(hist.getXaxis().getBinCenter(index), bin_centers[index]); @@ -40,23 +42,22 @@ TEST_F(Histogram1DTest, FixedBinDefaultContent) // default bin values std::vector<double> values = hist.getBinValues(); - for(size_t index=0; index < bin_centers.size(); ++index) { + for (size_t index = 0; index < bin_centers.size(); ++index) { EXPECT_EQ(hist.getBinContent(index), 0.0); EXPECT_EQ(values[index], 0.0); } // default bin errors std::vector<double> errors = hist.getBinErrors(); - for(size_t index=0; index < bin_centers.size(); ++index) { + for (size_t index = 0; index < bin_centers.size(); ++index) { EXPECT_EQ(hist.getBinError(index), 0.0); EXPECT_EQ(errors[index], 0.0); } // default bin entries - for(size_t index=0; index < bin_centers.size(); ++index) { + for (size_t index = 0; index < bin_centers.size(); ++index) { EXPECT_EQ(hist.getBinNumberOfEntries(index), 0); } - } TEST_F(Histogram1DTest, FixedBinFill) @@ -76,7 +77,7 @@ TEST_F(Histogram1DTest, FixedBinFill) EXPECT_EQ(hist.getBinError(4), 0.0); std::vector<double> values = {88.0, 0.0, 0.0, 0.0, 99.0}; - for(size_t index=0; index<hist.getTotalNumberOfBins(); ++index) { + for (size_t index = 0; index < hist.getTotalNumberOfBins(); ++index) { EXPECT_EQ(hist.getBinValues()[index], values[index]); EXPECT_EQ(hist.getBinErrors()[index], 0.0); } @@ -109,10 +110,9 @@ TEST_F(Histogram1DTest, FixedBinFill) EXPECT_EQ(3, hist.getBinNumberOfEntries(xbin)); EXPECT_EQ(6.0, hist.getBinContent(xbin)); EXPECT_EQ(2.0, hist.getBinAverage(xbin)); - EXPECT_EQ(2.0/3.0, hist.getBinError(xbin)*hist.getBinError(xbin)); + EXPECT_EQ(2.0 / 3.0, hist.getBinError(xbin) * hist.getBinError(xbin)); } - // -1.0 -0.5 0.5 1.0 2.0 X TEST_F(Histogram1DTest, crop) @@ -121,11 +121,11 @@ TEST_F(Histogram1DTest, crop) std::vector<double> xvalues = {-0.75, 0.0, 0.75, 1.5}; Histogram1D hist(4, xedges); - for(size_t i=0; i<xvalues.size(); ++i) { - hist.fill(xvalues[i], i*10.0); + for (size_t i = 0; i < xvalues.size(); ++i) { + hist.fill(xvalues[i], i * 10.0); } - std::unique_ptr<Histogram1D > crop(hist.crop(-0.49, 0.99)); + std::unique_ptr<Histogram1D> crop(hist.crop(-0.49, 0.99)); EXPECT_EQ(-0.5, crop->getXmin()); EXPECT_EQ(1.0, crop->getXmax()); @@ -134,12 +134,11 @@ TEST_F(Histogram1DTest, crop) EXPECT_EQ(20.0, crop->getBinContent(1)); } - TEST_F(Histogram1DTest, CreateHistogram) { OutputData<double> data; data.addAxis("x-axis", 10, 0.0, 10.0); - for(size_t i=0; i<data.getAllocatedSize(); ++i) { + for (size_t i = 0; i < data.getAllocatedSize(); ++i) { data[i] = double(i); } @@ -148,7 +147,7 @@ TEST_F(Histogram1DTest, CreateHistogram) EXPECT_EQ(data.getAllocatedSize(), hist->getNbinsX()); EXPECT_EQ(data.getAxis(0).getMin(), hist->getXmin()); EXPECT_EQ(data.getAxis(0).getMax(), hist->getXmax()); - for(size_t i=0; i<hist->getTotalNumberOfBins(); ++i) { + for (size_t i = 0; i < hist->getTotalNumberOfBins(); ++i) { EXPECT_EQ(data[i], hist->getBinContent(i)); EXPECT_EQ(data[i], hist->getBinAverage(i)); EXPECT_EQ(1, hist->getBinNumberOfEntries(i)); @@ -160,32 +159,32 @@ TEST_F(Histogram1DTest, CreateOutputData) { Histogram1D hist(10, -5.0, 5.0); - for(size_t i=0; i<hist.getNbinsX(); ++i) { + for (size_t i = 0; i < hist.getNbinsX(); ++i) { hist.fill(hist.getXaxisValue(i), 1.0); hist.fill(hist.getXaxisValue(i), 3.0); } - std::unique_ptr<OutputData<double> > data(hist.createOutputData(IHistogram::DataType::INTEGRAL)); + std::unique_ptr<OutputData<double>> data(hist.createOutputData(IHistogram::DataType::INTEGRAL)); EXPECT_EQ(size_t(1), data->getRank()); EXPECT_EQ(data->getAllocatedSize(), hist.getNbinsX()); EXPECT_EQ(data->getAxis(0).getMin(), hist.getXmin()); EXPECT_EQ(data->getAxis(0).getMax(), hist.getXmax()); - for(size_t i=0; i<data->getAllocatedSize(); ++i) { + for (size_t i = 0; i < data->getAllocatedSize(); ++i) { EXPECT_EQ(4.0, (*data)[i]); } data.reset(hist.createOutputData(IHistogram::DataType::AVERAGE)); - for(size_t i=0; i<data->getAllocatedSize(); ++i) { + for (size_t i = 0; i < data->getAllocatedSize(); ++i) { EXPECT_EQ(2.0, (*data)[i]); } data.reset(hist.createOutputData(IHistogram::DataType::STANDARD_ERROR)); - for(size_t i=0; i<data->getAllocatedSize(); ++i) { + for (size_t i = 0; i < data->getAllocatedSize(); ++i) { EXPECT_EQ(1.0, (*data)[i]); } data.reset(hist.createOutputData(IHistogram::DataType::NENTRIES)); - for(size_t i=0; i<data->getAllocatedSize(); ++i) { + for (size_t i = 0; i < data->getAllocatedSize(); ++i) { EXPECT_EQ(2.0, (*data)[i]); } } @@ -208,22 +207,21 @@ TEST_F(Histogram1DTest, Scale) { Histogram1D hist(10, -5.0, 5.0); - for(size_t i=0; i<hist.getTotalNumberOfBins(); ++i) { - hist.fill(-4.5+i, 1.0); + for (size_t i = 0; i < hist.getTotalNumberOfBins(); ++i) { + hist.fill(-4.5 + i, 1.0); } hist.scale(10.0); - for(size_t i=0; i<hist.getTotalNumberOfBins(); ++i) { + for (size_t i = 0; i < hist.getTotalNumberOfBins(); ++i) { EXPECT_EQ(10.0, hist.getBinContent(i)); } - } TEST_F(Histogram1DTest, Integral) { Histogram1D hist(10, -5.0, 5.0); - for(size_t i=0; i<hist.getTotalNumberOfBins(); ++i) { - hist.fill(-4.5+i, 1.0); + for (size_t i = 0; i < hist.getTotalNumberOfBins(); ++i) { + hist.fill(-4.5 + i, 1.0); } EXPECT_EQ(10.0, hist.integral()); } @@ -231,17 +229,17 @@ TEST_F(Histogram1DTest, Integral) TEST_F(Histogram1DTest, Addition) { Histogram1D hist1(10, -5.0, 5.0); - for(size_t i=0; i<hist1.getTotalNumberOfBins(); ++i) { - hist1.fill(-4.5+i, 1.0); + for (size_t i = 0; i < hist1.getTotalNumberOfBins(); ++i) { + hist1.fill(-4.5 + i, 1.0); } Histogram1D hist2(10, -5.0, 5.0); - for(size_t i=0; i<hist2.getTotalNumberOfBins(); ++i) { - hist2.fill(-4.5+i, 2.0); + for (size_t i = 0; i < hist2.getTotalNumberOfBins(); ++i) { + hist2.fill(-4.5 + i, 2.0); } hist1 += hist2; - for(size_t i=0; i<hist1.getTotalNumberOfBins(); ++i) { + for (size_t i = 0; i < hist1.getTotalNumberOfBins(); ++i) { EXPECT_EQ(3.0, hist1.getBinContent(i)); } } diff --git a/Tests/UnitTests/Core/Axes/Histogram2DTest.h b/Tests/UnitTests/Core/Axes/Histogram2DTest.h index ccfb77fed47..4eb8b7e4ac1 100644 --- a/Tests/UnitTests/Core/Axes/Histogram2DTest.h +++ b/Tests/UnitTests/Core/Axes/Histogram2DTest.h @@ -1,3 +1,5 @@ +#include "google_test.h" +#include "Histogram1D.h" #include "Histogram2D.h" #include <memory> @@ -10,7 +12,6 @@ class Histogram2DTest : public ::testing::Test Histogram2D *hist; }; - // y // 4.0 ----------------------------------- // | | | | | diff --git a/Tests/UnitTests/Core/Axes/KVectorTest.h b/Tests/UnitTests/Core/Axes/KVectorTest.h index d57ccc1b423..412823214e3 100644 --- a/Tests/UnitTests/Core/Axes/KVectorTest.h +++ b/Tests/UnitTests/Core/Axes/KVectorTest.h @@ -1,125 +1,173 @@ -#include "Vectors3D.h" +#include "google_test.h" #include "Transform3D.h" +#include "Vectors3D.h" class KVectorTest : public ::testing::Test { - protected: - KVectorTest() {} - virtual ~KVectorTest() {} +protected: + ~KVectorTest(); }; +KVectorTest::~KVectorTest() = default; + TEST_F(KVectorTest, BasicMethods) { kvector_t v; - EXPECT_EQ( double(0), v.x()); EXPECT_EQ( double(0), v.y()); EXPECT_EQ( double(0), v.z()); - kvector_t v2(1.,2.,3.); - EXPECT_EQ( double(1.), v2.x()); EXPECT_EQ( double(2.), v2.y()); EXPECT_EQ( double(3.), v2.z()); - v2.setX(10.); v2.setY(20.); v2.setZ(30.); - EXPECT_EQ( double(10.), v2.x()); EXPECT_EQ( double(20.), v2.y()); EXPECT_EQ( double(30.), v2.z()); + EXPECT_EQ(double(0), v.x()); + EXPECT_EQ(double(0), v.y()); + EXPECT_EQ(double(0), v.z()); + kvector_t v2(1., 2., 3.); + EXPECT_EQ(double(1.), v2.x()); + EXPECT_EQ(double(2.), v2.y()); + EXPECT_EQ(double(3.), v2.z()); + v2.setX(10.); + v2.setY(20.); + v2.setZ(30.); + EXPECT_EQ(double(10.), v2.x()); + EXPECT_EQ(double(20.), v2.y()); + EXPECT_EQ(double(30.), v2.z()); v2 = {1., 2., 3.}; - EXPECT_EQ( double(1.), v2.x()); EXPECT_EQ( double(2.), v2.y()); EXPECT_EQ( double(3.), v2.z()); + EXPECT_EQ(double(1.), v2.x()); + EXPECT_EQ(double(2.), v2.y()); + EXPECT_EQ(double(3.), v2.z()); - kvector_t v3(1.,2.,3.); - EXPECT_DOUBLE_EQ( v3.mag2(), 1*1+2*2+3*3); - EXPECT_DOUBLE_EQ( v3.mag2(), v3.mag()*v3.mag()); - EXPECT_DOUBLE_EQ( v3.magxy2(), 1*1+2*2); - EXPECT_DOUBLE_EQ( v3.magxy2(), v3.magxy()*v3.magxy()); - EXPECT_DOUBLE_EQ( v3.magxy(), std::sqrt(1*1+2*2) ); - EXPECT_DOUBLE_EQ( v3.mag(), std::sqrt(1*1+2*2+3*3) ); + kvector_t v3(1., 2., 3.); + EXPECT_DOUBLE_EQ(v3.mag2(), 1 * 1 + 2 * 2 + 3 * 3); + EXPECT_DOUBLE_EQ(v3.mag2(), v3.mag() * v3.mag()); + EXPECT_DOUBLE_EQ(v3.magxy2(), 1 * 1 + 2 * 2); + EXPECT_DOUBLE_EQ(v3.magxy2(), v3.magxy() * v3.magxy()); + EXPECT_DOUBLE_EQ(v3.magxy(), std::sqrt(1 * 1 + 2 * 2)); + EXPECT_DOUBLE_EQ(v3.mag(), std::sqrt(1 * 1 + 2 * 2 + 3 * 3)); } - TEST_F(KVectorTest, BasicArithmetics) { // assignment, self assignment, copy constructor kvector_t v1; kvector_t v2(v1); - EXPECT_EQ( double(0), v2.x()); EXPECT_EQ( double(0), v2.y()); EXPECT_EQ( double(0), v2.z()); - v2 = { 1., 2., 3. }; - EXPECT_EQ( double(1), v2.x()); EXPECT_EQ( double(2), v2.y()); EXPECT_EQ( double(3), v2.z()); + EXPECT_EQ(double(0), v2.x()); + EXPECT_EQ(double(0), v2.y()); + EXPECT_EQ(double(0), v2.z()); + v2 = {1., 2., 3.}; + EXPECT_EQ(double(1), v2.x()); + EXPECT_EQ(double(2), v2.y()); + EXPECT_EQ(double(3), v2.z()); kvector_t v3(v2); - EXPECT_EQ( double(1), v3.x()); EXPECT_EQ( double(2), v3.y()); EXPECT_EQ( double(3), v3.z()); + EXPECT_EQ(double(1), v3.x()); + EXPECT_EQ(double(2), v3.y()); + EXPECT_EQ(double(3), v3.z()); kvector_t v4 = v3; - EXPECT_EQ( double(1), v4.x()); EXPECT_EQ( double(2), v4.y()); EXPECT_EQ( double(3), v4.z()); + EXPECT_EQ(double(1), v4.x()); + EXPECT_EQ(double(2), v4.y()); + EXPECT_EQ(double(3), v4.z()); // += kvector_t a(1., 2., 3.); kvector_t b(10., 20., 30.); - a+=b; - EXPECT_EQ( double(11), a.x()); EXPECT_EQ( double(22), a.y()); EXPECT_EQ( double(33), a.z()); - EXPECT_EQ( double(10), b.x()); EXPECT_EQ( double(20), b.y()); EXPECT_EQ( double(30), b.z()); + a += b; + EXPECT_EQ(double(11), a.x()); + EXPECT_EQ(double(22), a.y()); + EXPECT_EQ(double(33), a.z()); + EXPECT_EQ(double(10), b.x()); + EXPECT_EQ(double(20), b.y()); + EXPECT_EQ(double(30), b.z()); a = kvector_t(1., 2., 3.); - a+=a; - EXPECT_EQ( double(2.), a.x()); EXPECT_EQ( double(4.), a.y()); EXPECT_EQ( double(6.), a.z()); + a += a; + EXPECT_EQ(double(2.), a.x()); + EXPECT_EQ(double(4.), a.y()); + EXPECT_EQ(double(6.), a.z()); // -= a = kvector_t(1., 2., 3.); - a-=a; - EXPECT_EQ( double(0.), a.x()); EXPECT_EQ( double(0.), a.y()); EXPECT_EQ( double(0.), a.z()); + a -= a; + EXPECT_EQ(double(0.), a.x()); + EXPECT_EQ(double(0.), a.y()); + EXPECT_EQ(double(0.), a.z()); b = kvector_t(1., 2., 3.); - a-=b; - EXPECT_EQ( double(-1.), a.x()); EXPECT_EQ( double(-2.), a.y()); EXPECT_EQ( double(-3.), a.z()); + a -= b; + EXPECT_EQ(double(-1.), a.x()); + EXPECT_EQ(double(-2.), a.y()); + EXPECT_EQ(double(-3.), a.z()); // *= and /= with scalar a *= 10.0; - EXPECT_EQ( double(-10.), a.x()); EXPECT_EQ( double(-20.), a.y()); EXPECT_EQ( double(-30.), a.z()); + EXPECT_EQ(double(-10.), a.x()); + EXPECT_EQ(double(-20.), a.y()); + EXPECT_EQ(double(-30.), a.z()); a /= 10.; - EXPECT_EQ( double(-1.), a.x()); EXPECT_EQ( double(-2.), a.y()); EXPECT_EQ( double(-3.), a.z()); + EXPECT_EQ(double(-1.), a.x()); + EXPECT_EQ(double(-2.), a.y()); + EXPECT_EQ(double(-3.), a.z()); // unary minus a = kvector_t(1., 2., 3.); b = -a; - EXPECT_EQ( double(1.), a.x()); EXPECT_EQ( double(2.), a.y()); EXPECT_EQ( double(3.), a.z() ); - EXPECT_EQ( double(-1.), b.x()); EXPECT_EQ( double(-2.), b.y()); EXPECT_EQ( double(-3.), b.z() ); + EXPECT_EQ(double(1.), a.x()); + EXPECT_EQ(double(2.), a.y()); + EXPECT_EQ(double(3.), a.z()); + EXPECT_EQ(double(-1.), b.x()); + EXPECT_EQ(double(-2.), b.y()); + EXPECT_EQ(double(-3.), b.z()); // addition of two vector a = kvector_t(1., 2., 3.); b = kvector_t(10., 20., 30.); - kvector_t c = a + b; - EXPECT_EQ( double(1.), a.x()); EXPECT_EQ( double(2.), a.y()); EXPECT_EQ( double(3.), a.z() ); - EXPECT_EQ( double(10.), b.x()); EXPECT_EQ( double(20.), b.y()); EXPECT_EQ( double(30.), b.z() ); - EXPECT_EQ( double(11.), c.x()); EXPECT_EQ( double(22.), c.y()); EXPECT_EQ( double(33.), c.z() ); + kvector_t c = a + b; + EXPECT_EQ(double(1.), a.x()); + EXPECT_EQ(double(2.), a.y()); + EXPECT_EQ(double(3.), a.z()); + EXPECT_EQ(double(10.), b.x()); + EXPECT_EQ(double(20.), b.y()); + EXPECT_EQ(double(30.), b.z()); + EXPECT_EQ(double(11.), c.x()); + EXPECT_EQ(double(22.), c.y()); + EXPECT_EQ(double(33.), c.z()); // substraction of two vectors c = b - a; - EXPECT_EQ( double(9.), c.x()); EXPECT_EQ( double(18.), c.y()); EXPECT_EQ( double(27.), c.z() ); + EXPECT_EQ(double(9.), c.x()); + EXPECT_EQ(double(18.), c.y()); + EXPECT_EQ(double(27.), c.z()); // multiplication by a scalar - a = { 1., 2., 3. }; - c = 2*a*2; - EXPECT_EQ( double(1.), a.x()); EXPECT_EQ( double(2.), a.y()); EXPECT_EQ( double(3.), a.z() ); - EXPECT_EQ( double(4.), c.x()); EXPECT_EQ( double(8.), c.y()); EXPECT_EQ( double(12.), c.z() ); + a = {1., 2., 3.}; + c = 2 * a * 2; + EXPECT_EQ(double(1.), a.x()); + EXPECT_EQ(double(2.), a.y()); + EXPECT_EQ(double(3.), a.z()); + EXPECT_EQ(double(4.), c.x()); + EXPECT_EQ(double(8.), c.y()); + EXPECT_EQ(double(12.), c.z()); // scalar product of two vectors - a = { 1., 2., 3. }; - b = { 10., 10., 10. }; - EXPECT_EQ( double(60), a.dot(b) ); + a = {1., 2., 3.}; + b = {10., 10., 10.}; + EXPECT_EQ(double(60), a.dot(b)); // crossproduct c = a.cross(b); - EXPECT_EQ(c.x(), a.y()*b.z() - a.z()*b.y()); - EXPECT_EQ(c.y(), a.z()*b.x() - a.x()*b.z()); - EXPECT_EQ(c.z(), a.x()*b.y() - a.y()*b.x()); + EXPECT_EQ(c.x(), a.y() * b.z() - a.z() * b.y()); + EXPECT_EQ(c.y(), a.z() * b.x() - a.x() * b.z()); + EXPECT_EQ(c.z(), a.x() * b.y() - a.y() * b.x()); // equality - a = { 1.,2.,3.}; - EXPECT_TRUE( a == kvector_t(1., 2., 3.) ); - EXPECT_TRUE( a != kvector_t(1., 1., 3.) ); + a = {1., 2., 3.}; + EXPECT_TRUE(a == kvector_t(1., 2., 3.)); + EXPECT_TRUE(a != kvector_t(1., 1., 3.)); } - TEST_F(KVectorTest, BasicTransformation) { - const double epsilon=1e-12; + const double epsilon = 1e-12; kvector_t a, v; // rotation via transformation - a = kvector_t(std::sqrt(3.)/2., 2., 0.5); - Transform3D m2 = Transform3D::createRotateY(M_PI/6.); + a = kvector_t(std::sqrt(3.) / 2., 2., 0.5); + Transform3D m2 = Transform3D::createRotateY(M_PI / 6.); v = m2.transformed(a); - ASSERT_NEAR( v.x(), 1.0, epsilon ); - EXPECT_DOUBLE_EQ( v.y(), 2.0 ); - ASSERT_NEAR( v.z(), 0.0, epsilon ); + ASSERT_NEAR(v.x(), 1.0, epsilon); + EXPECT_DOUBLE_EQ(v.y(), 2.0); + ASSERT_NEAR(v.z(), 0.0, epsilon); - a = kvector_t(0.5, std::sqrt(3.)/2., 2.); - Transform3D m3 = Transform3D::createRotateZ(M_PI/6.); + a = kvector_t(0.5, std::sqrt(3.) / 2., 2.); + Transform3D m3 = Transform3D::createRotateZ(M_PI / 6.); v = m3.transformed(a); - ASSERT_NEAR( v.x(), 0.0, epsilon ); - ASSERT_NEAR( v.y(), 1.0, epsilon ); - EXPECT_DOUBLE_EQ( v.z(), 2.0 ); + ASSERT_NEAR(v.x(), 0.0, epsilon); + ASSERT_NEAR(v.y(), 1.0, epsilon); + EXPECT_DOUBLE_EQ(v.z(), 2.0); Transform3D m4 = m3.getInverse(); v = m4.transformed(v); - ASSERT_NEAR( v.x(), a.x(), epsilon ); - ASSERT_NEAR( v.y(), a.y(), epsilon ); - ASSERT_NEAR( v.z(), a.z(), epsilon ); + ASSERT_NEAR(v.x(), a.x(), epsilon); + ASSERT_NEAR(v.y(), a.y(), epsilon); + ASSERT_NEAR(v.z(), a.z(), epsilon); } diff --git a/Tests/UnitTests/Core/Axes/VariableBinAxisTest.h b/Tests/UnitTests/Core/Axes/VariableBinAxisTest.h index 7959c591451..1ccfaa985e4 100644 --- a/Tests/UnitTests/Core/Axes/VariableBinAxisTest.h +++ b/Tests/UnitTests/Core/Axes/VariableBinAxisTest.h @@ -1,17 +1,20 @@ -#include "VariableBinAxis.h" +#include "google_test.h" #include "DataFormatUtils.h" +#include "Exceptions.h" +#include "VariableBinAxis.h" -class VariableBinAxisTest: public ::testing::Test +class VariableBinAxisTest : public ::testing::Test { protected: - VariableBinAxisTest() {} - + ~VariableBinAxisTest(); }; +VariableBinAxisTest::~VariableBinAxisTest() = default; + TEST_F(VariableBinAxisTest, VectorOfUnitLength) { static const double arr[] = {0., 1.}; - std::vector<double> values (arr, arr + sizeof(arr) / sizeof(arr[0]) ); + std::vector<double> values(arr, arr + sizeof(arr) / sizeof(arr[0])); VariableBinAxis axis("name", 1, values); EXPECT_EQ("name", axis.getName()); EXPECT_EQ(size_t(1), axis.size()); @@ -20,25 +23,22 @@ TEST_F(VariableBinAxisTest, VectorOfUnitLength) EXPECT_EQ(0.5, axis[0]); } - TEST_F(VariableBinAxisTest, ValidityOfCOnstructor) { std::vector<double> values; - ASSERT_THROW( VariableBinAxis("name",1,values), Exceptions::LogicErrorException); + ASSERT_THROW(VariableBinAxis("name", 1, values), Exceptions::LogicErrorException); values.resize(5); - ASSERT_THROW( VariableBinAxis("name",5,values), Exceptions::LogicErrorException); + ASSERT_THROW(VariableBinAxis("name", 5, values), Exceptions::LogicErrorException); static const double arr1[] = {-1.5, -1.5, 0.5, 1.5}; - std::vector<double> v1 (arr1, arr1 + sizeof(arr1) / sizeof(arr1[0]) ); - ASSERT_THROW( VariableBinAxis("name", 3, v1), Exceptions::LogicErrorException); + std::vector<double> v1(arr1, arr1 + sizeof(arr1) / sizeof(arr1[0])); + ASSERT_THROW(VariableBinAxis("name", 3, v1), Exceptions::LogicErrorException); static const double arr2[] = {1.5, -0.5, 0.5, -1.5}; - std::vector<double> v2 (arr2, arr2 + sizeof(arr2) / sizeof(arr2[0]) ); - ASSERT_THROW( VariableBinAxis("name", 3, v2), Exceptions::LogicErrorException); - + std::vector<double> v2(arr2, arr2 + sizeof(arr2) / sizeof(arr2[0])); + ASSERT_THROW(VariableBinAxis("name", 3, v2), Exceptions::LogicErrorException); } - TEST_F(VariableBinAxisTest, IndexedAccessor) { std::vector<double> values; @@ -46,10 +46,9 @@ TEST_F(VariableBinAxisTest, IndexedAccessor) double start(0.0); double end(10.0); size_t nbins(100); - double step = (end - start)/(nbins); - for (size_t i=0; i<nbins+1; ++i) - { - values.push_back(start + step*(int)i); + double step = (end - start) / (nbins); + for (size_t i = 0; i < nbins + 1; ++i) { + values.push_back(start + step * (int)i); } VariableBinAxis a1("name", nbins, values); @@ -63,31 +62,30 @@ TEST_F(VariableBinAxisTest, IndexedAccessor) EXPECT_DOUBLE_EQ(9.95, a1[99]); static const double arr[] = {-1.5, -0.5, 0.5, 1.5}; - std::vector<double> v2 (arr, arr + sizeof(arr) / sizeof(arr[0]) ); + std::vector<double> v2(arr, arr + sizeof(arr) / sizeof(arr[0])); VariableBinAxis a2("name", 3, v2); EXPECT_DOUBLE_EQ(-1.0, a2[0]); EXPECT_DOUBLE_EQ(0.0, a2[1]); EXPECT_DOUBLE_EQ(1.0, a2[2]); - ASSERT_THROW( a2[3], Exceptions::OutOfBoundsException); + ASSERT_THROW(a2[3], Exceptions::OutOfBoundsException); } - TEST_F(VariableBinAxisTest, FindClosestIndex) { static const double arr1[] = {0.0, 0.5, 1.0}; - std::vector<double> values1 (arr1, arr1 + sizeof(arr1) / sizeof(arr1[0]) ); + std::vector<double> values1(arr1, arr1 + sizeof(arr1) / sizeof(arr1[0])); VariableBinAxis v1("name", 2, values1); - EXPECT_EQ( size_t(2), v1.size()); - EXPECT_EQ( size_t(0), v1.findClosestIndex(0.0)); - EXPECT_EQ( size_t(0), v1.findClosestIndex(0.25)); - EXPECT_EQ( size_t(1), v1.findClosestIndex(0.5)); - EXPECT_EQ( size_t(1), v1.findClosestIndex(0.6)); -// ASSERT_THROW( v1.findClosestIndex(1.0), Exceptions::OutOfBoundsException); - EXPECT_EQ( size_t(1), v1.findClosestIndex(1.0)); + EXPECT_EQ(size_t(2), v1.size()); + EXPECT_EQ(size_t(0), v1.findClosestIndex(0.0)); + EXPECT_EQ(size_t(0), v1.findClosestIndex(0.25)); + EXPECT_EQ(size_t(1), v1.findClosestIndex(0.5)); + EXPECT_EQ(size_t(1), v1.findClosestIndex(0.6)); + // ASSERT_THROW( v1.findClosestIndex(1.0), Exceptions::OutOfBoundsException); + EXPECT_EQ(size_t(1), v1.findClosestIndex(1.0)); static const double arr2[] = {-1.5, -0.5, 0.5, 1.5}; - std::vector<double> values2 (arr2, arr2 + sizeof(arr2) / sizeof(arr2[0]) ); + std::vector<double> values2(arr2, arr2 + sizeof(arr2) / sizeof(arr2[0])); VariableBinAxis v2("name", 3, values2); EXPECT_EQ(size_t(0), v2.findClosestIndex(-1.5)); EXPECT_EQ(size_t(0), v2.findClosestIndex(-1.0)); @@ -95,11 +93,11 @@ TEST_F(VariableBinAxisTest, FindClosestIndex) EXPECT_EQ(size_t(1), v2.findClosestIndex(0.0)); EXPECT_EQ(size_t(2), v2.findClosestIndex(0.5)); EXPECT_EQ(size_t(2), v2.findClosestIndex(1.499)); -// ASSERT_THROW( v2.findClosestIndex(1.5), Exceptions::OutOfBoundsException); + // ASSERT_THROW( v2.findClosestIndex(1.5), Exceptions::OutOfBoundsException); EXPECT_EQ(size_t(2), v2.findClosestIndex(1.5)); static const double arr3[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values3 (arr3, arr3 + sizeof(arr3) / sizeof(arr2[0]) ); + std::vector<double> values3(arr3, arr3 + sizeof(arr3) / sizeof(arr2[0])); VariableBinAxis v3("name", 4, values3); EXPECT_EQ(size_t(0), v3.findClosestIndex(-1.0)); EXPECT_EQ(size_t(0), v3.findClosestIndex(-0.75)); @@ -113,83 +111,79 @@ TEST_F(VariableBinAxisTest, FindClosestIndex) EXPECT_EQ(size_t(3), v3.findClosestIndex(1.9999)); } - TEST_F(VariableBinAxisTest, CheckBin) { static const double arr3[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values3 (arr3, arr3 + sizeof(arr3) / sizeof(arr3[0]) ); + std::vector<double> values3(arr3, arr3 + sizeof(arr3) / sizeof(arr3[0])); VariableBinAxis axis("name", 4, values3); - EXPECT_DOUBLE_EQ( -1.0, axis.getBin(0).m_lower); - EXPECT_DOUBLE_EQ( -0.75, axis.getBin(0).getMidPoint()); - EXPECT_DOUBLE_EQ( -0.5, axis.getBin(0).m_upper); - EXPECT_DOUBLE_EQ( 0.5, axis.getBin(0).getBinSize()); - - EXPECT_DOUBLE_EQ( -0.5, axis.getBin(1).m_lower); - EXPECT_DOUBLE_EQ( 0.0, axis.getBin(1).getMidPoint()); - EXPECT_DOUBLE_EQ( 0.5, axis.getBin(1).m_upper); - EXPECT_DOUBLE_EQ( 1.0, axis.getBin(1).getBinSize()); - - EXPECT_DOUBLE_EQ( 0.5, axis.getBin(2).m_lower); - EXPECT_DOUBLE_EQ( 0.75, axis.getBin(2).getMidPoint()); - EXPECT_DOUBLE_EQ( 1.0, axis.getBin(2).m_upper); - EXPECT_DOUBLE_EQ( 0.5, axis.getBin(2).getBinSize()); - - EXPECT_DOUBLE_EQ( 1.0, axis.getBin(3).m_lower); - EXPECT_DOUBLE_EQ( 1.5, axis.getBin(3).getMidPoint()); - EXPECT_DOUBLE_EQ( 2.0, axis.getBin(3).m_upper); - EXPECT_DOUBLE_EQ( 1.0, axis.getBin(3).getBinSize()); + EXPECT_DOUBLE_EQ(-1.0, axis.getBin(0).m_lower); + EXPECT_DOUBLE_EQ(-0.75, axis.getBin(0).getMidPoint()); + EXPECT_DOUBLE_EQ(-0.5, axis.getBin(0).m_upper); + EXPECT_DOUBLE_EQ(0.5, axis.getBin(0).getBinSize()); + + EXPECT_DOUBLE_EQ(-0.5, axis.getBin(1).m_lower); + EXPECT_DOUBLE_EQ(0.0, axis.getBin(1).getMidPoint()); + EXPECT_DOUBLE_EQ(0.5, axis.getBin(1).m_upper); + EXPECT_DOUBLE_EQ(1.0, axis.getBin(1).getBinSize()); + + EXPECT_DOUBLE_EQ(0.5, axis.getBin(2).m_lower); + EXPECT_DOUBLE_EQ(0.75, axis.getBin(2).getMidPoint()); + EXPECT_DOUBLE_EQ(1.0, axis.getBin(2).m_upper); + EXPECT_DOUBLE_EQ(0.5, axis.getBin(2).getBinSize()); + + EXPECT_DOUBLE_EQ(1.0, axis.getBin(3).m_lower); + EXPECT_DOUBLE_EQ(1.5, axis.getBin(3).getMidPoint()); + EXPECT_DOUBLE_EQ(2.0, axis.getBin(3).m_upper); + EXPECT_DOUBLE_EQ(1.0, axis.getBin(3).getBinSize()); } - TEST_F(VariableBinAxisTest, CheckEquality) { static const double arr3[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values3 (arr3, arr3 + sizeof(arr3) / sizeof(arr3[0]) ); + std::vector<double> values3(arr3, arr3 + sizeof(arr3) / sizeof(arr3[0])); VariableBinAxis a1("name", 4, values3); VariableBinAxis a2("name", 4, values3); VariableBinAxis a3("nameX", 4, values3); - EXPECT_TRUE( a1 == a2); - EXPECT_FALSE( a1 == a3); + EXPECT_TRUE(a1 == a2); + EXPECT_FALSE(a1 == a3); static const double arr4[] = {-1.0, -0.5, 0.5, 1.1, 2.0}; - std::vector<double> values4 (arr4, arr4 + sizeof(arr4) / sizeof(arr4[0]) ); + std::vector<double> values4(arr4, arr4 + sizeof(arr4) / sizeof(arr4[0])); VariableBinAxis a4("nameX", 4, values4); - EXPECT_FALSE( a1 == a4); + EXPECT_FALSE(a1 == a4); } - TEST_F(VariableBinAxisTest, CheckClone) { static const double arr3[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values3 (arr3, arr3 + sizeof(arr3) / sizeof(arr3[0]) ); + std::vector<double> values3(arr3, arr3 + sizeof(arr3) / sizeof(arr3[0])); VariableBinAxis a1("name", 4, values3); - VariableBinAxis *clone=a1.clone(); + VariableBinAxis* clone = a1.clone(); EXPECT_TRUE(a1 == *clone); delete clone; } - TEST_F(VariableBinAxisTest, IOStream) { static const double arr[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values (arr, arr + sizeof(arr) / sizeof(arr[0]) ); + std::vector<double> values(arr, arr + sizeof(arr) / sizeof(arr[0])); VariableBinAxis axis("name", 4, values); std::ostringstream oss; oss << axis; - VariableBinAxis *result = dynamic_cast<VariableBinAxis *>(DataFormatUtils::createVariableBinAxis(oss.str())); + VariableBinAxis* result + = dynamic_cast<VariableBinAxis*>(DataFormatUtils::createVariableBinAxis(oss.str())); EXPECT_TRUE(axis == *result); delete result; } - TEST_F(VariableBinAxisTest, BinCenters) { static const double arr[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values (arr, arr + sizeof(arr) / sizeof(arr[0]) ); + std::vector<double> values(arr, arr + sizeof(arr) / sizeof(arr[0])); VariableBinAxis axis("name", 4, values); std::vector<double> centers = axis.getBinCenters(); @@ -200,11 +194,10 @@ TEST_F(VariableBinAxisTest, BinCenters) EXPECT_DOUBLE_EQ(1.5, centers[3]); } - TEST_F(VariableBinAxisTest, BinBoundaries) { static const double arr[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values (arr, arr + sizeof(arr) / sizeof(arr[0]) ); + std::vector<double> values(arr, arr + sizeof(arr) / sizeof(arr[0])); VariableBinAxis axis("name", 4, values); std::vector<double> boundaries = axis.getBinBoundaries(); @@ -219,14 +212,14 @@ TEST_F(VariableBinAxisTest, BinBoundaries) TEST_F(VariableBinAxisTest, ClippedAxis) { static const double arr[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values (arr, arr + sizeof(arr) / sizeof(arr[0]) ); + std::vector<double> values(arr, arr + sizeof(arr) / sizeof(arr[0])); VariableBinAxis axis("name", 4, values); - VariableBinAxis *clip1 = axis.createClippedAxis(-1.0, 2.0); + VariableBinAxis* clip1 = axis.createClippedAxis(-1.0, 2.0); EXPECT_TRUE(axis == *clip1); delete clip1; - VariableBinAxis *clip2 = axis.createClippedAxis(-0.5, 1.5); + VariableBinAxis* clip2 = axis.createClippedAxis(-0.5, 1.5); EXPECT_EQ(clip2->size(), size_t(3)); EXPECT_EQ(clip2->getMin(), -0.5); EXPECT_EQ(clip2->getMax(), 2.0); @@ -237,7 +230,7 @@ TEST_F(VariableBinAxisTest, ClippedAxis) EXPECT_TRUE(axis != *clip2); delete clip2; - VariableBinAxis *clip3 = axis.createClippedAxis(-0.5, 0.99); + VariableBinAxis* clip3 = axis.createClippedAxis(-0.5, 0.99); EXPECT_EQ(clip3->size(), size_t(2)); EXPECT_EQ(clip3->getMin(), -0.5); EXPECT_EQ(clip3->getMax(), 1.0); @@ -246,6 +239,4 @@ TEST_F(VariableBinAxisTest, ClippedAxis) EXPECT_EQ(boundaries[1], 0.5); EXPECT_EQ(boundaries[2], 1.0); delete clip3; - - } diff --git a/Tests/UnitTests/Core/DataStructure/IntensityDataFunctionsTest.h b/Tests/UnitTests/Core/DataStructure/IntensityDataFunctionsTest.h index 01b6e972eb4..0f24b179fcd 100644 --- a/Tests/UnitTests/Core/DataStructure/IntensityDataFunctionsTest.h +++ b/Tests/UnitTests/Core/DataStructure/IntensityDataFunctionsTest.h @@ -1,144 +1,64 @@ +#include "google_test.h" #include "IntensityDataFunctions.h" #include "VariableBinAxis.h" class IntensityDataFunctionsTest : public ::testing::Test { - protected: - IntensityDataFunctionsTest(){} - virtual ~IntensityDataFunctionsTest(){} - +protected: + ~IntensityDataFunctionsTest(); }; - +IntensityDataFunctionsTest::~IntensityDataFunctionsTest() = default; TEST_F(IntensityDataFunctionsTest, ClipDataSetFixed) { OutputData<double> data; - FixedBinAxis axis0("axis0",10, -5.0, 5.0); + FixedBinAxis axis0("axis0", 10, -5.0, 5.0); data.addAxis(axis0); - FixedBinAxis axis1("axis1",3, 0.0, 3.0); + FixedBinAxis axis1("axis1", 3, 0.0, 3.0); data.addAxis(axis1); - for(size_t i=0; i<data.getAllocatedSize(); ++i) { + for (size_t i = 0; i < data.getAllocatedSize(); ++i) { data[i] = static_cast<double>(i); } - OutputData<double> *clip = IntensityDataFunctions::createClippedDataSet(data, -5.0, 0.0, -1.5, 1.5); + OutputData<double>* clip + = IntensityDataFunctions::createClippedDataSet(data, -5.0, 0.0, -1.5, 1.5); std::vector<double> vref = {0.0, 1.0, 3.0, 4.0, 6.0, 7.0, 9.0, 10.0}; EXPECT_EQ(clip->getAllocatedSize(), size_t(8)); int index(0); - for(size_t i=0; i<clip->getAllocatedSize(); ++i) { + for (size_t i = 0; i < clip->getAllocatedSize(); ++i) { EXPECT_EQ(vref[index++], (*clip)[i]); } delete clip; } - TEST_F(IntensityDataFunctionsTest, ClipDataSetVariable) { static const double arr[] = {-1.0, -0.5, 0.5, 1.0, 2.0}; - std::vector<double> values (arr, arr + sizeof(arr) / sizeof(arr[0]) ); + std::vector<double> values(arr, arr + sizeof(arr) / sizeof(arr[0])); OutputData<double> data; - VariableBinAxis axis0("axis0",4, values); + VariableBinAxis axis0("axis0", 4, values); data.addAxis(axis0); - VariableBinAxis axis1("axis1",4, values); + VariableBinAxis axis1("axis1", 4, values); data.addAxis(axis1); - for(size_t i=0; i<data.getAllocatedSize(); ++i) { + for (size_t i = 0; i < data.getAllocatedSize(); ++i) { data[i] = static_cast<double>(i); } - OutputData<double> *clip = IntensityDataFunctions::createClippedDataSet(data, -0.5, 0.5, 0.99, 2.0); + OutputData<double>* clip + = IntensityDataFunctions::createClippedDataSet(data, -0.5, 0.5, 0.99, 2.0); std::vector<double> vref = {6.0, 7.0, 10.0, 11.0}; EXPECT_EQ(clip->getAllocatedSize(), size_t(4)); - int index(0); - for(size_t i=0; i<clip->getAllocatedSize(); ++i) { + size_t index(0); + for (size_t i = 0; i < clip->getAllocatedSize(); ++i) { EXPECT_EQ(vref[index++], (*clip)[i]); } delete clip; - - } - -//------------------------------------------------- 2.5 -// 2 || 2 | 5 | 8 | 11 | 14 | 17 | 20 | 23 | -//------------------------------------------------ -// 1 || 1 | 4 | 7 | 10 | 13 | 16 | 19 | 22 | -//------------------------------------------------ -// 0 || 0 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | -//================================================== -0.5 -// || 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | -// -4.5 3.5 - -//TEST_F(IntensityDataFunctionsTest, AddRectangularMask) -//{ -// OutputData<double > data; -// data.addAxis("x", 8, -4.5, 3.5); -// data.addAxis("y", 3, -0.5, 2.5); -// data.setAllTo(0.0); -// IntensityDataFunctions::addRectangularMask(data, -3.0, -0.5, 1.0, 1.49); -// IntensityDataFunctions::addRectangularMask(data, 1.5, 0.5, 3.5, 2.5); - -// for(size_t i=0; i<data.getAllocatedSize(); ++i) { -// data[i] = i; -// } - -// int index(0); - -// std::vector<double> xref = {-4.0, -4.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0); -// std::vector<double> yref = {0.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 0.0, 0.0); -// std::vector<double> vref = {0, 1, 2, 5, 8, 11, 14, 17, 18, 21); -// for(OutputData<double>::iterator it = data.begin(); it!=data.end(); ++it) { -// double x = data.getAxisValue(it.getIndex(), "x"); -// double y = data.getAxisValue(it.getIndex(), "y"); -// EXPECT_EQ(x, xref[index]); -// EXPECT_EQ(y, yref[index]); -// EXPECT_EQ(*it, vref[index]); -// ++index; -// } -// data.removeAllMasks(); -// index=0; -// for(OutputData<double>::iterator it = data.begin(); it!=data.end(); ++it) { -// EXPECT_EQ( int(index++), int(it.getIndex()) ); -// } -//} - - -//TEST_F(IntensityDataFunctionsTest, AddRectangularMask2) -//{ -// OutputData<double > data; -// data.addAxis("x", 8, -4.5, 3.5); -// data.addAxis("y", 3, -0.5, 2.5); -// data.setAllTo(0.0); -// IntensityDataFunctions::addRectangularMask(data, -3.0, -0.5, 1.0, 1.49, false); -// IntensityDataFunctions::addRectangularMask(data, 1.5, 0.5, 3.5, 2.5, false); - -// for(size_t i=0; i<data.getAllocatedSize(); ++i) { -// data[i] = i; -// } - -// int index(0); - -// std::vector<double> xref = {-4.0, -4.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0); -// std::vector<double> yref = {0.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 0.0, 0.0); -// std::vector<double> vref = {0, 1, 2, 5, 8, 11, 14, 17, 18, 21); -// for(OutputData<double>::iterator it = data.begin(); it!=data.end(); ++it) { -// double x = data.getValueOfAxis("x", it.getIndex()); -// double y = data.getValueOfAxis("y", it.getIndex()); -// EXPECT_EQ(x, xref[index]); -// EXPECT_EQ(y, yref[index]); -// EXPECT_EQ(*it, vref[index]); -// ++index; -// } -// data.removeAllMasks(); -// index=0; -// for(OutputData<double>::iterator it = data.begin(); it!=data.end(); ++it) { -// EXPECT_EQ( int(index++), int(it.getIndex()) ); -// } -//} - TEST_F(IntensityDataFunctionsTest, createRearrangedDataSet) { OutputData<double> input_data; @@ -215,7 +135,6 @@ TEST_F(IntensityDataFunctionsTest, coordinateToFromBinf) EXPECT_EQ(3.5, IntensityDataFunctions::coordinateFromBinf(8.5, axis)); } - //! Transformation of coordinates from one OutputData to another using convertion from axes //! coordinates to bin-fraction-coordinates and then to another axes coordinates. @@ -233,12 +152,12 @@ TEST_F(IntensityDataFunctionsTest, outputDataCoordinatesToFromBinf) IntensityDataFunctions::coordinateToBinf(x, y, data1); IntensityDataFunctions::coordinateFromBinf(x, y, data2); EXPECT_DOUBLE_EQ(x, -5.0); - EXPECT_DOUBLE_EQ(y, -5.0); + EXPECT_DOUBLE_EQ(y, -5.0); - x = 3.1; y = 5.1; + x = 3.1; + y = 5.1; IntensityDataFunctions::coordinateToBinf(x, y, data1); IntensityDataFunctions::coordinateFromBinf(x, y, data2); - EXPECT_DOUBLE_EQ(x, 71.0); - EXPECT_DOUBLE_EQ(y, 21.0); - + EXPECT_DOUBLE_EQ(x, 71.0); + EXPECT_DOUBLE_EQ(y, 21.0); } diff --git a/Tests/UnitTests/Core/DataStructure/LLDataTest.h b/Tests/UnitTests/Core/DataStructure/LLDataTest.h index dd7bd217c51..defeed3680d 100644 --- a/Tests/UnitTests/Core/DataStructure/LLDataTest.h +++ b/Tests/UnitTests/Core/DataStructure/LLDataTest.h @@ -1,56 +1,51 @@ +#include "google_test.h" +#include "Complex.h" #include "LLData.h" #include <algorithm> -#include "Complex.h" - class LLDataTest : public ::testing::Test { - protected: +protected: LLDataTest(); - virtual ~LLDataTest(); - + ~LLDataTest(); - LLData<int> *int_data_0d; - LLData<float> *fl_data_1d; - LLData<double> *db_data_3d; + LLData<int>* int_data_0d; + LLData<float>* fl_data_1d; + LLData<double>* db_data_3d; - LLData<Eigen::Matrix2d> *matrix_data_2d; + LLData<Eigen::Matrix2d>* matrix_data_2d; }; LLDataTest::LLDataTest() { - int *dim0 = new int[0]; + int* dim0 = new int[0]; - int *dim1 = new int[1]; + int* dim1 = new int[1]; dim1[0] = 10; - int *dim3 = new int[3]; + int* dim3 = new int[3]; dim3[0] = 10; dim3[1] = 15; dim3[2] = 20; - int *dim2 = new int[2]; + int* dim2 = new int[2]; dim2[0] = 20; dim2[1] = 30; int_data_0d = new LLData<int>(0u, dim0); - fl_data_1d = new LLData<float>(1u, dim1); - db_data_3d = new LLData<double>(3u, dim3); + fl_data_1d = new LLData<float>(1u, dim1); + db_data_3d = new LLData<double>(3u, dim3); matrix_data_2d = new LLData<Eigen::Matrix2d>(2u, dim2); - } -LLDataTest::~LLDataTest() -{ -} +LLDataTest::~LLDataTest() = default; TEST_F(LLDataTest, TotalSize) { EXPECT_EQ(1u, int_data_0d->getTotalSize()); EXPECT_EQ(10u, fl_data_1d->getTotalSize()); EXPECT_EQ(3000u, db_data_3d->getTotalSize()); - EXPECT_EQ(600u, matrix_data_2d->getTotalSize()); } @@ -62,12 +57,10 @@ TEST_F(LLDataTest, GetRank) EXPECT_EQ(2u, matrix_data_2d->getRank()); } - - TEST_F(LLDataTest, SetAll) { db_data_3d->setAll(1.0); - EXPECT_DOUBLE_EQ( (*db_data_3d)[0], 1.0); + EXPECT_DOUBLE_EQ((*db_data_3d)[0], 1.0); matrix_data_2d->setAll(Eigen::Matrix2d::Identity()); EXPECT_EQ((*matrix_data_2d)[0], Eigen::Matrix2d::Identity()); @@ -77,54 +70,55 @@ TEST_F(LLDataTest, ScaleAll) { db_data_3d->setAll(2.0); db_data_3d->scaleAll(2.5); - EXPECT_DOUBLE_EQ( (*db_data_3d)[0], 5.0); + EXPECT_DOUBLE_EQ((*db_data_3d)[0], 5.0); matrix_data_2d->setAll(Eigen::Matrix2d::Identity()); matrix_data_2d->scaleAll(3 * Eigen::Matrix2d::Identity()); - EXPECT_EQ((*matrix_data_2d)[0], 3 * Eigen::Matrix2d::Identity()*Eigen::Matrix2d::Identity()); + EXPECT_EQ((*matrix_data_2d)[0], 3 * Eigen::Matrix2d::Identity() * Eigen::Matrix2d::Identity()); } TEST_F(LLDataTest, TotalSum) { fl_data_1d->setAll(2.0); - EXPECT_FLOAT_EQ( fl_data_1d->getTotalSum(), 20.0); + EXPECT_FLOAT_EQ(fl_data_1d->getTotalSum(), 20.0); db_data_3d->setAll(0.5); - EXPECT_DOUBLE_EQ( db_data_3d->getTotalSum(), 1500.0); + EXPECT_DOUBLE_EQ(db_data_3d->getTotalSum(), 1500.0); matrix_data_2d->setAll(Eigen::Matrix2d::Identity()); EXPECT_EQ(600 * Eigen::Matrix2d::Identity(), matrix_data_2d->getTotalSum()); } -TEST_F(LLDataTest, GetDimensions) { - EXPECT_EQ( int_data_0d->getDimensions(), (int*)0); - EXPECT_EQ( fl_data_1d->getDimensions()[0], 10); - EXPECT_EQ( db_data_3d->getDimensions()[1], 15); - EXPECT_EQ( matrix_data_2d->getDimensions()[1], 30); +TEST_F(LLDataTest, GetDimensions) +{ + EXPECT_EQ(int_data_0d->getDimensions(), (int*)0); + EXPECT_EQ(fl_data_1d->getDimensions()[0], 10); + EXPECT_EQ(db_data_3d->getDimensions()[1], 15); + EXPECT_EQ(matrix_data_2d->getDimensions()[1], 30); } -TEST_F(LLDataTest, DataCopyingConstructor) { - LLData<int> *other_int_data_0d = new LLData<int>(*int_data_0d); +TEST_F(LLDataTest, DataCopyingConstructor) +{ + LLData<int>* other_int_data_0d = new LLData<int>(*int_data_0d); EXPECT_TRUE(HaveSameDimensions(*int_data_0d, *other_int_data_0d)); fl_data_1d->setAll(1.2); - LLData<float> *other_fl_data_1d = new LLData<float>(*fl_data_1d); + LLData<float>* other_fl_data_1d = new LLData<float>(*fl_data_1d); EXPECT_TRUE(HaveSameDimensions(*fl_data_1d, *other_fl_data_1d)); - EXPECT_FLOAT_EQ( (*other_fl_data_1d)[0], 1.2f); + EXPECT_FLOAT_EQ((*other_fl_data_1d)[0], 1.2f); EXPECT_FLOAT_EQ(fl_data_1d->getTotalSum(), other_fl_data_1d->getTotalSum()); db_data_3d->setAll(1.17); - LLData<double> *other_db_data_3d = new LLData<double>(*db_data_3d); + LLData<double>* other_db_data_3d = new LLData<double>(*db_data_3d); EXPECT_TRUE(HaveSameDimensions(*db_data_3d, *other_db_data_3d)); - EXPECT_DOUBLE_EQ( (*other_db_data_3d)[10], 1.17); + EXPECT_DOUBLE_EQ((*other_db_data_3d)[10], 1.17); EXPECT_DOUBLE_EQ(db_data_3d->getTotalSum(), other_db_data_3d->getTotalSum()); - matrix_data_2d->setAll(Eigen::Matrix2d::Identity()); - LLData<Eigen::Matrix2d> *other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); + LLData<Eigen::Matrix2d>* other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); EXPECT_TRUE(HaveSameDimensions(*matrix_data_2d, *other_matrix_data_2d)); - EXPECT_EQ( (*other_matrix_data_2d)[7], Eigen::Matrix2d::Identity()); - //EXPECT_EQ(matrix_data_2d->getTotalSum(), other_matrix_data_2d->getTotalSum()); + EXPECT_EQ((*other_matrix_data_2d)[7], Eigen::Matrix2d::Identity()); + // EXPECT_EQ(matrix_data_2d->getTotalSum(), other_matrix_data_2d->getTotalSum()); delete other_int_data_0d; delete other_fl_data_1d; @@ -132,65 +126,64 @@ TEST_F(LLDataTest, DataCopyingConstructor) { delete other_matrix_data_2d; } -TEST_F(LLDataTest, DataAssignment) { +TEST_F(LLDataTest, DataAssignment) +{ - LLData<float> *other_fl_data_1d = new LLData<float>(*fl_data_1d); + LLData<float>* other_fl_data_1d = new LLData<float>(*fl_data_1d); fl_data_1d->setAll(1.1f); - (*other_fl_data_1d) = (*fl_data_1d); - EXPECT_FLOAT_EQ( (*other_fl_data_1d)[0], 1.1f); + (*other_fl_data_1d) = (*fl_data_1d); + EXPECT_FLOAT_EQ((*other_fl_data_1d)[0], 1.1f); EXPECT_FLOAT_EQ(fl_data_1d->getTotalSum(), other_fl_data_1d->getTotalSum()); - LLData<double> *other_db_data_3d = new LLData<double>(*db_data_3d); + LLData<double>* other_db_data_3d = new LLData<double>(*db_data_3d); db_data_3d->setAll(1.27); - (*other_db_data_3d) = (*db_data_3d); - EXPECT_DOUBLE_EQ( (*other_db_data_3d)[11], 1.27); + (*other_db_data_3d) = (*db_data_3d); + EXPECT_DOUBLE_EQ((*other_db_data_3d)[11], 1.27); EXPECT_DOUBLE_EQ(db_data_3d->getTotalSum(), other_db_data_3d->getTotalSum()); - matrix_data_2d->setAll(Eigen::Matrix2d::Identity()); - LLData<Eigen::Matrix2d> *other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); + LLData<Eigen::Matrix2d>* other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); other_matrix_data_2d->setAll(10 * Eigen::Matrix2d::Identity()); - (* other_matrix_data_2d) = (* matrix_data_2d); - EXPECT_TRUE( (*other_matrix_data_2d)[7].isIdentity()); + (*other_matrix_data_2d) = (*matrix_data_2d); + EXPECT_TRUE((*other_matrix_data_2d)[7].isIdentity()); delete other_fl_data_1d; delete other_db_data_3d; delete other_matrix_data_2d; } -TEST_F(LLDataTest, Addition) { +TEST_F(LLDataTest, Addition) +{ - LLData<float> *other_fl_data_1d = new LLData<float>(*fl_data_1d); + LLData<float>* other_fl_data_1d = new LLData<float>(*fl_data_1d); fl_data_1d->setAll(1.1f); other_fl_data_1d->setAll(2.9f); - (*other_fl_data_1d) += (*fl_data_1d); - EXPECT_FLOAT_EQ( (*other_fl_data_1d)[0], 4.0f); + (*other_fl_data_1d) += (*fl_data_1d); + EXPECT_FLOAT_EQ((*other_fl_data_1d)[0], 4.0f); EXPECT_FLOAT_EQ(other_fl_data_1d->getTotalSum(), 40.0f); - LLData<double> *other_db_data_3d = new LLData<double>(*db_data_3d); + LLData<double>* other_db_data_3d = new LLData<double>(*db_data_3d); db_data_3d->setAll(1.27); other_db_data_3d->setAll(0.73); - (*other_db_data_3d) += (*db_data_3d); - EXPECT_DOUBLE_EQ( (*other_db_data_3d)[11], 2.0); + (*other_db_data_3d) += (*db_data_3d); + EXPECT_DOUBLE_EQ((*other_db_data_3d)[11], 2.0); EXPECT_DOUBLE_EQ(other_db_data_3d->getTotalSum(), 6000.0); - int *odim1 = new int[1]; + int* odim1 = new int[1]; odim1[0] = 12; - LLData<float> *fl_data_1d2 = new LLData<float>(1u, odim1); + LLData<float>* fl_data_1d2 = new LLData<float>(1u, odim1); fl_data_1d2->setAll(10.0); EXPECT_THROW((*fl_data_1d) += (*fl_data_1d2), Exceptions::RuntimeErrorException); - - LLData<Eigen::Matrix2d> *other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); - matrix_data_2d->setAll( Eigen::Matrix2d::Identity()); - other_matrix_data_2d->setAll( 5 * Eigen::Matrix2d::Identity()); + LLData<Eigen::Matrix2d>* other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); + matrix_data_2d->setAll(Eigen::Matrix2d::Identity()); + other_matrix_data_2d->setAll(5 * Eigen::Matrix2d::Identity()); (*other_matrix_data_2d) += (*matrix_data_2d); - EXPECT_EQ( (*other_matrix_data_2d)[5], 6 * Eigen::Matrix2d::Identity()); - + EXPECT_EQ((*other_matrix_data_2d)[5], 6 * Eigen::Matrix2d::Identity()); delete fl_data_1d2; - delete [] odim1; + delete[] odim1; delete other_fl_data_1d; delete other_db_data_3d; @@ -198,130 +191,132 @@ TEST_F(LLDataTest, Addition) { delete other_matrix_data_2d; } -TEST_F(LLDataTest, Substraction) { +TEST_F(LLDataTest, Substraction) +{ - LLData<float> *other_fl_data_1d = new LLData<float>(*fl_data_1d); + LLData<float>* other_fl_data_1d = new LLData<float>(*fl_data_1d); fl_data_1d->setAll(1.15f); other_fl_data_1d->setAll(5.15f); - (*other_fl_data_1d) -= (*fl_data_1d); - EXPECT_FLOAT_EQ( (*other_fl_data_1d)[0], 4.0f); + (*other_fl_data_1d) -= (*fl_data_1d); + EXPECT_FLOAT_EQ((*other_fl_data_1d)[0], 4.0f); EXPECT_FLOAT_EQ(other_fl_data_1d->getTotalSum(), 40.0f); - LLData<double> *other_db_data_3d = new LLData<double>(*db_data_3d); + LLData<double>* other_db_data_3d = new LLData<double>(*db_data_3d); db_data_3d->setAll(1.27); other_db_data_3d->setAll(1.77); - (*other_db_data_3d) -= (*db_data_3d); - EXPECT_DOUBLE_EQ( (*other_db_data_3d)[11], 0.5); + (*other_db_data_3d) -= (*db_data_3d); + EXPECT_DOUBLE_EQ((*other_db_data_3d)[11], 0.5); EXPECT_DOUBLE_EQ(other_db_data_3d->getTotalSum(), 1500.0); - int *odim1 = new int[1]; + int* odim1 = new int[1]; odim1[0] = 12; - LLData<float> *fl_data_1d2 = new LLData<float>(1u, odim1); + LLData<float>* fl_data_1d2 = new LLData<float>(1u, odim1); fl_data_1d2->setAll(10.0); EXPECT_THROW((*fl_data_1d) -= (*fl_data_1d2), Exceptions::RuntimeErrorException); - LLData<Eigen::Matrix2d> *other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); - matrix_data_2d->setAll( Eigen::Matrix2d::Identity()); - other_matrix_data_2d->setAll( 5 * Eigen::Matrix2d::Identity()); + LLData<Eigen::Matrix2d>* other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); + matrix_data_2d->setAll(Eigen::Matrix2d::Identity()); + other_matrix_data_2d->setAll(5 * Eigen::Matrix2d::Identity()); (*other_matrix_data_2d) -= (*matrix_data_2d); - EXPECT_EQ( (*other_matrix_data_2d)[5], 4 * Eigen::Matrix2d::Identity()); + EXPECT_EQ((*other_matrix_data_2d)[5], 4 * Eigen::Matrix2d::Identity()); delete fl_data_1d2; - delete [] odim1; + delete[] odim1; delete other_fl_data_1d; delete other_db_data_3d; delete other_matrix_data_2d; } -TEST_F(LLDataTest, Multiplication) { +TEST_F(LLDataTest, Multiplication) +{ - LLData<float> *other_fl_data_1d = new LLData<float>(*fl_data_1d); + LLData<float>* other_fl_data_1d = new LLData<float>(*fl_data_1d); fl_data_1d->setAll(1.15f); other_fl_data_1d->setAll(2.0f); - (*other_fl_data_1d) *= (*fl_data_1d); - EXPECT_FLOAT_EQ( (*other_fl_data_1d)[0], 2.30f); + (*other_fl_data_1d) *= (*fl_data_1d); + EXPECT_FLOAT_EQ((*other_fl_data_1d)[0], 2.30f); EXPECT_FLOAT_EQ(other_fl_data_1d->getTotalSum(), 23.0f); - LLData<double> *other_db_data_3d = new LLData<double>(*db_data_3d); + LLData<double>* other_db_data_3d = new LLData<double>(*db_data_3d); db_data_3d->setAll(1.25); other_db_data_3d->setAll(2.0); - (*other_db_data_3d) *= (*db_data_3d); - EXPECT_DOUBLE_EQ( (*other_db_data_3d)[11], 2.5); + (*other_db_data_3d) *= (*db_data_3d); + EXPECT_DOUBLE_EQ((*other_db_data_3d)[11], 2.5); EXPECT_DOUBLE_EQ(other_db_data_3d->getTotalSum(), 7500.0); - int *odim1 = new int[1]; + int* odim1 = new int[1]; odim1[0] = 12; - LLData<float> *fl_data_1d2 = new LLData<float>(1u, odim1); + LLData<float>* fl_data_1d2 = new LLData<float>(1u, odim1); fl_data_1d2->setAll(10.0); EXPECT_THROW((*fl_data_1d) *= (*fl_data_1d2), Exceptions::RuntimeErrorException); - LLData<Eigen::Matrix2d> *other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); - matrix_data_2d->setAll( 2*Eigen::Matrix2d::Identity()); - other_matrix_data_2d->setAll( 5 * Eigen::Matrix2d::Identity()); + LLData<Eigen::Matrix2d>* other_matrix_data_2d = new LLData<Eigen::Matrix2d>(*matrix_data_2d); + matrix_data_2d->setAll(2 * Eigen::Matrix2d::Identity()); + other_matrix_data_2d->setAll(5 * Eigen::Matrix2d::Identity()); (*other_matrix_data_2d) *= (*matrix_data_2d); - EXPECT_EQ( (*other_matrix_data_2d)[5], 10 * Eigen::Matrix2d::Identity()); + EXPECT_EQ((*other_matrix_data_2d)[5], 10 * Eigen::Matrix2d::Identity()); delete fl_data_1d2; - delete [] odim1; + delete[] odim1; delete other_fl_data_1d; delete other_db_data_3d; delete other_matrix_data_2d; } -TEST_F(LLDataTest, Division) { +TEST_F(LLDataTest, Division) +{ - LLData<float> *other_fl_data_1d = new LLData<float>(*fl_data_1d); + LLData<float>* other_fl_data_1d = new LLData<float>(*fl_data_1d); fl_data_1d->setAll(1.15f); other_fl_data_1d->setAll(2.3f); - (*other_fl_data_1d) /= (*fl_data_1d); - EXPECT_FLOAT_EQ( (*other_fl_data_1d)[0], 2.0f); + (*other_fl_data_1d) /= (*fl_data_1d); + EXPECT_FLOAT_EQ((*other_fl_data_1d)[0], 2.0f); EXPECT_FLOAT_EQ(other_fl_data_1d->getTotalSum(), 20.0f); - LLData<double> *other_db_data_3d = new LLData<double>(*db_data_3d); + LLData<double>* other_db_data_3d = new LLData<double>(*db_data_3d); db_data_3d->setAll(1.25); other_db_data_3d->setAll(2.5); - (*other_db_data_3d) /= (*db_data_3d); - EXPECT_DOUBLE_EQ( (*other_db_data_3d)[11], 2.0); + (*other_db_data_3d) /= (*db_data_3d); + EXPECT_DOUBLE_EQ((*other_db_data_3d)[11], 2.0); EXPECT_DOUBLE_EQ(other_db_data_3d->getTotalSum(), 6000.0); - int *odim1 = new int[1]; + int* odim1 = new int[1]; odim1[0] = 12; - LLData<float> *fl_data_1d2 = new LLData<float>(1u, odim1); + LLData<float>* fl_data_1d2 = new LLData<float>(1u, odim1); fl_data_1d2->setAll(10.0); EXPECT_THROW((*fl_data_1d) /= (*fl_data_1d2), Exceptions::RuntimeErrorException); - delete fl_data_1d2; - delete [] odim1; + delete[] odim1; delete other_fl_data_1d; delete other_db_data_3d; } -TEST_F (LLDataTest, HaveSameDimensions) { - int *odim0 = new int[0]; +TEST_F(LLDataTest, HaveSameDimensions) +{ + int* odim0 = new int[0]; - int *odim1 = new int[1]; + int* odim1 = new int[1]; odim1[0] = 10; - int *odim3 = new int[3]; + int* odim3 = new int[3]; odim3[0] = 10; odim3[1] = 15; odim3[2] = 20; - int *odim2 = new int[2]; + int* odim2 = new int[2]; odim2[0] = 20; odim2[1] = 30; - - LLData<int> *other_int_data_0d = new LLData<int>(0u, odim0); - LLData<float> *other_fl_data_1d = new LLData<float>(1u, odim1); - LLData<double> *other_db_data_3d = new LLData<double>(3u, odim3); - LLData<Eigen::Matrix2d> *other_matrix_data_2d = new LLData<Eigen::Matrix2d>(2u, odim2); + LLData<int>* other_int_data_0d = new LLData<int>(0u, odim0); + LLData<float>* other_fl_data_1d = new LLData<float>(1u, odim1); + LLData<double>* other_db_data_3d = new LLData<double>(3u, odim3); + LLData<Eigen::Matrix2d>* other_matrix_data_2d = new LLData<Eigen::Matrix2d>(2u, odim2); EXPECT_TRUE(HaveSameDimensions(*int_data_0d, *other_int_data_0d)); EXPECT_TRUE(HaveSameDimensions(*fl_data_1d, *other_fl_data_1d)); @@ -329,7 +324,7 @@ TEST_F (LLDataTest, HaveSameDimensions) { EXPECT_TRUE(HaveSameDimensions(*other_matrix_data_2d, *matrix_data_2d)); odim3[1] = 25; - LLData<double> *some_other_db_data_3d = new LLData<double>(3u, odim3); + LLData<double>* some_other_db_data_3d = new LLData<double>(3u, odim3); EXPECT_FALSE(HaveSameDimensions(*db_data_3d, *some_other_db_data_3d)); delete other_int_data_0d; @@ -337,29 +332,30 @@ TEST_F (LLDataTest, HaveSameDimensions) { delete other_db_data_3d; delete some_other_db_data_3d; delete other_matrix_data_2d; - delete [] odim0; - delete [] odim1; - delete [] odim3; - delete [] odim2; + delete[] odim0; + delete[] odim1; + delete[] odim3; + delete[] odim2; } -TEST_F(LLDataTest, Accessors) { - for (size_t i=0; i < fl_data_1d->getTotalSize(); ++i) { - (*fl_data_1d)[i] = 0.5f*i; +TEST_F(LLDataTest, Accessors) +{ + for (size_t i = 0; i < fl_data_1d->getTotalSize(); ++i) { + (*fl_data_1d)[i] = 0.5f * i; } EXPECT_FLOAT_EQ((*fl_data_1d)[2], 1.0f); - int *coordinate = new int[1]; + int* coordinate = new int[1]; coordinate[0] = 2; EXPECT_FLOAT_EQ(fl_data_1d->atCoordinate(coordinate), 1.0f); EXPECT_FLOAT_EQ(fl_data_1d->getTotalSum(), 22.5f); - for (size_t i=0; i < db_data_3d->getTotalSize(); ++i) { - (*db_data_3d)[i] = 0.2*i; + for (size_t i = 0; i < db_data_3d->getTotalSize(); ++i) { + (*db_data_3d)[i] = 0.2 * i; } EXPECT_DOUBLE_EQ((*db_data_3d)[2], 0.4); - int *coordinate3d = new int[3]; + int* coordinate3d = new int[3]; coordinate3d[0] = 0; coordinate3d[1] = 0; coordinate3d[2] = 2; @@ -367,21 +363,18 @@ TEST_F(LLDataTest, Accessors) { EXPECT_DOUBLE_EQ(db_data_3d->atCoordinate(coordinate3d), 0.4); EXPECT_DOUBLE_EQ(db_data_3d->getTotalSum(), 899700.0); - - - for (size_t i=0; i < matrix_data_2d->getTotalSize(); ++i) { - (*matrix_data_2d)[i] = static_cast<double>(i) * Eigen::Matrix2d::Identity(); + for (size_t i = 0; i < matrix_data_2d->getTotalSize(); ++i) { + (*matrix_data_2d)[i] = static_cast<double>(i) * Eigen::Matrix2d::Identity(); } EXPECT_EQ((*matrix_data_2d)[2], 2 * Eigen::Matrix2d::Identity()); - int *coordinate2d = new int[2]; + int* coordinate2d = new int[2]; coordinate2d[0] = 0; coordinate2d[1] = 2; EXPECT_EQ(matrix_data_2d->atCoordinate(coordinate2d), 2 * Eigen::Matrix2d::Identity()); - delete [] coordinate; - delete [] coordinate3d; - delete [] coordinate2d; - + delete[] coordinate; + delete[] coordinate3d; + delete[] coordinate2d; } diff --git a/Tests/UnitTests/Core/DataStructure/OutputDataIteratorTest.h b/Tests/UnitTests/Core/DataStructure/OutputDataIteratorTest.h index a8af9d13a2f..6ac5df8faf1 100644 --- a/Tests/UnitTests/Core/DataStructure/OutputDataIteratorTest.h +++ b/Tests/UnitTests/Core/DataStructure/OutputDataIteratorTest.h @@ -1,18 +1,20 @@ +#include "google_test.h" +#include "OutputData.h" #include "OutputDataIterator.h" class OutputDataIteratorTest : public ::testing::Test { - protected: +protected: OutputDataIteratorTest(); virtual ~OutputDataIteratorTest(); - OutputData<double> *p_data; + OutputData<double>* p_data; }; OutputDataIteratorTest::OutputDataIteratorTest() { p_data = new OutputData<double>(); - int *dims = new int[2]; + int* dims = new int[2]; dims[0] = 3; dims[1] = 5; p_data->setAxisSizes(2, dims); @@ -25,16 +27,13 @@ OutputDataIteratorTest::OutputDataIteratorTest() } } -OutputDataIteratorTest::~OutputDataIteratorTest() -{ - delete p_data; -} +OutputDataIteratorTest::~OutputDataIteratorTest() { delete p_data; } TEST_F(OutputDataIteratorTest, Iterate) { OutputData<double>::iterator it = p_data->begin(); EXPECT_EQ(0.0, *it); - for (size_t i=0; i<14; ++i) { + for (size_t i = 0; i < 14; ++i) { ++it; } EXPECT_DOUBLE_EQ(14.0, *it); @@ -48,7 +47,7 @@ TEST_F(OutputDataIteratorTest, ConstIterate) { OutputData<double>::const_iterator it = p_data->begin(); EXPECT_EQ(0.0, *it); - for (size_t i=0; i<14; ++i) { + for (size_t i = 0; i < 14; ++i) { ++it; } EXPECT_DOUBLE_EQ(14.0, *it); diff --git a/Tests/UnitTests/Core/DataStructure/OutputDataTest.h b/Tests/UnitTests/Core/DataStructure/OutputDataTest.h index 4cf4e0fc025..826983567ac 100644 --- a/Tests/UnitTests/Core/DataStructure/OutputDataTest.h +++ b/Tests/UnitTests/Core/DataStructure/OutputDataTest.h @@ -1,3 +1,4 @@ +#include "google_test.h" #include "OutputData.h" #include <algorithm> #include "IntensityDataFunctions.h" diff --git a/Tests/UnitTests/Core/Detector/DetectorMaskTest.h b/Tests/UnitTests/Core/Detector/DetectorMaskTest.h index cf616c70a7b..b858a2b375e 100644 --- a/Tests/UnitTests/Core/Detector/DetectorMaskTest.h +++ b/Tests/UnitTests/Core/Detector/DetectorMaskTest.h @@ -1,13 +1,16 @@ +#include "google_test.h" #include "DetectorMask.h" -#include "SphericalDetector.h" #include "Polygon.h" +#include "SphericalDetector.h" #include <memory> class DetectorMaskTest : public ::testing::Test { public: + ~DetectorMaskTest(); }; +DetectorMaskTest::~DetectorMaskTest() = default; TEST_F(DetectorMaskTest, InitialState) { @@ -16,7 +19,6 @@ TEST_F(DetectorMaskTest, InitialState) EXPECT_FALSE(test.getMaskData()->isInitialized()); } - // 4.0 ------------------------------------------------------------------------- // | 5 | 11 | 17 | 23 | 29 | 35 | 41 | 47 | 53 | 59 | 65 | 71 | // 3.0 ------------------------------------------------------------------------- @@ -50,10 +52,10 @@ TEST_F(DetectorMaskTest, AddMask) EXPECT_TRUE(detectorMask.getMaskData()->isInitialized()); - for(size_t index=0; index<detectorMask.getMaskData()->getAllocatedSize(); ++index) { + for (size_t index = 0; index < detectorMask.getMaskData()->getAllocatedSize(); ++index) { double x = detectorMask.getMaskData()->getAxisValue(index, 0); double y = detectorMask.getMaskData()->getAxisValue(index, 1); - if( x>= -4.0 && x <=4.0 && y>=-2.0 && y<=2.0) { + if (x >= -4.0 && x <= 4.0 && y >= -2.0 && y <= 2.0) { EXPECT_TRUE(detectorMask.isMasked(index)); } else { EXPECT_FALSE(detectorMask.isMasked(index)); @@ -66,7 +68,7 @@ TEST_F(DetectorMaskTest, AddMask) detectorMask.addMask(polygon, false); detectorMask.initMaskData(detector); - for(size_t index=0; index<detectorMask.getMaskData()->getAllocatedSize(); ++index) { + for (size_t index = 0; index < detectorMask.getMaskData()->getAllocatedSize(); ++index) { EXPECT_FALSE(detectorMask.isMasked(index)); } EXPECT_EQ(detectorMask.numberOfMaskedChannels(), 0); @@ -77,10 +79,10 @@ TEST_F(DetectorMaskTest, AddMask) Polygon polygon2(x, y); detectorMask.addMask(polygon2, true); detectorMask.initMaskData(detector); - for(size_t index=0; index<detectorMask.getMaskData()->getAllocatedSize(); ++index) { + for (size_t index = 0; index < detectorMask.getMaskData()->getAllocatedSize(); ++index) { double x = detectorMask.getMaskData()->getAxisValue(index, 0); double y = detectorMask.getMaskData()->getAxisValue(index, 1); - if( x>= 5.0 && x <=8.0 && y>=2.0 && y<=4.0) { + if (x >= 5.0 && x <= 8.0 && y >= 2.0 && y <= 4.0) { EXPECT_TRUE(detectorMask.isMasked(index)); } else { EXPECT_FALSE(detectorMask.isMasked(index)); @@ -90,13 +92,11 @@ TEST_F(DetectorMaskTest, AddMask) // clearing all masks detectorMask.removeMasks(); detectorMask.initMaskData(detector); - for(size_t index=0; index<detectorMask.getMaskData()->getAllocatedSize(); ++index) { + for (size_t index = 0; index < detectorMask.getMaskData()->getAllocatedSize(); ++index) { EXPECT_FALSE(detectorMask.isMasked(index)); } - } - TEST_F(DetectorMaskTest, AssignmentOperator) { DetectorMask detectorMask; @@ -117,20 +117,18 @@ TEST_F(DetectorMaskTest, AssignmentOperator) EXPECT_TRUE(mask.getMaskData()->isInitialized()); - for(size_t index=0; index<mask.getMaskData()->getAllocatedSize(); ++index) { + for (size_t index = 0; index < mask.getMaskData()->getAllocatedSize(); ++index) { double x = mask.getMaskData()->getAxisValue(index, 0); double y = mask.getMaskData()->getAxisValue(index, 1); - if( x>= -4.0 && x <=4.0 && y>=-2.0 && y<=2.0) { + if (x >= -4.0 && x <= 4.0 && y >= -2.0 && y <= 2.0) { EXPECT_TRUE(mask.isMasked(index)); } else { EXPECT_FALSE(mask.isMasked(index)); } } EXPECT_EQ(mask.numberOfMaskedChannels(), 32); - } - TEST_F(DetectorMaskTest, CopyConstructor) { DetectorMask detectorMask; diff --git a/Tests/UnitTests/Core/Detector/PolygonTest.h b/Tests/UnitTests/Core/Detector/PolygonTest.h index 20b55d62764..45d13714b21 100644 --- a/Tests/UnitTests/Core/Detector/PolygonTest.h +++ b/Tests/UnitTests/Core/Detector/PolygonTest.h @@ -1,11 +1,15 @@ +#include "google_test.h" #include "Polygon.h" +#include "Bin.h" #include <memory> class PolygonTest : public ::testing::Test { public: + ~PolygonTest(); }; +PolygonTest::~PolygonTest() = default; TEST_F(PolygonTest, SimpleRectangle) { @@ -47,7 +51,7 @@ TEST_F(PolygonTest, SandWatchShape) std::vector<double> x = {2.0, -2.0, 2.0, -2.0, 2.0}; std::vector<double> y = {2.0, 2.0, -2.0, -2.0, 2.0}; Polygon polygon(x, y); -// std::cout << polygon << std::endl; + // std::cout << polygon << std::endl; // for some reason area calculation doesn't work for boost's polygon of such shape // EXPECT_DOUBLE_EQ(8.0, polygon.getArea()); @@ -59,7 +63,6 @@ TEST_F(PolygonTest, SandWatchShape) EXPECT_FALSE(polygon.contains(1.0, 0.0)); EXPECT_FALSE(polygon.contains(-1.5, 0.5)); - } TEST_F(PolygonTest, ContainsBin) @@ -78,14 +81,13 @@ TEST_F(PolygonTest, ContainsBin) EXPECT_FALSE(polygon.contains(binx2, biny2)); } - TEST_F(PolygonTest, Clone) { std::vector<double> x = {4.0, -4.0, -4.0, 4.0, 4.0}; std::vector<double> y = {2.0, 2.0, -2.0, -2.0, 2.0}; Polygon polygon(x, y); - std::unique_ptr<Polygon > clone(polygon.clone()); + std::unique_ptr<Polygon> clone(polygon.clone()); EXPECT_DOUBLE_EQ(32.0, clone->getArea()); EXPECT_TRUE(clone->contains(0.0, 0.0)); EXPECT_TRUE(clone->contains(4.0, 2.0)); @@ -101,8 +103,8 @@ TEST_F(PolygonTest, ConstructFrom2DArray) const size_t npoints(5); double array[npoints][2] = {{4.0, 2.0}, {-4.0, 2.0}, {-4.0, -2.0}, {4.0, -2.0}, {4.0, 2.0}}; - std::vector<std::vector<double > > points; - for(size_t i=0; i<npoints; ++i) { + std::vector<std::vector<double>> points; + for (size_t i = 0; i < npoints; ++i) { std::vector<double> p = {array[i][0], array[i][1]}; points.push_back(p); } @@ -116,19 +118,3 @@ TEST_F(PolygonTest, ConstructFrom2DArray) EXPECT_FALSE(polygon.contains(0.0, 2.01)); EXPECT_FALSE(polygon.contains(4.0, -2.01)); } - -//TEST_F(PolygonTest, GetPoints) -//{ -// std::vector<double> xpos; -// std::vector<double> ypos; - -// std::vector<double> x = {4.0, -4.0, -4.0, 4.0, 4.0}; -// std::vector<double> y = {2.0, 2.0, -2.0, -2.0, 2.0}; -// Polygon polygon(x, y); - -// polygon.getPoints(xpos, ypos); -// for(size_t i=0; i<xpos.size(); ++i) { -// std::cout << xpos[i] << " " << ypos[i] << std::endl; -// } - -//} diff --git a/Tests/UnitTests/Core/Detector/PrecomputedTest.h b/Tests/UnitTests/Core/Detector/PrecomputedTest.h index ec5be695daa..038bc077cfc 100644 --- a/Tests/UnitTests/Core/Detector/PrecomputedTest.h +++ b/Tests/UnitTests/Core/Detector/PrecomputedTest.h @@ -1,28 +1,33 @@ +#include "google_test.h" #include "Precomputed.h" #include <memory> -namespace { - constexpr auto ReciprocalFactorialArray = Precomputed::GenerateReciprocalFactorialArray<171>(); +namespace +{ +constexpr auto ReciprocalFactorialArray = Precomputed::GenerateReciprocalFactorialArray<171>(); } class PrecomputedTest : public ::testing::Test { public: + ~PrecomputedTest(); }; +PrecomputedTest::~PrecomputedTest() = default; + TEST_F(PrecomputedTest, ReciprocalFactorial) { const double eps = 2.3e-16; // about the machine precision - EXPECT_TRUE(ReciprocalFactorialArray.size()>150); + EXPECT_TRUE(ReciprocalFactorialArray.size() > 150); EXPECT_DOUBLE_EQ(ReciprocalFactorialArray[0], 1.); EXPECT_DOUBLE_EQ(ReciprocalFactorialArray[1], 1.); EXPECT_DOUBLE_EQ(ReciprocalFactorialArray[2], 0.5); - EXPECT_DOUBLE_EQ(ReciprocalFactorialArray[3], 1.0/6); + EXPECT_DOUBLE_EQ(ReciprocalFactorialArray[3], 1.0 / 6); /* the following disabled because tgamma is too unprecise under old versions of glibc (at leat up to 2.12, but less than 2.22) for( size_t k=4; k<precomputed.factorial.size(); ++k ) EXPECT_NEAR(precomputed.factorial[k], tgamma(k+1.), 12*eps*tgamma(k+1.) ); */ EXPECT_NEAR(ReciprocalFactorialArray[150], 1.75027620692601519e-263, - 4*eps*ReciprocalFactorialArray[150]); + 4 * eps * ReciprocalFactorialArray[150]); } diff --git a/Tests/UnitTests/Core/Detector/RectangularDetectorTest.h b/Tests/UnitTests/Core/Detector/RectangularDetectorTest.h index 4d77ef77322..84a2831b841 100644 --- a/Tests/UnitTests/Core/Detector/RectangularDetectorTest.h +++ b/Tests/UnitTests/Core/Detector/RectangularDetectorTest.h @@ -1,33 +1,39 @@ -#include "RectangularDetector.h" #include "GISASSimulation.h" -#include "SimulationElement.h" #include "Numeric.h" +#include "RectangularDetector.h" +#include "SimulationElement.h" #include "Units.h" -#include <memory> +#include "google_test.h" #include <iostream> +#include <memory> class RectangularDetectorTest : public ::testing::Test { - protected: - RectangularDetectorTest(){} - virtual ~RectangularDetectorTest(){} - - double phi(SimulationElement &element) {return element.getPhiMean()/Units::degree; } - double alpha(SimulationElement &element) {return element.getAlphaMean()/Units::degree; } - double phi(kvector_t k) {return k.phi()/Units::degree; } - double alpha(kvector_t k) {return 90.0 - k.theta()/Units::degree; } - - bool isEqual(const kvector_t lhs, const kvector_t rhs) { - bool is_equal = Numeric::areAlmostEqual(lhs.x(), rhs.x()) && - Numeric::areAlmostEqual(lhs.y(), rhs.y()) && - Numeric::areAlmostEqual(lhs.z(), rhs.z()); - if(!is_equal) { - std::cout << "lhs:" << lhs << " rhs:" << rhs << " diff:" << (lhs-rhs) << std::endl; +protected: + ~RectangularDetectorTest(); + + double phi(SimulationElement& element) + { + return element.getPhiMean() / Units::degree; + } + double alpha(SimulationElement& element) { return element.getAlphaMean() / Units::degree; } + double phi(kvector_t k) { return k.phi() / Units::degree; } + double alpha(kvector_t k) { return 90.0 - k.theta() / Units::degree; } + + bool isEqual(const kvector_t lhs, const kvector_t rhs) + { + bool is_equal = Numeric::areAlmostEqual(lhs.x(), rhs.x()) + && Numeric::areAlmostEqual(lhs.y(), rhs.y()) + && Numeric::areAlmostEqual(lhs.z(), rhs.z()); + if (!is_equal) { + std::cout << "lhs:" << lhs << " rhs:" << rhs << " diff:" << (lhs - rhs) << std::endl; } return is_equal; } }; +RectangularDetectorTest::~RectangularDetectorTest() = default; + TEST_F(RectangularDetectorTest, InitialState) { RectangularDetector det(50, 10.0, 60, 20.0); @@ -67,8 +73,8 @@ TEST_F(RectangularDetectorTest, PerpToSample) int nbinsx(5), nbinsy(4); double width(50.0), height(40.0); double distance(100.0), u0(20.0), v0(10.0); - double dx = width/nbinsx; - double dy = height/nbinsy; + double dx = width / nbinsx; + double dy = height / nbinsy; RectangularDetector det(nbinsx, width, nbinsy, height); @@ -83,48 +89,48 @@ TEST_F(RectangularDetectorTest, PerpToSample) // initializing with the simulation GISASSimulation simulation; - simulation.setBeamParameters(1.0, 10.0*Units::degree, 0.0); + simulation.setBeamParameters(1.0, 10.0 * Units::degree, 0.0); det.init(simulation.getInstrument().getBeam()); EXPECT_TRUE(kvector_t(distance, 0, 0) == det.getNormalVector()); EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); - std::vector<SimulationElement> elements = det.createSimulationElements(simulation.getInstrument().getBeam()); - EXPECT_EQ(elements.size(), size_t(nbinsx*nbinsy)); + std::vector<SimulationElement> elements + = det.createSimulationElements(simulation.getInstrument().getBeam()); + EXPECT_EQ(elements.size(), size_t(nbinsx * nbinsy)); // lower left bin - kvector_t k(distance, u0-dx/2., (-v0+dy/2.)); + kvector_t k(distance, u0 - dx / 2., (-v0 + dy / 2.)); SimulationElement element = elements[0]; EXPECT_DOUBLE_EQ(phi(k), phi(element)); - EXPECT_NEAR(alpha(k), alpha(element), 1e-10*std::abs(alpha(k))); + EXPECT_NEAR(alpha(k), alpha(element), 1e-10 * std::abs(alpha(k))); // upper left bin - k = kvector_t(distance, u0-dx/2., (height - v0 - dy/2.)); + k = kvector_t(distance, u0 - dx / 2., (height - v0 - dy / 2.)); element = elements[3]; EXPECT_DOUBLE_EQ(phi(k), phi(element)); - EXPECT_NEAR(alpha(k), alpha(element), 1e-10*std::abs(alpha(k))); + EXPECT_NEAR(alpha(k), alpha(element), 1e-10 * std::abs(alpha(k))); // lower right bin - k = kvector_t(distance, -(width-u0-dx/2.), (-v0+dy/2.)); + k = kvector_t(distance, -(width - u0 - dx / 2.), (-v0 + dy / 2.)); element = elements[16]; EXPECT_DOUBLE_EQ(phi(k), phi(element)); - EXPECT_NEAR(alpha(k), alpha(element), 1e-10*std::abs(alpha(k))); + EXPECT_NEAR(alpha(k), alpha(element), 1e-10 * std::abs(alpha(k))); // upper right bin - k = kvector_t(distance, -(width-u0-dx/2.), (height - v0 - dy/2.)); + k = kvector_t(distance, -(width - u0 - dx / 2.), (height - v0 - dy / 2.)); element = elements[19]; EXPECT_DOUBLE_EQ(phi(k), phi(element)); - EXPECT_NEAR(alpha(k), alpha(element), 1e-10*std::abs(alpha(k))); + EXPECT_NEAR(alpha(k), alpha(element), 1e-10 * std::abs(alpha(k))); } - TEST_F(RectangularDetectorTest, PerpToDirectBeam) { int nbinsx(5), nbinsy(4); double width(50.0), height(40.0); double distance(100.0), u0(20.0), v0(10.0); - double dx = width/nbinsx; - double dy = height/nbinsy; - double alpha_i(10.0*Units::degree); + double dx = width / nbinsx; + double dy = height / nbinsy; + double alpha_i(10.0 * Units::degree); RectangularDetector det(nbinsx, width, nbinsy, height); @@ -141,33 +147,33 @@ TEST_F(RectangularDetectorTest, PerpToDirectBeam) GISASSimulation simulation; simulation.setBeamParameters(1.0, alpha_i, 0.0); det.init(simulation.getInstrument().getBeam()); - kvector_t normal(distance*cos(alpha_i), 0.0, -1.0*distance*sin(alpha_i)); + kvector_t normal(distance * cos(alpha_i), 0.0, -1.0 * distance * sin(alpha_i)); EXPECT_TRUE(isEqual(normal, det.getNormalVector())); EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); - std::vector<SimulationElement> elements = det.createSimulationElements(simulation.getInstrument().getBeam()); - EXPECT_EQ(elements.size(), size_t(nbinsx*nbinsy)); + std::vector<SimulationElement> elements + = det.createSimulationElements(simulation.getInstrument().getBeam()); + EXPECT_EQ(elements.size(), size_t(nbinsx * nbinsy)); // lower left bin - double ds = v0 - dy/2.; - double alpha_x = alpha_i+std::atan(ds/distance); - double c = distance*std::sin(alpha_i) + ds*std::cos(alpha_i); - double x = c/std::tan(alpha_x); - kvector_t k(x, u0-dx/2., -c); + double ds = v0 - dy / 2.; + double alpha_x = alpha_i + std::atan(ds / distance); + double c = distance * std::sin(alpha_i) + ds * std::cos(alpha_i); + double x = c / std::tan(alpha_x); + kvector_t k(x, u0 - dx / 2., -c); SimulationElement element = elements[0]; EXPECT_DOUBLE_EQ(phi(k), phi(element)); - EXPECT_NEAR(alpha(k), alpha(element), 1e-10*std::abs(alpha(k))); + EXPECT_NEAR(alpha(k), alpha(element), 1e-10 * std::abs(alpha(k))); } - TEST_F(RectangularDetectorTest, PerpToReflectedBeam) { int nbinsx(5), nbinsy(4); double width(50.0), height(40.0); double distance(100.0), u0(20.0), v0(10.0); - double dx = width/nbinsx; - double dy = height/nbinsy; - double alpha_i(10.0*Units::degree); + double dx = width / nbinsx; + double dy = height / nbinsy; + double alpha_i(10.0 * Units::degree); RectangularDetector det(nbinsx, width, nbinsy, height); @@ -184,23 +190,24 @@ TEST_F(RectangularDetectorTest, PerpToReflectedBeam) GISASSimulation simulation; simulation.setBeamParameters(1.0, alpha_i, 0.0); det.init(simulation.getInstrument().getBeam()); - kvector_t normal(distance*cos(alpha_i), 0.0, 1.0*distance*sin(alpha_i)); + kvector_t normal(distance * cos(alpha_i), 0.0, 1.0 * distance * sin(alpha_i)); EXPECT_TRUE(isEqual(normal, det.getNormalVector())); EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); // checking detector elements - std::vector<SimulationElement> elements = det.createSimulationElements(simulation.getInstrument().getBeam()); - EXPECT_EQ(elements.size(), size_t(nbinsx*nbinsy)); + std::vector<SimulationElement> elements + = det.createSimulationElements(simulation.getInstrument().getBeam()); + EXPECT_EQ(elements.size(), size_t(nbinsx * nbinsy)); - double ds = v0 - dy/2.; - double alpha_x = alpha_i - std::atan(ds/distance); - double c = distance*std::sin(alpha_i) - std::cos(alpha_i)*ds; - double x = c/std::tan(alpha_x); + double ds = v0 - dy / 2.; + double alpha_x = alpha_i - std::atan(ds / distance); + double c = distance * std::sin(alpha_i) - std::cos(alpha_i) * ds; + double x = c / std::tan(alpha_x); - kvector_t k(x, u0-dx/2., c); + kvector_t k(x, u0 - dx / 2., c); SimulationElement element = elements[0]; EXPECT_DOUBLE_EQ(phi(k), phi(element)); - EXPECT_NEAR(alpha(k), alpha(element), 1e-10*std::abs(alpha(k))); + EXPECT_NEAR(alpha(k), alpha(element), 1e-10 * std::abs(alpha(k))); } // detector perpendicular to reflected beam, when direct beam position is known @@ -209,9 +216,9 @@ TEST_F(RectangularDetectorTest, PerpToReflectedBeamDpos) int nbinsx(5), nbinsy(4); double width(50.0), height(40.0); double distance(100.0), u0(20.0), v0(10.0); - double dx = width/nbinsx; - double dy = height/nbinsy; - double alpha_i(10.0*Units::degree); + double dx = width / nbinsx; + double dy = height / nbinsy; + double alpha_i(10.0 * Units::degree); RectangularDetector det(nbinsx, width, nbinsy, height); @@ -224,39 +231,41 @@ TEST_F(RectangularDetectorTest, PerpToReflectedBeamDpos) EXPECT_EQ(0.0, det.getDirectBeamV0()); double dbeam_u0 = u0; - double dbeam_v0 = -distance*std::tan(alpha_i*2.0) + v0; + double dbeam_v0 = -distance * std::tan(alpha_i * 2.0) + v0; det.setDirectBeamPosition(dbeam_u0, dbeam_v0); EXPECT_EQ(dbeam_u0, det.getDirectBeamU0()); EXPECT_EQ(dbeam_v0, det.getDirectBeamV0()); EXPECT_TRUE(kvector_t() == det.getNormalVector()); EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); - EXPECT_EQ(RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS, det.getDetectorArrangment()); + EXPECT_EQ(RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS, + det.getDetectorArrangment()); // initializing with the simulation GISASSimulation simulation; simulation.setBeamParameters(1.0, alpha_i, 0.0); det.init(simulation.getInstrument().getBeam()); - kvector_t normal(distance*cos(alpha_i), 0.0, 1.0*distance*sin(alpha_i)); + kvector_t normal(distance * cos(alpha_i), 0.0, 1.0 * distance * sin(alpha_i)); EXPECT_TRUE(isEqual(normal, det.getNormalVector())); EXPECT_TRUE(kvector_t(0.0, -1.0, 0.0) == det.getDirectionVector()); EXPECT_EQ(u0, det.getU0()); EXPECT_EQ(v0, det.getV0()); // checking detector elements - std::vector<SimulationElement> elements = det.createSimulationElements(simulation.getInstrument().getBeam()); - EXPECT_EQ(elements.size(), size_t(nbinsx*nbinsy)); + std::vector<SimulationElement> elements + = det.createSimulationElements(simulation.getInstrument().getBeam()); + EXPECT_EQ(elements.size(), size_t(nbinsx * nbinsy)); - double ds = v0 - dy/2.; - double alpha_x = alpha_i - std::atan(ds/distance); - double c = distance*std::sin(alpha_i) - std::cos(alpha_i)*ds; - double x = c/std::tan(alpha_x); + double ds = v0 - dy / 2.; + double alpha_x = alpha_i - std::atan(ds / distance); + double c = distance * std::sin(alpha_i) - std::cos(alpha_i) * ds; + double x = c / std::tan(alpha_x); - kvector_t k(x, u0-dx/2., c); + kvector_t k(x, u0 - dx / 2., c); SimulationElement element = elements[0]; EXPECT_DOUBLE_EQ(phi(k), phi(element)); - EXPECT_NEAR(alpha(k), alpha(element), 1e-10*std::abs(alpha(k))); + EXPECT_NEAR(alpha(k), alpha(element), 1e-10 * std::abs(alpha(k))); } // Test retrieval of analyzer properties diff --git a/Tests/UnitTests/Core/Detector/RegionOfInterestTest.h b/Tests/UnitTests/Core/Detector/RegionOfInterestTest.h index 2231879aa17..94580a45047 100644 --- a/Tests/UnitTests/Core/Detector/RegionOfInterestTest.h +++ b/Tests/UnitTests/Core/Detector/RegionOfInterestTest.h @@ -1,18 +1,17 @@ -#ifndef REGIONOFINTERESTTEST_H -#define REGIONOFINTERESTTEST_H - +#include "google_test.h" +#include "Exceptions.h" #include "RegionOfInterest.h" #include "SphericalDetector.h" -#include "Exceptions.h" #include <memory> class RegionOfInterestTest : public ::testing::Test { - protected: - RegionOfInterestTest(){} - virtual ~RegionOfInterestTest(){} +protected: + ~RegionOfInterestTest(); }; +RegionOfInterestTest::~RegionOfInterestTest() = default; + //! Testing region of interest with reasonable area within the detector. TEST_F(RegionOfInterestTest, constructor) @@ -48,7 +47,6 @@ TEST_F(RegionOfInterestTest, constructor) EXPECT_EQ(roi.detectorIndex(9), 22u); } - //! Testing region of interest which is larger than the detector. TEST_F(RegionOfInterestTest, largeArea) @@ -113,5 +111,3 @@ TEST_F(RegionOfInterestTest, clone) EXPECT_EQ(clone->detectorIndex(2), 9u); EXPECT_EQ(clone->detectorIndex(9), 22u); } - -#endif diff --git a/Tests/UnitTests/Core/Detector/SimulationAreaTest.h b/Tests/UnitTests/Core/Detector/SimulationAreaTest.h index 3ad42ec4aa6..db961bc1b1d 100644 --- a/Tests/UnitTests/Core/Detector/SimulationAreaTest.h +++ b/Tests/UnitTests/Core/Detector/SimulationAreaTest.h @@ -1,19 +1,18 @@ -#ifndef SIMULATIONAREATEST_H -#define SIMULATIONAREATEST_H - +#include "google_test.h" +#include "Rectangle.h" #include "SimulationArea.h" #include "SphericalDetector.h" -#include "Rectangle.h" -#include <memory> #include <iostream> +#include <memory> class SimulationAreaTest : public ::testing::Test { - protected: - SimulationAreaTest(){} - virtual ~SimulationAreaTest(){} +protected: + ~SimulationAreaTest(); }; +SimulationAreaTest::~SimulationAreaTest() = default; + // Iterators test TEST_F(SimulationAreaTest, iteratorOperations) @@ -53,7 +52,8 @@ TEST_F(SimulationAreaTest, iteratorOperations) EXPECT_EQ(it.elementIndex(), 2u); // incrementing well behind the end - for(size_t i=0; i<100; ++i) ++it; + for (size_t i = 0; i < 100; ++i) + ++it; EXPECT_EQ(it.index(), detector.totalSize()); EXPECT_EQ(it.elementIndex(), detector.totalSize()); } @@ -71,7 +71,7 @@ TEST_F(SimulationAreaTest, detectorIteration) std::vector<size_t> indexes; std::vector<size_t> elementIndexes; std::vector<size_t> detectorIndexes; - for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) { + for (SimulationArea::iterator it = area.begin(); it != area.end(); ++it) { indexes.push_back(it.index()); elementIndexes.push_back(it.elementIndex()); detectorIndexes.push_back(it.detectorIndex()); @@ -94,7 +94,7 @@ TEST_F(SimulationAreaTest, maskedIteration) std::vector<size_t> expectedElementIndexes = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; std::vector<size_t> indexes; std::vector<size_t> elementIndexes; - for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) { + for (SimulationArea::iterator it = area.begin(); it != area.end(); ++it) { indexes.push_back(it.index()); elementIndexes.push_back(it.elementIndex()); } @@ -112,12 +112,12 @@ TEST_F(SimulationAreaTest, maskedCornerIteration) SimulationArea area(&detector); std::vector<size_t> expectedIndexes - = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; + = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; std::vector<size_t> expectedElementIndexes - = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; + = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; std::vector<size_t> indexes; std::vector<size_t> elementIndexes; - for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) { + for (SimulationArea::iterator it = area.begin(); it != area.end(); ++it) { indexes.push_back(it.index()); elementIndexes.push_back(it.elementIndex()); } @@ -135,7 +135,7 @@ TEST_F(SimulationAreaTest, allMaskedIteration) std::vector<size_t> indexes; std::vector<size_t> elementIndexes; - for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) { + for (SimulationArea::iterator it = area.begin(); it != area.end(); ++it) { indexes.push_back(it.index()); elementIndexes.push_back(it.elementIndex()); } @@ -159,7 +159,7 @@ TEST_F(SimulationAreaTest, maskAndRoiIteration) std::vector<size_t> elementIndexes; std::vector<size_t> detectorIndexes; std::vector<size_t> roiIndexes; - for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) { + for (SimulationArea::iterator it = area.begin(); it != area.end(); ++it) { indexes.push_back(it.index()); elementIndexes.push_back(it.elementIndex()); detectorIndexes.push_back(it.detectorIndex()); @@ -188,7 +188,7 @@ TEST_F(SimulationAreaTest, indexInRoi) std::vector<size_t> elementIndexes; std::vector<size_t> roiIndexes; std::vector<size_t> detectorIndexes; - for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) { + for (SimulationArea::iterator it = area.begin(); it != area.end(); ++it) { indexes.push_back(it.index()); elementIndexes.push_back(it.elementIndex()); roiIndexes.push_back(it.roiIndex()); @@ -199,5 +199,3 @@ TEST_F(SimulationAreaTest, indexInRoi) EXPECT_EQ(roiIndexes, expectedRoi); EXPECT_EQ(detectorIndexes, expectedDetectorIndexes); } - -#endif diff --git a/Tests/UnitTests/Core/Detector/SpecialFunctionsTest.h b/Tests/UnitTests/Core/Detector/SpecialFunctionsTest.h index f6d56324403..8596edd561b 100644 --- a/Tests/UnitTests/Core/Detector/SpecialFunctionsTest.h +++ b/Tests/UnitTests/Core/Detector/SpecialFunctionsTest.h @@ -1,20 +1,6 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/UnitTests/Core/Detector/SpecialFunctionsTest.h -//! @brief Defines unit test for Form factors. -//! -//! @homepage http://bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#include "MathFunctions.h" +#include "google_test.h" #include "MathConstants.h" +#include "MathFunctions.h" #define EXPECT_CNEAR(a,b,epsi) \ EXPECT_NEAR((a).real(),(b).real(),epsi); EXPECT_NEAR((a).imag(),(b).imag(),epsi); @@ -22,9 +8,11 @@ class SpecialFunctionsTest : public ::testing::Test { protected: - SpecialFunctionsTest(){} + ~SpecialFunctionsTest(); }; +SpecialFunctionsTest::~SpecialFunctionsTest() = default; + // Test complex Bessel function J1 TEST_F(SpecialFunctionsTest, BesselJ1) { @@ -39,21 +27,21 @@ TEST_F(SpecialFunctionsTest, BesselJ1) // online calculator http://keisan.casio.com/exec/system/1180573474. // Agreement is excellent, except for the dominantly imaginary argument .01+100i. // In conclusion, Bessel_J1 is clearly good enough for our purpose. - res = MathFunctions::Bessel_J1(complex_t(0.8,1.5)); - EXPECT_NEAR( res.real(), 0.72837687825769404, eps*std::abs(res) ); // Keisan ..69398... - EXPECT_NEAR( res.imag(), 0.75030568686427268, eps*std::abs(res) ); // Keisan ..27264... + res = MathFunctions::Bessel_J1(complex_t(0.8, 1.5)); + EXPECT_NEAR(res.real(), 0.72837687825769404, eps * std::abs(res)); // Keisan ..69398... + EXPECT_NEAR(res.imag(), 0.75030568686427268, eps * std::abs(res)); // Keisan ..27264... - res = MathFunctions::Bessel_J1(complex_t(1e-2,1e2)); - EXPECT_NEAR( res.real(), 1.0630504683139779e+40, eps*std::abs(res) ); // Keisan 1.063015... - EXPECT_NEAR( res.imag(), 1.0683164984973165e+42, eps*std::abs(res) ); // Keisan ..73162... + res = MathFunctions::Bessel_J1(complex_t(1e-2, 1e2)); + EXPECT_NEAR(res.real(), 1.0630504683139779e+40, eps * std::abs(res)); // Keisan 1.063015... + EXPECT_NEAR(res.imag(), 1.0683164984973165e+42, eps * std::abs(res)); // Keisan ..73162... - res = MathFunctions::Bessel_J1(complex_t(-1e2,1e-2)); - EXPECT_NEAR( res.real(), 0.077149198549289394, eps*std::abs(res) ); // Keisan ..89252... - EXPECT_NEAR( res.imag(), 2.075766253119904e-4, eps*std::abs(res) ); // Keisan ..19951... + res = MathFunctions::Bessel_J1(complex_t(-1e2, 1e-2)); + EXPECT_NEAR(res.real(), 0.077149198549289394, eps * std::abs(res)); // Keisan ..89252... + EXPECT_NEAR(res.imag(), 2.075766253119904e-4, eps * std::abs(res)); // Keisan ..19951... - res = MathFunctions::Bessel_J1(complex_t(7,9)); - EXPECT_NEAR( res.real(), 370.00180888861155, eps*std::abs(res) ); // Keisan ..61107... - EXPECT_NEAR( res.imag(), 856.00300811057934, eps*std::abs(res) ); // Keisan ..57940... + res = MathFunctions::Bessel_J1(complex_t(7, 9)); + EXPECT_NEAR(res.real(), 370.00180888861155, eps * std::abs(res)); // Keisan ..61107... + EXPECT_NEAR(res.imag(), 856.00300811057934, eps * std::abs(res)); // Keisan ..57940... } // Test accuracy of complex function sinc(z) near the removable singularity at z=0 @@ -62,31 +50,51 @@ TEST_F(SpecialFunctionsTest, csinc) { const double eps = 4.7e-16; // more than twice the machine precision - for( int i=0; i<24; ++i ) { - double ph = M_TWOPI*i/24; - //std::cout << "---------------------------------------------------------------------\n"; - //std::cout << "phase = " << ph << "\n"; - EXPECT_EQ( MathFunctions::sinc(complex_t(0,0)), complex_t(1.,0.) ); + for (int i = 0; i < 24; ++i) { + double ph = M_TWOPI * i / 24; + // std::cout << "---------------------------------------------------------------------\n"; + // std::cout << "phase = " << ph << "\n"; + EXPECT_EQ(MathFunctions::sinc(complex_t(0, 0)), complex_t(1., 0.)); complex_t z; - z=std::polar(1e-17,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(2e-17,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(5e-17,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(1e-16,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(2e-16,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(5e-16,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(1e-15,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(1e-13,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(1e-11,ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(1e-9, ph); EXPECT_CNEAR( MathFunctions::sinc(z), complex_t(1.,0.), eps ); - z=std::polar(5e-8,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6., eps ); - z=std::polar(2e-8,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6., eps ); - z=std::polar(1e-8,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6., eps ); - z=std::polar(5e-7,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6., eps ); - z=std::polar(2e-7,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6., eps ); - z=std::polar(1e-7,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6., eps ); - z=std::polar(1e-6,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6., eps ); - z=std::polar(1e-5,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6., eps ); - z=std::polar(1e-4,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6.*(1.-z*z/20.), eps ); - z=std::polar(1e-3,ph); EXPECT_CNEAR( MathFunctions::sinc(z), 1.-z*z/6.*(1.-z*z/20.), eps ); + z = std::polar(1e-17, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(2e-17, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(5e-17, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(1e-16, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(2e-16, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(5e-16, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(1e-15, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(1e-13, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(1e-11, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(1e-9, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), complex_t(1., 0.), eps); + z = std::polar(5e-8, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6., eps); + z = std::polar(2e-8, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6., eps); + z = std::polar(1e-8, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6., eps); + z = std::polar(5e-7, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6., eps); + z = std::polar(2e-7, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6., eps); + z = std::polar(1e-7, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6., eps); + z = std::polar(1e-6, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6., eps); + z = std::polar(1e-5, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6., eps); + z = std::polar(1e-4, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6. * (1. - z * z / 20.), eps); + z = std::polar(1e-3, ph); + EXPECT_CNEAR(MathFunctions::sinc(z), 1. - z * z / 6. * (1. - z * z / 20.), eps); } } diff --git a/Tests/UnitTests/Core/Detector/SpecularDetector1DTest.h b/Tests/UnitTests/Core/Detector/SpecularDetector1DTest.h index e6a7653768e..117ae5da774 100644 --- a/Tests/UnitTests/Core/Detector/SpecularDetector1DTest.h +++ b/Tests/UnitTests/Core/Detector/SpecularDetector1DTest.h @@ -1,19 +1,22 @@ -#include "SpecularDetector1D.h" -#include "OutputData.h" -#include "FixedBinAxis.h" -#include "BornAgainNamespace.h" -#include "Units.h" #include "Beam.h" +#include "BornAgainNamespace.h" +#include "FixedBinAxis.h" +#include "OutputData.h" +#include "SimulationElement.h" #include "SimulationArea.h" +#include "SpecularDetector1D.h" +#include "Units.h" +#include "google_test.h" #include <memory> class SpecularDetectorTest : public ::testing::Test { - protected: - SpecularDetectorTest(){} - virtual ~SpecularDetectorTest(){} +protected: + ~SpecularDetectorTest(); }; +SpecularDetectorTest::~SpecularDetectorTest() = default; + // Default detector construction TEST_F(SpecularDetectorTest, basicBehaviour) { @@ -106,7 +109,7 @@ TEST_F(SpecularDetectorTest, SimulationElements) FixedBinAxis axis("axis0", 5, 1.0 * Units::deg, 10.0 * Units::deg); SpecularDetector1D detector(axis); Beam beam; - beam.setCentralK(1.0*Units::angstrom, 0.4*Units::deg, 0.0); + beam.setCentralK(1.0 * Units::angstrom, 0.4 * Units::deg, 0.0); auto sim_elements = detector.createSimulationElements(beam); @@ -135,7 +138,7 @@ TEST_F(SpecularDetectorTest, Clone) SpecularDetector1D detector(axis); std::unique_ptr<SpecularDetector1D> clone(detector.clone()); Beam beam; - beam.setCentralK(1.0*Units::angstrom, 0.4*Units::deg, 0.0); + beam.setCentralK(1.0 * Units::angstrom, 0.4 * Units::deg, 0.0); const auto data = clone->createDetectorMap(beam, AxesUnits::DEGREES); EXPECT_EQ(data->getAxis(0).size(), 5u); @@ -151,7 +154,7 @@ TEST_F(SpecularDetectorTest, Clone) const std::vector<size_t> expectedElementIndexes = expectedDetectorIndexes; std::vector<size_t> detectorIndexes; std::vector<size_t> elementIndexes; - for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) { + for (SimulationArea::iterator it = area.begin(); it != area.end(); ++it) { detectorIndexes.push_back(it.detectorIndex()); elementIndexes.push_back(it.elementIndex()); } diff --git a/Tests/UnitTests/Core/Detector/SphericalDetectorTest.h b/Tests/UnitTests/Core/Detector/SphericalDetectorTest.h index 36dadded99f..2b0ea9eae5a 100644 --- a/Tests/UnitTests/Core/Detector/SphericalDetectorTest.h +++ b/Tests/UnitTests/Core/Detector/SphericalDetectorTest.h @@ -1,26 +1,28 @@ -#include "SphericalDetector.h" +#include "google_test.h" +#include "Beam.h" +#include "BornAgainNamespace.h" +#include "ConvolutionDetectorResolution.h" +#include "DetectorFunctions.h" #include "Exceptions.h" -#include "OutputData.h" #include "FixedBinAxis.h" -#include "ConvolutionDetectorResolution.h" -#include "ResolutionFunction2DGaussian.h" +#include "OutputData.h" #include "Polygon.h" -#include "BornAgainNamespace.h" -#include "RegionOfInterest.h" #include "Rectangle.h" -#include "Units.h" -#include "Beam.h" +#include "RegionOfInterest.h" +#include "ResolutionFunction2DGaussian.h" #include "SimulationArea.h" -#include "DetectorFunctions.h" +#include "SphericalDetector.h" +#include "Units.h" #include <memory> class SphericalDetectorTest : public ::testing::Test { - protected: - SphericalDetectorTest(){} - virtual ~SphericalDetectorTest(){} +protected: + ~SphericalDetectorTest(); }; +SphericalDetectorTest::~SphericalDetectorTest() = default; + // Default detector construction TEST_F(SphericalDetectorTest, initialState) { @@ -31,8 +33,8 @@ TEST_F(SphericalDetectorTest, initialState) EXPECT_EQ(AxesUnits::RADIANS, detector.defaultAxesUnits()); // detector units - std::vector<AxesUnits> validUnits = - {AxesUnits::NBINS, AxesUnits::RADIANS, AxesUnits::DEGREES, AxesUnits::QYQZ}; + std::vector<AxesUnits> validUnits + = {AxesUnits::NBINS, AxesUnits::RADIANS, AxesUnits::DEGREES, AxesUnits::QYQZ}; EXPECT_EQ(validUnits, detector.validAxesUnits()); // masks @@ -48,8 +50,7 @@ TEST_F(SphericalDetectorTest, initialState) // behavior ASSERT_THROW(detector.getAxis(0), std::runtime_error); OutputData<double>* p_intensity_map(nullptr); - ASSERT_THROW(detector.applyDetectorResolution(p_intensity_map), - std::runtime_error); + ASSERT_THROW(detector.applyDetectorResolution(p_intensity_map), std::runtime_error); } // Construction of the detector with axes. @@ -63,12 +64,12 @@ TEST_F(SphericalDetectorTest, constructionWithAxes) // checking dimension and axes EXPECT_EQ(2u, detector.dimension()); - EXPECT_EQ(axis0.getMin(), detector.getAxis(0).getMin() ); - EXPECT_EQ(axis0.getMax(), detector.getAxis(0).getMax() ); - EXPECT_EQ(axis0.getName(), detector.getAxis(0).getName() ); - EXPECT_EQ(axis1.getName(), detector.getAxis(1).getName() ); - EXPECT_EQ(axis1.getMin(), detector.getAxis(1).getMin() ); - EXPECT_EQ(axis1.getMax(), detector.getAxis(1).getMax() ); + EXPECT_EQ(axis0.getMin(), detector.getAxis(0).getMin()); + EXPECT_EQ(axis0.getMax(), detector.getAxis(0).getMax()); + EXPECT_EQ(axis0.getName(), detector.getAxis(0).getName()); + EXPECT_EQ(axis1.getName(), detector.getAxis(1).getName()); + EXPECT_EQ(axis1.getMin(), detector.getAxis(1).getMin()); + EXPECT_EQ(axis1.getMax(), detector.getAxis(1).getMax()); // clearing detector detector.clear(); @@ -79,13 +80,13 @@ TEST_F(SphericalDetectorTest, constructionWithAxes) TEST_F(SphericalDetectorTest, constructionWithParameters) { SphericalDetector detector(10, -1.0, 1.0, 20, 0.0, 2.0); - EXPECT_EQ(10u, detector.getAxis(0).size() ); - EXPECT_EQ(-1.0, detector.getAxis(0).getMin() ); - EXPECT_EQ(1.0, detector.getAxis(0).getMax() ); + EXPECT_EQ(10u, detector.getAxis(0).size()); + EXPECT_EQ(-1.0, detector.getAxis(0).getMin()); + EXPECT_EQ(1.0, detector.getAxis(0).getMax()); EXPECT_EQ(BornAgain::PHI_AXIS_NAME, detector.getAxis(0).getName()); - EXPECT_EQ(20u, detector.getAxis(1).size() ); - EXPECT_EQ(0.0, detector.getAxis(1).getMin() ); - EXPECT_EQ(2.0, detector.getAxis(1).getMax() ); + EXPECT_EQ(20u, detector.getAxis(1).size()); + EXPECT_EQ(0.0, detector.getAxis(1).getMin()); + EXPECT_EQ(2.0, detector.getAxis(1).getMax()); EXPECT_EQ(BornAgain::ALPHA_AXIS_NAME, detector.getAxis(1).getName()); } @@ -98,33 +99,33 @@ TEST_F(SphericalDetectorTest, initOutputData) EXPECT_EQ(data.getAllocatedSize(), 200u); - EXPECT_EQ(10u, data.getAxis(0).size() ); - EXPECT_EQ(-1.0, data.getAxis(0).getMin() ); - EXPECT_EQ(1.0, data.getAxis(0).getMax() ); + EXPECT_EQ(10u, data.getAxis(0).size()); + EXPECT_EQ(-1.0, data.getAxis(0).getMin()); + EXPECT_EQ(1.0, data.getAxis(0).getMax()); EXPECT_EQ(BornAgain::PHI_AXIS_NAME, data.getAxis(0).getName()); - EXPECT_EQ(20u, data.getAxis(1).size() ); - EXPECT_EQ(0.0, data.getAxis(1).getMin() ); - EXPECT_EQ(2.0, data.getAxis(1).getMax() ); + EXPECT_EQ(20u, data.getAxis(1).size()); + EXPECT_EQ(0.0, data.getAxis(1).getMin()); + EXPECT_EQ(2.0, data.getAxis(1).getMax()); EXPECT_EQ(BornAgain::ALPHA_AXIS_NAME, data.getAxis(1).getName()); } // Creation of the detector map with axes in given units TEST_F(SphericalDetectorTest, createDetectorMap) { - SphericalDetector detector(10, -1.0*Units::deg, 1.0*Units::deg, - 20, 0.0*Units::deg, 2.0*Units::deg); + SphericalDetector detector(10, -1.0 * Units::deg, 1.0 * Units::deg, 20, 0.0 * Units::deg, + 2.0 * Units::deg); Beam beam; - beam.setCentralK(1.0*Units::angstrom, 0.4*Units::deg, 0.0); + beam.setCentralK(1.0 * Units::angstrom, 0.4 * Units::deg, 0.0); // creating map in default units, which are radians and checking axes auto data = detector.createDetectorMap(beam, AxesUnits::DEFAULT); EXPECT_EQ(data->getAxis(0).size(), 10u); - EXPECT_EQ(data->getAxis(0).getMin(), -1.0*Units::deg); - EXPECT_EQ(data->getAxis(0).getMax(), 1.0*Units::deg); + EXPECT_EQ(data->getAxis(0).getMin(), -1.0 * Units::deg); + EXPECT_EQ(data->getAxis(0).getMax(), 1.0 * Units::deg); EXPECT_EQ(data->getAxis(1).size(), 20u); - EXPECT_EQ(data->getAxis(1).getMin(), 0.0*Units::deg); - EXPECT_EQ(data->getAxis(1).getMax(), 2.0*Units::deg); + EXPECT_EQ(data->getAxis(1).getMin(), 0.0 * Units::deg); + EXPECT_EQ(data->getAxis(1).getMax(), 2.0 * Units::deg); // creating map in degrees and checking axes data = detector.createDetectorMap(beam, AxesUnits::DEGREES); @@ -200,22 +201,23 @@ TEST_F(SphericalDetectorTest, regionOfInterestAndData) // Create detector map in the presence of region of interest. TEST_F(SphericalDetectorTest, regionOfInterestAndDetectorMap) { - SphericalDetector detector(6, -1.0*Units::deg, 5.0*Units::deg, - 4, 0.0*Units::deg, 4.0*Units::deg); + SphericalDetector detector(6, -1.0 * Units::deg, 5.0 * Units::deg, 4, 0.0 * Units::deg, + 4.0 * Units::deg); - detector.setRegionOfInterest(0.1*Units::deg, 1.1*Units::deg, 3.0*Units::deg, 2.9*Units::deg); + detector.setRegionOfInterest(0.1 * Units::deg, 1.1 * Units::deg, 3.0 * Units::deg, + 2.9 * Units::deg); Beam beam; - beam.setCentralK(1.0*Units::angstrom, 0.4*Units::deg, 0.0); + beam.setCentralK(1.0 * Units::angstrom, 0.4 * Units::deg, 0.0); // Creating map in default units, which are radians and checking that axes are clipped // to region of interest. auto data = detector.createDetectorMap(beam, AxesUnits::DEFAULT); EXPECT_EQ(data->getAxis(0).size(), 4u); - EXPECT_EQ(data->getAxis(0).getMin(), 0.0*Units::deg); - EXPECT_EQ(data->getAxis(0).getMax(), 4.0*Units::deg); + EXPECT_EQ(data->getAxis(0).getMin(), 0.0 * Units::deg); + EXPECT_EQ(data->getAxis(0).getMax(), 4.0 * Units::deg); EXPECT_EQ(data->getAxis(1).size(), 2u); - EXPECT_EQ(data->getAxis(1).getMin(), 1.0*Units::deg); - EXPECT_EQ(data->getAxis(1).getMax(), 3.0*Units::deg); + EXPECT_EQ(data->getAxis(1).getMin(), 1.0 * Units::deg); + EXPECT_EQ(data->getAxis(1).getMax(), 3.0 * Units::deg); // Creating map with axes in degrees, and checking that it is clipped to the region of interest data = detector.createDetectorMap(beam, AxesUnits::DEGREES); @@ -230,36 +232,38 @@ TEST_F(SphericalDetectorTest, regionOfInterestAndDetectorMap) // Checking IDetector2D::getIntensityData in the presence of region of interest. TEST_F(SphericalDetectorTest, getIntensityData) { - SphericalDetector detector(6, -1.0*Units::deg, 5.0*Units::deg, - 4, 0.0*Units::deg, 4.0*Units::deg); - detector.setRegionOfInterest(0.1*Units::deg, 1.1*Units::deg, 3.0*Units::deg, 2.9*Units::deg); + SphericalDetector detector(6, -1.0 * Units::deg, 5.0 * Units::deg, 4, 0.0 * Units::deg, + 4.0 * Units::deg); + detector.setRegionOfInterest(0.1 * Units::deg, 1.1 * Units::deg, 3.0 * Units::deg, + 2.9 * Units::deg); Beam beam; - beam.setCentralK(1.0*Units::angstrom, 0.4*Units::deg, 0.0); + beam.setCentralK(1.0 * Units::angstrom, 0.4 * Units::deg, 0.0); // Initializing data (no region of interest involved yet) and filling with amplitudes OutputData<double> intensityData; detector.initOutputData(intensityData); EXPECT_EQ(intensityData.getAllocatedSize(), 24u); - for(size_t i=0; i<intensityData.getAllocatedSize(); ++i) { + for (size_t i = 0; i < intensityData.getAllocatedSize(); ++i) { intensityData[i] = static_cast<double>(i); } - EXPECT_EQ(intensityData[intensityData.getAllocatedSize()-1], 23.0); + EXPECT_EQ(intensityData[intensityData.getAllocatedSize() - 1], 23.0); // Getting detectorIntensity and checking that amplitudes are correct and it is clipped to // region of interest. -// std::unique_ptr<OutputData<double>> detectorIntensity( -// detector.getDetectorIntensity(intensityData, beam, DetectorAxesUnits::DEGREES)); - -// EXPECT_EQ(detectorIntensity->getAllocatedSize(), 8); -// EXPECT_EQ((*detectorIntensity)[0], 5.0); -// EXPECT_EQ((*detectorIntensity)[7], 18.0); -// EXPECT_EQ(detectorIntensity->getAxis(0).size(), 4); -// EXPECT_EQ(detectorIntensity->getAxis(0).getMin(), 0.0); -// EXPECT_EQ(detectorIntensity->getAxis(0).getMax(), 4.0); -// EXPECT_EQ(detectorIntensity->getAxis(1).size(), 2); -// EXPECT_EQ(detectorIntensity->getAxis(1).getMin(), 1.0); -// EXPECT_EQ(detectorIntensity->getAxis(1).getMax(), 3.0); + // std::unique_ptr<OutputData<double>> detectorIntensity( + // detector.getDetectorIntensity(intensityData, beam, + // DetectorAxesUnits::DEGREES)); + + // EXPECT_EQ(detectorIntensity->getAllocatedSize(), 8); + // EXPECT_EQ((*detectorIntensity)[0], 5.0); + // EXPECT_EQ((*detectorIntensity)[7], 18.0); + // EXPECT_EQ(detectorIntensity->getAxis(0).size(), 4); + // EXPECT_EQ(detectorIntensity->getAxis(0).getMin(), 0.0); + // EXPECT_EQ(detectorIntensity->getAxis(0).getMax(), 4.0); + // EXPECT_EQ(detectorIntensity->getAxis(1).size(), 2); + // EXPECT_EQ(detectorIntensity->getAxis(1).getMin(), 1.0); + // EXPECT_EQ(detectorIntensity->getAxis(1).getMax(), 3.0); } TEST_F(SphericalDetectorTest, MaskOfDetector) @@ -274,11 +278,11 @@ TEST_F(SphericalDetectorTest, MaskOfDetector) Polygon polygon(x, y); detector.addMask(polygon, true); - const OutputData<bool> *mask = detector.detectorMask()->getMaskData(); - for(size_t index=0; index<mask->getAllocatedSize(); ++index) { + const OutputData<bool>* mask = detector.detectorMask()->getMaskData(); + for (size_t index = 0; index < mask->getAllocatedSize(); ++index) { double x = mask->getAxisValue(index, 0); double y = mask->getAxisValue(index, 1); - if( x>= -4.0 && x <=4.0 && y>=-2.0 && y<=2.0) { + if (x >= -4.0 && x <= 4.0 && y >= -2.0 && y <= 2.0) { EXPECT_TRUE(detector.detectorMask()->isMasked(index)); } else { EXPECT_FALSE(detector.detectorMask()->isMasked(index)); @@ -287,10 +291,10 @@ TEST_F(SphericalDetectorTest, MaskOfDetector) SphericalDetector detector2(detector); mask = detector2.detectorMask()->getMaskData(); - for(size_t index=0; index<mask->getAllocatedSize(); ++index) { + for (size_t index = 0; index < mask->getAllocatedSize(); ++index) { double x = mask->getAxisValue(index, 0); double y = mask->getAxisValue(index, 1); - if( x>= -4.0 && x <=4.0 && y>=-2.0 && y<=2.0) { + if (x >= -4.0 && x <= 4.0 && y >= -2.0 && y <= 2.0) { EXPECT_TRUE(detector2.detectorMask()->isMasked(index)); } else { EXPECT_FALSE(detector2.detectorMask()->isMasked(index)); @@ -298,10 +302,10 @@ TEST_F(SphericalDetectorTest, MaskOfDetector) } mask = detector.detectorMask()->getMaskData(); - for(size_t index=0; index<mask->getAllocatedSize(); ++index) { + for (size_t index = 0; index < mask->getAllocatedSize(); ++index) { double x = mask->getAxisValue(index, 0); double y = mask->getAxisValue(index, 1); - if( x>= -4.0 && x <=4.0 && y>=-2.0 && y<=2.0) { + if (x >= -4.0 && x <= 4.0 && y >= -2.0 && y <= 2.0) { EXPECT_TRUE(detector.detectorMask()->isMasked(index)); } else { EXPECT_FALSE(detector.detectorMask()->isMasked(index)); @@ -313,15 +317,18 @@ TEST_F(SphericalDetectorTest, MaskOfDetector) TEST_F(SphericalDetectorTest, Clone) { Beam beam; - beam.setCentralK(1.0*Units::angstrom, 0.4*Units::deg, 0.0); - - SphericalDetector detector(6, -1.0*Units::deg, 5.0*Units::deg, - 4, 0.0*Units::deg, 4.0*Units::deg); - detector.setRegionOfInterest(0.1*Units::deg, 1.1*Units::deg, 3.0*Units::deg, 2.9*Units::deg); - detector.addMask(Rectangle(-0.9*Units::deg, 0.1*Units::deg, 0.9*Units::deg, 1.9*Units::deg), true); - detector.addMask(Rectangle(3.1*Units::deg, 2.1*Units::deg, 4.9*Units::deg, 3.9*Units::deg), true); - detector.setDetectorResolution(ConvolutionDetectorResolution( - ResolutionFunction2DGaussian(1,1))); + beam.setCentralK(1.0 * Units::angstrom, 0.4 * Units::deg, 0.0); + + SphericalDetector detector(6, -1.0 * Units::deg, 5.0 * Units::deg, 4, 0.0 * Units::deg, + 4.0 * Units::deg); + detector.setRegionOfInterest(0.1 * Units::deg, 1.1 * Units::deg, 3.0 * Units::deg, + 2.9 * Units::deg); + detector.addMask( + Rectangle(-0.9 * Units::deg, 0.1 * Units::deg, 0.9 * Units::deg, 1.9 * Units::deg), true); + detector.addMask( + Rectangle(3.1 * Units::deg, 2.1 * Units::deg, 4.9 * Units::deg, 3.9 * Units::deg), true); + detector.setDetectorResolution( + ConvolutionDetectorResolution(ResolutionFunction2DGaussian(1, 1))); std::unique_ptr<SphericalDetector> clone(detector.clone()); @@ -333,8 +340,7 @@ TEST_F(SphericalDetectorTest, Clone) EXPECT_EQ(data->getAxis(1).getMin(), 1.0); EXPECT_EQ(data->getAxis(1).getMax(), 3.0); - EXPECT_EQ(std::string("ConvolutionDetectorResolution"), - clone->detectorResolution()->getName()); + EXPECT_EQ(std::string("ConvolutionDetectorResolution"), clone->detectorResolution()->getName()); EXPECT_EQ(clone->detectorMask()->numberOfMaskedChannels(), 8); @@ -344,7 +350,7 @@ TEST_F(SphericalDetectorTest, Clone) std::vector<size_t> expectedElementIndexes = {0, 1, 2, 3, 4, 5}; std::vector<size_t> detectorIndexes; std::vector<size_t> elementIndexes; - for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) { + for (SimulationArea::iterator it = area.begin(); it != area.end(); ++it) { detectorIndexes.push_back(it.detectorIndex()); elementIndexes.push_back(it.elementIndex()); } @@ -369,8 +375,8 @@ TEST_F(SphericalDetectorTest, nameToUnitTranslation) // Test retrieval of analyzer properties TEST_F(SphericalDetectorTest, AnalyzerProperties) { - SphericalDetector detector(6, -1.0*Units::deg, 5.0*Units::deg, - 4, 0.0*Units::deg, 4.0*Units::deg); + SphericalDetector detector(6, -1.0 * Units::deg, 5.0 * Units::deg, 4, 0.0 * Units::deg, + 4.0 * Units::deg); kvector_t direction; double efficiency = 0.0; diff --git a/Tests/UnitTests/Core/ExportToPython/PythonFormattingTest.h b/Tests/UnitTests/Core/ExportToPython/PythonFormattingTest.h index 61dbaf206d3..6571aef8fc6 100644 --- a/Tests/UnitTests/Core/ExportToPython/PythonFormattingTest.h +++ b/Tests/UnitTests/Core/ExportToPython/PythonFormattingTest.h @@ -1,23 +1,26 @@ -#include "PythonFormatting.h" +#include "google_test.h" #include "BornAgainNamespace.h" -#include "Units.h" -#include "RealLimits.h" #include "Distributions.h" #include "ParameterDistribution.h" +#include "PythonFormatting.h" +#include "RealLimits.h" +#include "Units.h" class PythonFormattingTest : public ::testing::Test { public: + ~PythonFormattingTest(); }; +PythonFormattingTest::~PythonFormattingTest() = default; + TEST_F(PythonFormattingTest, ValueTimesUnits) { EXPECT_EQ("2.0*nm", PythonFormatting::printValue(2.0, BornAgain::UnitsNm)); - EXPECT_EQ("2.0*deg", PythonFormatting::printValue(2.0*Units::deg, BornAgain::UnitsRad)); + EXPECT_EQ("2.0*deg", PythonFormatting::printValue(2.0 * Units::deg, BornAgain::UnitsRad)); EXPECT_EQ("2.0", PythonFormatting::printValue(2.0, BornAgain::UnitsNone)); } - TEST_F(PythonFormattingTest, RealLimits) { EXPECT_EQ("RealLimits.positive()", PythonFormatting::printRealLimits(RealLimits::positive())); @@ -55,7 +58,6 @@ TEST_F(PythonFormattingTest, RealLimits) RealLimits::limited(1.0 * Units::deg, 2.0 * Units::deg), BornAgain::UnitsRad)); EXPECT_EQ("", PythonFormatting::printRealLimitsArg(RealLimits::limitless())); - } TEST_F(PythonFormattingTest, printDistribution) @@ -75,7 +77,6 @@ TEST_F(PythonFormattingTest, printDistribution) "ba.DistributionLogNormal(1.0*deg, 0.01)"); } - TEST_F(PythonFormattingTest, printParameterDistribution) { @@ -100,10 +101,8 @@ TEST_F(PythonFormattingTest, printParameterDistribution) // RealLimits defined, checking that method guess radians units correctly ParameterDistribution dist4("/Particle/ZRotation/Angle", gate, 5, 2.0, - RealLimits::limited(1.0*Units::deg, 2.0*Units::deg)); + RealLimits::limited(1.0 * Units::deg, 2.0 * Units::deg)); EXPECT_EQ(PythonFormatting::printParameterDistribution(dist4, "distr_1", BornAgain::UnitsRad), "ba.ParameterDistribution(\"/Particle/ZRotation/Angle\", " "distr_1, 5, 2.0, ba.RealLimits.limited(1.0*deg, 2.0*deg))"); - - } diff --git a/Tests/UnitTests/Core/Fresnel/MatrixRTCoefficientsTest.h b/Tests/UnitTests/Core/Fresnel/MatrixRTCoefficientsTest.h index 830809346aa..a77ca0aac99 100644 --- a/Tests/UnitTests/Core/Fresnel/MatrixRTCoefficientsTest.h +++ b/Tests/UnitTests/Core/Fresnel/MatrixRTCoefficientsTest.h @@ -1,22 +1,20 @@ #include "MatrixRTCoefficients.h" +#include "google_test.h" -class MatrixRTCoefficientsTest : public ::testing :: Test +class MatrixRTCoefficientsTest : public ::testing::Test { protected: - MatrixRTCoefficientsTest(); - virtual ~MatrixRTCoefficientsTest(){} + ~MatrixRTCoefficientsTest(); MatrixRTCoefficients mrtcDefault; }; -MatrixRTCoefficientsTest::MatrixRTCoefficientsTest() -{ -} +MatrixRTCoefficientsTest::~MatrixRTCoefficientsTest() = default; TEST_F(MatrixRTCoefficientsTest, T1plus) { Eigen::Vector2cd vector = mrtcDefault.T1plus(); - EXPECT_EQ(complex_t(0.5,0.0), vector(0)); + EXPECT_EQ(complex_t(0.5, 0.0), vector(0)); EXPECT_EQ(0.0, vector(1)); } @@ -24,13 +22,13 @@ TEST_F(MatrixRTCoefficientsTest, T1min) { Eigen::Vector2cd vector = mrtcDefault.T1min(); EXPECT_EQ(0.0, vector(0)); - EXPECT_EQ(complex_t(0.5,0.0), vector(1)); + EXPECT_EQ(complex_t(0.5, 0.0), vector(1)); } TEST_F(MatrixRTCoefficientsTest, T2plus) { Eigen::Vector2cd vector = mrtcDefault.T2plus(); - EXPECT_EQ(complex_t(0.5,0.0), vector(0)); + EXPECT_EQ(complex_t(0.5, 0.0), vector(0)); EXPECT_EQ(0.0, vector(1)); } @@ -38,14 +36,13 @@ TEST_F(MatrixRTCoefficientsTest, T2min) { Eigen::Vector2cd vector = mrtcDefault.T2min(); EXPECT_EQ(0.0, vector(0)); - EXPECT_EQ(complex_t(0.5,0.0), vector(1)); + EXPECT_EQ(complex_t(0.5, 0.0), vector(1)); } - TEST_F(MatrixRTCoefficientsTest, R1plus) { Eigen::Vector2cd vector = mrtcDefault.R1plus(); - EXPECT_EQ(complex_t(-0.5,0.0), vector(0)); + EXPECT_EQ(complex_t(-0.5, 0.0), vector(0)); EXPECT_EQ(0.0, vector(1)); } @@ -53,13 +50,13 @@ TEST_F(MatrixRTCoefficientsTest, R1min) { Eigen::Vector2cd vector = mrtcDefault.R1min(); EXPECT_EQ(0.0, vector(0)); - EXPECT_EQ(complex_t(-0.5,0.0), vector(1)); + EXPECT_EQ(complex_t(-0.5, 0.0), vector(1)); } TEST_F(MatrixRTCoefficientsTest, R2plus) { Eigen::Vector2cd vector = mrtcDefault.R2plus(); - EXPECT_EQ(complex_t(-0.5,0.0), vector(0)); + EXPECT_EQ(complex_t(-0.5, 0.0), vector(0)); EXPECT_EQ(0.0, vector(1)); } @@ -67,12 +64,12 @@ TEST_F(MatrixRTCoefficientsTest, R2min) { Eigen::Vector2cd vector = mrtcDefault.R2min(); EXPECT_EQ(0.0, vector(0)); - EXPECT_EQ(complex_t(-0.5,0.0), vector(1)); + EXPECT_EQ(complex_t(-0.5, 0.0), vector(1)); } TEST_F(MatrixRTCoefficientsTest, getKz) { Eigen::Vector2cd vector = mrtcDefault.getKz(); - EXPECT_EQ(complex_t(0.0,0.0), vector(0)); - EXPECT_EQ(complex_t(0.0,0.0), vector(1)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(0)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(1)); } diff --git a/Tests/UnitTests/Core/Fresnel/ScalarRTCoefficientsTest.h b/Tests/UnitTests/Core/Fresnel/ScalarRTCoefficientsTest.h index 6b3b3f7c08c..b93c1d896e4 100644 --- a/Tests/UnitTests/Core/Fresnel/ScalarRTCoefficientsTest.h +++ b/Tests/UnitTests/Core/Fresnel/ScalarRTCoefficientsTest.h @@ -1,14 +1,14 @@ +#include "google_test.h" #include "ScalarRTCoefficients.h" -class ScalarRTCoefficientsTest : public ::testing :: Test +class ScalarRTCoefficientsTest : public ::testing::Test { protected: ScalarRTCoefficientsTest(); - virtual ~ScalarRTCoefficientsTest(){} + ~ScalarRTCoefficientsTest(); ScalarRTCoefficients scrtDefault; ScalarRTCoefficients scrtCustom; - }; ScalarRTCoefficientsTest::ScalarRTCoefficientsTest() @@ -19,14 +19,16 @@ ScalarRTCoefficientsTest::ScalarRTCoefficientsTest() scrtCustom.t_r(1) = complex_t(1.0, 0.5); } +ScalarRTCoefficientsTest::~ScalarRTCoefficientsTest() = default; + TEST_F(ScalarRTCoefficientsTest, T1plus) { Eigen::Vector2cd vector = scrtDefault.T1plus(); - EXPECT_EQ(complex_t(0.0,0.0), vector(0)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(0)); EXPECT_EQ(0.0, vector(1)); Eigen::Vector2cd vector2 = scrtCustom.T1plus(); - EXPECT_EQ(complex_t(0.0,0.0), vector2(0)); + EXPECT_EQ(complex_t(0.0, 0.0), vector2(0)); EXPECT_EQ(0.0, vector2(1)); } @@ -34,17 +36,17 @@ TEST_F(ScalarRTCoefficientsTest, T1min) { Eigen::Vector2cd vector = scrtDefault.T1min(); EXPECT_EQ(0.0, vector(0)); - EXPECT_EQ(complex_t(1.0,0.0), vector(1)); + EXPECT_EQ(complex_t(1.0, 0.0), vector(1)); Eigen::Vector2cd vector2 = scrtCustom.T1min(); EXPECT_EQ(0.0, vector2(0)); - EXPECT_EQ(complex_t(0.0,0.5), vector2(1)); + EXPECT_EQ(complex_t(0.0, 0.5), vector2(1)); } TEST_F(ScalarRTCoefficientsTest, T2plus) { Eigen::Vector2cd vector = scrtDefault.T2plus(); - EXPECT_EQ(complex_t(1.0,0.0), vector(0)); + EXPECT_EQ(complex_t(1.0, 0.0), vector(0)); EXPECT_EQ(0.0, vector(1)); Eigen::Vector2cd vector2 = scrtCustom.T2plus(); @@ -56,22 +58,21 @@ TEST_F(ScalarRTCoefficientsTest, T2min) { Eigen::Vector2cd vector = scrtDefault.T2min(); EXPECT_EQ(0.0, vector(0)); - EXPECT_EQ(complex_t(0.0,0.0), vector(1)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(1)); Eigen::Vector2cd vector2 = scrtCustom.T2min(); EXPECT_EQ(0.0, vector2(0)); - EXPECT_EQ(complex_t(0.0,0.0), vector2(1)); + EXPECT_EQ(complex_t(0.0, 0.0), vector2(1)); } - TEST_F(ScalarRTCoefficientsTest, R1plus) { Eigen::Vector2cd vector = scrtDefault.R1plus(); - EXPECT_EQ(complex_t(0.0,0.0), vector(0)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(0)); EXPECT_EQ(0.0, vector(1)); Eigen::Vector2cd vector2 = scrtCustom.R1plus(); - EXPECT_EQ(complex_t(0.0,0.0), vector2(0)); + EXPECT_EQ(complex_t(0.0, 0.0), vector2(0)); EXPECT_EQ(0.0, vector2(1)); } @@ -79,11 +80,11 @@ TEST_F(ScalarRTCoefficientsTest, R1min) { Eigen::Vector2cd vector = scrtDefault.R1min(); EXPECT_EQ(0.0, vector(0)); - EXPECT_EQ(complex_t(0.0,0.0), vector(1)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(1)); Eigen::Vector2cd vector2 = scrtCustom.R1min(); EXPECT_EQ(0.0, vector2(0)); - EXPECT_EQ(complex_t(1.0,0.5), vector2(1)); + EXPECT_EQ(complex_t(1.0, 0.5), vector2(1)); } TEST_F(ScalarRTCoefficientsTest, R2plus) @@ -93,7 +94,7 @@ TEST_F(ScalarRTCoefficientsTest, R2plus) EXPECT_EQ(0.0, vector(1)); Eigen::Vector2cd vector2 = scrtCustom.R2plus(); - EXPECT_EQ(complex_t(1.0,0.5), vector2(0)); + EXPECT_EQ(complex_t(1.0, 0.5), vector2(0)); EXPECT_EQ(0.0, vector2(1)); } @@ -101,31 +102,31 @@ TEST_F(ScalarRTCoefficientsTest, R2min) { Eigen::Vector2cd vector = scrtDefault.R2min(); EXPECT_EQ(0.0, vector(0)); - EXPECT_EQ(complex_t(0.0,0.0), vector(1)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(1)); Eigen::Vector2cd vector2 = scrtCustom.R2min(); EXPECT_EQ(0.0, vector2(0)); - EXPECT_EQ(complex_t(0.0,0.0), vector2(1)); + EXPECT_EQ(complex_t(0.0, 0.0), vector2(1)); } TEST_F(ScalarRTCoefficientsTest, getKz) { Eigen::Vector2cd vector = scrtDefault.getKz(); - EXPECT_EQ(complex_t(0.0,0.0), vector(0)); - EXPECT_EQ(complex_t(0.0,0.0), vector(1)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(0)); + EXPECT_EQ(complex_t(0.0, 0.0), vector(1)); Eigen::Vector2cd vector2 = scrtCustom.getKz(); - EXPECT_EQ(complex_t(1.0,1.0), vector2(0)); - EXPECT_EQ(complex_t(1.0,1.0), vector2(1)); + EXPECT_EQ(complex_t(1.0, 1.0), vector2(0)); + EXPECT_EQ(complex_t(1.0, 1.0), vector2(1)); } TEST_F(ScalarRTCoefficientsTest, getScalar) { - EXPECT_EQ(complex_t(1.0,0.0), scrtDefault.getScalarT()); - EXPECT_EQ(complex_t(0.0,0.0), scrtDefault.getScalarR()); - EXPECT_EQ(complex_t(0.0,0.0), scrtDefault.getScalarKz()); + EXPECT_EQ(complex_t(1.0, 0.0), scrtDefault.getScalarT()); + EXPECT_EQ(complex_t(0.0, 0.0), scrtDefault.getScalarR()); + EXPECT_EQ(complex_t(0.0, 0.0), scrtDefault.getScalarKz()); - EXPECT_EQ(complex_t(0.0,0.5), scrtCustom.getScalarT()); - EXPECT_EQ(complex_t(1.0,0.5), scrtCustom.getScalarR()); - EXPECT_EQ(complex_t(1.0,1.0), scrtCustom.getScalarKz()); + EXPECT_EQ(complex_t(0.0, 0.5), scrtCustom.getScalarT()); + EXPECT_EQ(complex_t(1.0, 0.5), scrtCustom.getScalarR()); + EXPECT_EQ(complex_t(1.0, 1.0), scrtCustom.getScalarKz()); } diff --git a/Tests/UnitTests/Core/Fresnel/SpecularMagneticTest.h b/Tests/UnitTests/Core/Fresnel/SpecularMagneticTest.h index 3b18fefab48..d907c871889 100644 --- a/Tests/UnitTests/Core/Fresnel/SpecularMagneticTest.h +++ b/Tests/UnitTests/Core/Fresnel/SpecularMagneticTest.h @@ -1,16 +1,18 @@ -#include "SpecularMatrix.h" -#include "SpecularMagnetic.h" +#include "google_test.h" +#include "Layer.h" #include "MaterialFactoryFuncs.h" +#include "MultiLayer.h" +#include "SpecularMagnetic.h" +#include "SpecularMatrix.h" #include "Units.h" -class SpecularMagneticTest : public ::testing :: Test +class SpecularMagneticTest : public ::testing::Test { protected: - SpecularMagneticTest(); - virtual ~SpecularMagneticTest(){} + ~SpecularMagneticTest(); }; -SpecularMagneticTest::SpecularMagneticTest() {} +SpecularMagneticTest::~SpecularMagneticTest() = default; TEST_F(SpecularMagneticTest, initial) { @@ -19,11 +21,10 @@ TEST_F(SpecularMagneticTest, initial) std::vector<MatrixRTCoefficients> coeff; // @Error: Throws exception (Layer index is out of bounds) - //matrix.execute(mLayer, v, coeff); - + // matrix.execute(mLayer, v, coeff); - Material air = HomogeneousMaterial("air",0,1.0); - Layer layer0(air, 0*Units::nanometer); + Material air = HomogeneousMaterial("air", 0, 1.0); + Layer layer0(air, 0 * Units::nanometer); mLayer.addLayer(layer0); SpecularMagnetic::execute(mLayer, v, coeff); @@ -34,9 +35,9 @@ TEST_F(SpecularMagneticTest, zerofield) double eps = 1e-10; kvector_t substr_field(0.0, 0.0, 0.0); - kvector_t k1 = vecOfLambdaAlphaPhi(1.0, -0.1*Units::deg, 0.0); - kvector_t k2 = vecOfLambdaAlphaPhi(1.0, -2.0*Units::deg, 0.0); - kvector_t k3 = vecOfLambdaAlphaPhi(1.0, -10.0*Units::deg, 0.0); + kvector_t k1 = vecOfLambdaAlphaPhi(1.0, -0.1 * Units::deg, 0.0); + kvector_t k2 = vecOfLambdaAlphaPhi(1.0, -2.0 * Units::deg, 0.0); + kvector_t k3 = vecOfLambdaAlphaPhi(1.0, -10.0 * Units::deg, 0.0); MultiLayer multi_layer_scalar; Material substr_material_scalar = HomogeneousMaterial("Substrate", 7e-6, 2e-8); @@ -68,14 +69,14 @@ TEST_F(SpecularMagneticTest, zerofield) Eigen::Vector2cd TMM = RTMatrix.T1min() + RTMatrix.T2min(); Eigen::Vector2cd RMM = RTMatrix.R1min() + RTMatrix.R2min(); - EXPECT_NEAR(0.0, std::abs(TPS(0)-TPM(0)), eps); - EXPECT_NEAR(0.0, std::abs(TPS(1)-TPM(1)), eps); - EXPECT_NEAR(0.0, std::abs(RPS(0)-RPM(0)), eps); - EXPECT_NEAR(0.0, std::abs(RPS(1)-RPM(1)), eps); - EXPECT_NEAR(0.0, std::abs(TMS(0)-TMM(0)), eps); - EXPECT_NEAR(0.0, std::abs(TMS(1)-TMM(1)), eps); - EXPECT_NEAR(0.0, std::abs(RMS(0)-RMM(0)), eps); - EXPECT_NEAR(0.0, std::abs(RMS(1)-RMM(1)), eps); + EXPECT_NEAR(0.0, std::abs(TPS(0) - TPM(0)), eps); + EXPECT_NEAR(0.0, std::abs(TPS(1) - TPM(1)), eps); + EXPECT_NEAR(0.0, std::abs(RPS(0) - RPM(0)), eps); + EXPECT_NEAR(0.0, std::abs(RPS(1) - RPM(1)), eps); + EXPECT_NEAR(0.0, std::abs(TMS(0) - TMM(0)), eps); + EXPECT_NEAR(0.0, std::abs(TMS(1) - TMM(1)), eps); + EXPECT_NEAR(0.0, std::abs(RMS(0) - RMM(0)), eps); + EXPECT_NEAR(0.0, std::abs(RMS(1) - RMM(1)), eps); // k2 SpecularMatrix::execute(multi_layer_scalar, k2, coeffs_scalar); @@ -92,14 +93,14 @@ TEST_F(SpecularMagneticTest, zerofield) TMM = RTMatrix.T1min() + RTMatrix.T2min(); RMM = RTMatrix.R1min() + RTMatrix.R2min(); - EXPECT_NEAR(0.0, std::abs(TPS(0)-TPM(0)), eps); - EXPECT_NEAR(0.0, std::abs(TPS(1)-TPM(1)), eps); - EXPECT_NEAR(0.0, std::abs(RPS(0)-RPM(0)), eps); - EXPECT_NEAR(0.0, std::abs(RPS(1)-RPM(1)), eps); - EXPECT_NEAR(0.0, std::abs(TMS(0)-TMM(0)), eps); - EXPECT_NEAR(0.0, std::abs(TMS(1)-TMM(1)), eps); - EXPECT_NEAR(0.0, std::abs(RMS(0)-RMM(0)), eps); - EXPECT_NEAR(0.0, std::abs(RMS(1)-RMM(1)), eps); + EXPECT_NEAR(0.0, std::abs(TPS(0) - TPM(0)), eps); + EXPECT_NEAR(0.0, std::abs(TPS(1) - TPM(1)), eps); + EXPECT_NEAR(0.0, std::abs(RPS(0) - RPM(0)), eps); + EXPECT_NEAR(0.0, std::abs(RPS(1) - RPM(1)), eps); + EXPECT_NEAR(0.0, std::abs(TMS(0) - TMM(0)), eps); + EXPECT_NEAR(0.0, std::abs(TMS(1) - TMM(1)), eps); + EXPECT_NEAR(0.0, std::abs(RMS(0) - RMM(0)), eps); + EXPECT_NEAR(0.0, std::abs(RMS(1) - RMM(1)), eps); // k3 SpecularMatrix::execute(multi_layer_scalar, k3, coeffs_scalar); @@ -116,12 +117,12 @@ TEST_F(SpecularMagneticTest, zerofield) TMM = RTMatrix.T1min() + RTMatrix.T2min(); RMM = RTMatrix.R1min() + RTMatrix.R2min(); - EXPECT_NEAR(0.0, std::abs(TPS(0)-TPM(0)), eps); - EXPECT_NEAR(0.0, std::abs(TPS(1)-TPM(1)), eps); - EXPECT_NEAR(0.0, std::abs(RPS(0)-RPM(0)), eps); - EXPECT_NEAR(0.0, std::abs(RPS(1)-RPM(1)), eps); - EXPECT_NEAR(0.0, std::abs(TMS(0)-TMM(0)), eps); - EXPECT_NEAR(0.0, std::abs(TMS(1)-TMM(1)), eps); - EXPECT_NEAR(0.0, std::abs(RMS(0)-RMM(0)), eps); - EXPECT_NEAR(0.0, std::abs(RMS(1)-RMM(1)), eps); + EXPECT_NEAR(0.0, std::abs(TPS(0) - TPM(0)), eps); + EXPECT_NEAR(0.0, std::abs(TPS(1) - TPM(1)), eps); + EXPECT_NEAR(0.0, std::abs(RPS(0) - RPM(0)), eps); + EXPECT_NEAR(0.0, std::abs(RPS(1) - RPM(1)), eps); + EXPECT_NEAR(0.0, std::abs(TMS(0) - TMM(0)), eps); + EXPECT_NEAR(0.0, std::abs(TMS(1) - TMM(1)), eps); + EXPECT_NEAR(0.0, std::abs(RMS(0) - RMM(0)), eps); + EXPECT_NEAR(0.0, std::abs(RMS(1) - RMM(1)), eps); } diff --git a/Tests/UnitTests/Core/Fresnel/SpecularMatrixTest.h b/Tests/UnitTests/Core/Fresnel/SpecularMatrixTest.h index 3a35d6b5334..f18df386b94 100644 --- a/Tests/UnitTests/Core/Fresnel/SpecularMatrixTest.h +++ b/Tests/UnitTests/Core/Fresnel/SpecularMatrixTest.h @@ -1,15 +1,17 @@ -#include "SpecularMatrix.h" +#include "google_test.h" +#include "Layer.h" +#include "MultiLayer.h" #include "MaterialFactoryFuncs.h" +#include "SpecularMatrix.h" #include "Units.h" -class SpecularMatrixTest : public ::testing :: Test +class SpecularMatrixTest : public ::testing::Test { protected: - SpecularMatrixTest(); - virtual ~SpecularMatrixTest(){} + ~SpecularMatrixTest(); }; -SpecularMatrixTest::SpecularMatrixTest() {} +SpecularMatrixTest::~SpecularMatrixTest() = default; TEST_F(SpecularMatrixTest, initial) { @@ -18,9 +20,9 @@ TEST_F(SpecularMatrixTest, initial) std::vector<ScalarRTCoefficients> coeff; // @Error: Throws exception (Layer index is out of bounds) - //matrix.execute(mLayer, v, coeff); + // matrix.execute(mLayer, v, coeff); - Layer layer0(HomogeneousMaterial("air",0,1.0), 0*Units::nanometer); + Layer layer0(HomogeneousMaterial("air", 0, 1.0), 0 * Units::nanometer); mLayer.addLayer(layer0); SpecularMatrix::execute(mLayer, v, coeff); diff --git a/Tests/UnitTests/Core/Fresnel/SpecularSimulationTest.h b/Tests/UnitTests/Core/Fresnel/SpecularSimulationTest.h index 0681bd216b0..25d361c7990 100644 --- a/Tests/UnitTests/Core/Fresnel/SpecularSimulationTest.h +++ b/Tests/UnitTests/Core/Fresnel/SpecularSimulationTest.h @@ -1,19 +1,21 @@ -#include "SpecularSimulation.h" -#include "IMultiLayerBuilder.h" +#include "google_test.h" #include "Exceptions.h" #include "FixedBinAxis.h" #include "Histogram1D.h" +#include "IMultiLayerBuilder.h" #include "Layer.h" #include "MaterialFactoryFuncs.h" #include "MultiLayer.h" -#include "VariableBinAxis.h" +#include "SpecularSimulation.h" #include "Units.h" +#include "VariableBinAxis.h" #include <iostream> class SpecularSimulationTest : public ::testing::Test { - protected: +protected: SpecularSimulationTest(); + ~SpecularSimulationTest(); MultiLayer multilayer; }; @@ -24,7 +26,7 @@ SpecularSimulationTest::SpecularSimulationTest() Material mat2 = HomogeneousMaterial("substrate", 15e-6, 0.0); Layer layer0(mat0); - Layer layer1(mat1, 10*Units::nanometer); + Layer layer1(mat1, 10 * Units::nanometer); Layer layer2(mat2); multilayer.addLayer(layer0); @@ -32,6 +34,8 @@ SpecularSimulationTest::SpecularSimulationTest() multilayer.addLayer(layer2); } +SpecularSimulationTest::~SpecularSimulationTest() = default; + TEST_F(SpecularSimulationTest, InitialState) { SpecularSimulation sim; @@ -64,7 +68,7 @@ TEST_F(SpecularSimulationTest, SetBeamParameters) { SpecularSimulation sim; - VariableBinAxis axis("axis",2, std::vector<double>{1.0, 2.0, 3.0}); + VariableBinAxis axis("axis", 2, std::vector<double>{1.0, 2.0, 3.0}); sim.setBeamParameters(1.0, axis); EXPECT_EQ(2u, sim.getAlphaAxis()->size()); EXPECT_EQ(1.0, sim.getAlphaAxis()->getMin()); @@ -82,7 +86,7 @@ TEST_F(SpecularSimulationTest, SetBeamParameters) TEST_F(SpecularSimulationTest, ConstructSimulation) { SpecularSimulation sim; - sim.setBeamParameters(1.0, 10, 0.0*Units::degree, 2.0*Units::degree); + sim.setBeamParameters(1.0, 10, 0.0 * Units::degree, 2.0 * Units::degree); sim.setSample(multilayer); EXPECT_EQ(3u, sim.sample()->numberOfLayers()); @@ -101,7 +105,7 @@ TEST_F(SpecularSimulationTest, ConstructSimulation) EXPECT_EQ(10u, reflectivity->getTotalNumberOfBins()); EXPECT_EQ(1u, reflectivity->getRank()); EXPECT_EQ(0.0, reflectivity->getXaxis().getMin()); - EXPECT_EQ(2.0*Units::degree, reflectivity->getXaxis().getMax()); + EXPECT_EQ(2.0 * Units::degree, reflectivity->getXaxis().getMax()); EXPECT_DOUBLE_EQ(std::norm(sim.getScalarR(0)[5]), reflectivity->getBinValues()[5]); const std::unique_ptr<OutputData<double>> output(sim.getDetectorIntensity()); @@ -114,19 +118,18 @@ TEST_F(SpecularSimulationTest, ConstructSimulation) EXPECT_EQ(10u, transmissivity->getTotalNumberOfBins()); EXPECT_EQ(1u, transmissivity->getRank()); EXPECT_EQ(0.0, transmissivity->getXaxis().getMin()); - EXPECT_EQ(2.0*Units::degree, transmissivity->getXaxis().getMax()); + EXPECT_EQ(2.0 * Units::degree, transmissivity->getXaxis().getMax()); EXPECT_DOUBLE_EQ(std::norm(sim.getScalarT(2)[5]), transmissivity->getBinValues()[5]); ASSERT_THROW(sim.getScalarR(3), std::runtime_error); ASSERT_THROW(sim.getScalarT(3), std::runtime_error); ASSERT_THROW(sim.getScalarKz(3), std::runtime_error); - } TEST_F(SpecularSimulationTest, SimulationClone) { SpecularSimulation sim; - sim.setBeamParameters(1.0, 10, 0.0*Units::degree, 2.0*Units::degree); + sim.setBeamParameters(1.0, 10, 0.0 * Units::degree, 2.0 * Units::degree); sim.setSample(multilayer); std::unique_ptr<SpecularSimulation> clone(sim.clone()); diff --git a/Tests/UnitTests/Core/Numeric0/FormFactorSpecializationTest.h b/Tests/UnitTests/Core/Numeric0/FormFactorSpecializationTest.h index 27f09864241..94453e74176 100644 --- a/Tests/UnitTests/Core/Numeric0/FormFactorSpecializationTest.h +++ b/Tests/UnitTests/Core/Numeric0/FormFactorSpecializationTest.h @@ -1,18 +1,4 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/UnitTests/Core/Numeric0/FormFactorSpecializationTest.h -//! @brief Unit tests for special cases of particle-shape form factors. -//! -//! @homepage http://bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015-16 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - +#include "google_test.h" #include "MathConstants.h" #include "BornAgainNamespace.h" #include "HardParticles.h" @@ -29,8 +15,11 @@ public: EXPECT_NEAR( real(f0), real(f1), eps*avge ); EXPECT_NEAR( imag(f0), imag(f1), eps*avge ); } + ~FFSpecializationTest(); }; +FFSpecializationTest::~FFSpecializationTest() = default; + INSTANTIATE_TEST_CASE_P( FFSpecializationTests, FFSpecializationTest, @@ -42,82 +31,82 @@ double eps_polyh = 7.5e-13; TEST_P(FFSpecializationTest, TruncatedCubeAsBox) { - if( skip_q( 1e-99, 5e2 ) ) + if (skip_q(1e-99, 5e2)) return; - double L=.5; + double L = .5; FormFactorTruncatedCube p0(L, 0); FormFactorBox p1(L, L, L); - test_ff_eq( &p0, &p1, eps_polyh ); + test_ff_eq(&p0, &p1, eps_polyh); } TEST_P(FFSpecializationTest, AnisoPyramidAsPyramid) { - if( skip_q( 1e-99, 5e3 ) ) + if (skip_q(1e-99, 5e3)) return; - double L=1.5, H=.24, alpha=.6; + double L = 1.5, H = .24, alpha = .6; FormFactorAnisoPyramid p0(L, L, H, alpha); FormFactorPyramid p1(L, H, alpha); - test_ff_eq( &p0, &p1, eps_polyh ); + test_ff_eq(&p0, &p1, eps_polyh); } TEST_P(FFSpecializationTest, Pyramid3AsPrism) { - if( skip_q( 1e-99, 5e3 ) ) + if (skip_q(1e-99, 5e3)) return; - double L=1.8, H=.3; - FormFactorTetrahedron p0(L, H, M_PI/2); + double L = 1.8, H = .3; + FormFactorTetrahedron p0(L, H, M_PI / 2); FormFactorPrism3 p1(L, H); - test_ff_eq( &p0, &p1, eps_polyh ); + test_ff_eq(&p0, &p1, eps_polyh); } TEST_P(FFSpecializationTest, PyramidAsBox) { - if( skip_q( 1e-99, 5e2 ) ) + if (skip_q(1e-99, 5e2)) return; - double L=1.8, H=.3; - FormFactorPyramid p0(L, H, M_PI/2); + double L = 1.8, H = .3; + FormFactorPyramid p0(L, H, M_PI / 2); FormFactorBox p1(L, L, H); - test_ff_eq( &p0, &p1, eps_polyh ); + test_ff_eq(&p0, &p1, eps_polyh); } TEST_P(FFSpecializationTest, Cone6AsPrism) { - if( skip_q( 1e-99, 5e2 ) ) + if (skip_q(1e-99, 5e2)) return; - double L=.8, H=1.13; - FormFactorCone6 p0(L, H, M_PI/2); + double L = .8, H = 1.13; + FormFactorCone6 p0(L, H, M_PI / 2); FormFactorPrism6 p1(L, H); - test_ff_eq( &p0, &p1, eps_polyh ); + test_ff_eq(&p0, &p1, eps_polyh); } //*********** spheroids *************** TEST_P(FFSpecializationTest, HemiEllipsoidAsTruncatedSphere) { - if( skip_q( 1e-99, 5e2 ) ) + if (skip_q(1e-99, 5e2)) return; - double R=1.07; + double R = 1.07; FormFactorHemiEllipsoid p0(R, R, R); FormFactorTruncatedSphere p1(R, R); - test_ff_eq( &p0, &p1, 1e-10 ); + test_ff_eq(&p0, &p1, 1e-10); } TEST_P(FFSpecializationTest, EllipsoidalCylinderAsCylinder) { - if( skip_q( 1e-99, 5e3 ) ) + if (skip_q(1e-99, 5e3)) return; - double R=.8, H=1.2; + double R = .8, H = 1.2; FormFactorEllipsoidalCylinder p0(R, R, H); FormFactorCylinder p1(R, H); - test_ff_eq( &p0, &p1, 1e-11 ); + test_ff_eq(&p0, &p1, 1e-11); } TEST_P(FFSpecializationTest, TruncatedSphereAsSphere) { - if( skip_q( .02, 5e1 ) ) // WAITING #1416 improve/replace numeric integration + if (skip_q(.02, 5e1)) // WAITING #1416 improve/replace numeric integration return; - double R=1.; - FormFactorTruncatedSphere p0(R, 2*R); + double R = 1.; + FormFactorTruncatedSphere p0(R, 2 * R); FormFactorFullSphere p1(R); - test_ff_eq( &p0, &p1 ); + test_ff_eq(&p0, &p1); } diff --git a/Tests/UnitTests/Core/Numeric1/FormFactorSymmetryTest.h b/Tests/UnitTests/Core/Numeric1/FormFactorSymmetryTest.h index 597344b07ec..2cbf8cf753a 100644 --- a/Tests/UnitTests/Core/Numeric1/FormFactorSymmetryTest.h +++ b/Tests/UnitTests/Core/Numeric1/FormFactorSymmetryTest.h @@ -1,18 +1,4 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/UnitTests/Core/Numeric1/FormFactorSymmetryTest.h -//! @brief Unit tests for symmetry of particle-shape form factors. -//! -//! @homepage http://bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015-16 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - +#include "google_test.h" #include "MathConstants.h" #include "BornAgainNamespace.h" #include "HardParticles.h" @@ -21,6 +7,7 @@ class FFSymmetryTest : public QLoopedTest { public: + ~FFSymmetryTest(); void test_qq_eq( IFormFactorBorn* p, cvector_t q0, cvector_t q1, double eps=1e-12 ) { complex_t f0 = p->evaluate_for_q(q0); complex_t f1 = p->evaluate_for_q(q1); @@ -31,6 +18,8 @@ public: cvector_t qt; }; +FFSymmetryTest::~FFSymmetryTest() = default; + INSTANTIATE_TEST_CASE_P( FFSymmetryTests, FFSymmetryTest, @@ -40,63 +29,63 @@ INSTANTIATE_TEST_CASE_P( TEST_P(FFSymmetryTest, Prism3) { - if( skip_q( 1e-99, 2e2 ) ) + if (skip_q(1e-99, 2e2)) return; FormFactorPrism3 p(.83, .45); - test_qq_eq( &p, q, q.rotatedZ(M_TWOPI/3) ); + test_qq_eq(&p, q, q.rotatedZ(M_TWOPI / 3)); } TEST_P(FFSymmetryTest, Prism6) { - if( skip_q( 1e-99, 2e3 ) ) + if (skip_q(1e-99, 2e3)) return; FormFactorPrism6 p(1.33, .42); - test_qq_eq( &p, q, q.rotatedZ( M_PI/3), 1e-12 ); - test_qq_eq( &p, q, q.rotatedZ(-M_TWOPI/3), 3.8e-12 ); + test_qq_eq(&p, q, q.rotatedZ(M_PI / 3), 1e-12); + test_qq_eq(&p, q, q.rotatedZ(-M_TWOPI / 3), 3.8e-12); } TEST_P(FFSymmetryTest, Tetrahedron) { - if( skip_q( 1e-99, 2e2 ) ) + if (skip_q(1e-99, 2e2)) return; FormFactorTetrahedron p(8.43, .25, .53); - test_qq_eq( &p, q, q.rotatedZ(M_TWOPI/3), 6e-12 ); + test_qq_eq(&p, q, q.rotatedZ(M_TWOPI / 3), 6e-12); // Linux: 3e-12, relaxed for Mac } TEST_P(FFSymmetryTest, Cone6_flat) { - if( skip_q( 1e-99, 2e2) ) // TODO for larger q, imag(ff) is nan + if (skip_q(1e-99, 2e2)) // TODO for larger q, imag(ff) is nan return; FormFactorCone6 p(4.3, .09, .1); - test_qq_eq( &p, q, q.rotatedZ(-M_PI/3), 3.8e-12 ); + test_qq_eq(&p, q, q.rotatedZ(-M_PI / 3), 3.8e-12); } TEST_P(FFSymmetryTest, Cone6_steep) { - if( skip_q( 1e-99, 2e2) ) // TODO for larger q, imag(ff) is nan + if (skip_q(1e-99, 2e2)) // TODO for larger q, imag(ff) is nan return; - FormFactorCone6 p(.23, 3.5, .999*M_PI/2); - test_qq_eq( &p, q, q.rotatedZ(-M_PI/3), 2.5e-12 ); + FormFactorCone6 p(.23, 3.5, .999 * M_PI / 2); + test_qq_eq(&p, q, q.rotatedZ(-M_PI / 3), 2.5e-12); } //*********** spheroids *************** TEST_P(FFSymmetryTest, HemiEllipsoid) { - if( skip_q( 1e-99, 2e2 ) ) + if (skip_q(1e-99, 2e2)) return; FormFactorHemiEllipsoid p(.53, .78, 1.3); - test_qq_eq( &p, q, cvector_t(-q.x(), q.y(), q.z()) ); - test_qq_eq( &p, q, cvector_t(q.x(), -q.y(), q.z()) ); + test_qq_eq(&p, q, cvector_t(-q.x(), q.y(), q.z())); + test_qq_eq(&p, q, cvector_t(q.x(), -q.y(), q.z())); } TEST_P(FFSymmetryTest, TruncatedSphere) { - if( skip_q( 1e-99, 2e2 ) ) + if (skip_q(1e-99, 2e2)) return; FormFactorTruncatedSphere p(.79, .34); - test_qq_eq( &p, q, q.rotatedZ(M_PI/3.13698), 1e-10 ); + test_qq_eq(&p, q, q.rotatedZ(M_PI / 3.13698), 1e-10); } // ****** TODO: tests that do not pass for the full q range ********* diff --git a/Tests/UnitTests/Core/Other/BeamTest.h b/Tests/UnitTests/Core/Other/BeamTest.h index 89ae85a90d7..ed603960b0a 100644 --- a/Tests/UnitTests/Core/Other/BeamTest.h +++ b/Tests/UnitTests/Core/Other/BeamTest.h @@ -2,40 +2,41 @@ #include "BornAgainNamespace.h" #include "MathConstants.h" #include "ParameterPool.h" +#include "RealParameter.h" +#include "google_test.h" #include <memory> - class BeamTest : public ::testing::Test { protected: - BeamTest() {} + ~BeamTest(); Beam m_empty_beam; }; +BeamTest::~BeamTest() = default; + TEST_F(BeamTest, BeamInitialState) { EXPECT_DOUBLE_EQ(M_TWOPI, m_empty_beam.getCentralK()[0]); EXPECT_EQ(0.0, m_empty_beam.getCentralK()[1]); EXPECT_EQ(0.0, m_empty_beam.getCentralK()[2]); EXPECT_EQ(1.0, m_empty_beam.getIntensity()); - /* TEMPORARILY DISABLED getParameterPool() - EXPECT_EQ(size_t(4), m_empty_beam.getParameterPool()->size()); - EXPECT_EQ(0.0, m_empty_beam.getParameterPool()->getParameter(BornAgain::Intensity).getValue()); - EXPECT_EQ(1.0, m_empty_beam.getParameterPool()->getParameter(BornAgain::Wavelength).getValue()); - EXPECT_EQ(0.0, m_empty_beam.getParameterPool()->getParameter(BornAgain::Alpha).getValue()); - EXPECT_EQ(0.0, m_empty_beam.getParameterPool()->getParameter(BornAgain::Phi).getValue()); - EXPECT_EQ(complex_t(0.5, 0.0), m_empty_beam.getPolarization()(0, 0)); - EXPECT_EQ(complex_t(0.5, 0.0), m_empty_beam.getPolarization()(1, 1)); - */ + //EXPECT_EQ(size_t(4), m_empty_beam.parameterPool()->size()); +// EXPECT_EQ(1.0, m_empty_beam.parameterPool()->parameter(BornAgain::Intensity)->value()); +// EXPECT_EQ(1.0, m_empty_beam.parameterPool()->parameter(BornAgain::Wavelength)->value()); +// EXPECT_EQ(0.0, m_empty_beam.parameterPool()->parameter(BornAgain::Alpha)->value()); +// EXPECT_EQ(0.0, m_empty_beam.parameterPool()->parameter(BornAgain::Phi)->value()); +// EXPECT_EQ(complex_t(0.5, 0.0), m_empty_beam.getPolarization()(0, 0)); +// EXPECT_EQ(complex_t(0.5, 0.0), m_empty_beam.getPolarization()(1, 1)); } TEST_F(BeamTest, BeamAssignment) { kvector_t polarization(0.0, 0.0, 0.2); - std::unique_ptr<Beam> P_beam { new Beam() }; + std::unique_ptr<Beam> P_beam{new Beam()}; P_beam->setCentralK(1.0, 1.0, 1.0); P_beam->setIntensity(2.0); diff --git a/Tests/UnitTests/Core/Other/ChiSquaredModuleTest.h b/Tests/UnitTests/Core/Other/ChiSquaredModuleTest.h index 0c55251e692..d1b3ba6feda 100644 --- a/Tests/UnitTests/Core/Other/ChiSquaredModuleTest.h +++ b/Tests/UnitTests/Core/Other/ChiSquaredModuleTest.h @@ -1,111 +1,35 @@ +#include "google_test.h" +#include "BornAgainNamespace.h" #include "ChiSquaredModule.h" #include "ISquaredFunction.h" -#include "BornAgainNamespace.h" - +// TODO revise test class ChiSquaredModuleTest : public ::testing::Test { - protected: - ChiSquaredModuleTest(); - virtual ~ChiSquaredModuleTest(); +protected: + ~ChiSquaredModuleTest(); ChiSquaredModule m_chi_empty; ChiSquaredModule m_chi_default; - OutputData<double > m_real_data; - OutputData<double > m_simul_data; + OutputData<double> m_real_data; + OutputData<double> m_simul_data; }; - -ChiSquaredModuleTest::ChiSquaredModuleTest() -{ -// m_real_data.addAxis(BornAgain::PHI_AXIS_NAME, 10, 0.0, 10.0); -// m_real_data.addAxis(BornAgain::ALPHA_AXIS_NAME, 10, 0.0, 10.0); -// m_real_data.setAllTo(1.0); -// m_simul_data.copyFrom(m_real_data); -// m_simul_data.setAllTo(1.1); - - // default module with set of real and simulated data -// m_chi_default.setRealAndSimulatedData(m_real_data, m_simul_data); - -} - - -ChiSquaredModuleTest::~ChiSquaredModuleTest() -{ -} - +ChiSquaredModuleTest::~ChiSquaredModuleTest() = default; TEST_F(ChiSquaredModuleTest, InitialState) { -// EXPECT_EQ( nullptr, m_chi_empty.getRealData()); -// EXPECT_EQ( nullptr, m_chi_empty.getSimulationData()); - EXPECT_TRUE( dynamic_cast<const SquaredFunctionDefault*>(m_chi_empty.getSquaredFunction())); -// EXPECT_TRUE( dynamic_cast<const DefaultAllDataSelector*>(m_chi_empty.getFittingDataSelector())); - EXPECT_EQ( nullptr, m_chi_empty.getIntensityNormalizer()); - EXPECT_EQ( nullptr, m_chi_empty.getIntensityFunction()); -// ASSERT_THROW(m_chi_empty.calculateChiSquared(), Exceptions::NullPointerException); -// ASSERT_THROW(m_chi_empty.createChi2DifferenceMap(), Exceptions::NullPointerException); + EXPECT_TRUE(dynamic_cast<const SquaredFunctionDefault*>(m_chi_empty.getSquaredFunction())); + EXPECT_EQ(nullptr, m_chi_empty.getIntensityNormalizer()); + EXPECT_EQ(nullptr, m_chi_empty.getIntensityFunction()); } TEST_F(ChiSquaredModuleTest, CloneOfEmpty) { - ChiSquaredModule *clone_of_empty = m_chi_empty.clone(); -// EXPECT_EQ( nullptr, clone_of_empty->getRealData()); -// EXPECT_EQ( nullptr, clone_of_empty->getSimulationData()); - EXPECT_TRUE( dynamic_cast<const SquaredFunctionDefault*>(clone_of_empty->getSquaredFunction())); -// EXPECT_TRUE( dynamic_cast<const DefaultAllDataSelector*>(clone_of_empty->getFittingDataSelector())); - EXPECT_EQ( nullptr, clone_of_empty->getIntensityNormalizer()); - EXPECT_EQ( nullptr, clone_of_empty->getIntensityFunction()); -// ASSERT_THROW(clone_of_empty->calculateChiSquared(), Exceptions::NullPointerException); -// ASSERT_THROW(clone_of_empty->createChi2DifferenceMap(), Exceptions::NullPointerException); + ChiSquaredModule* clone_of_empty = m_chi_empty.clone(); + EXPECT_TRUE(dynamic_cast<const SquaredFunctionDefault*>(clone_of_empty->getSquaredFunction())); + EXPECT_EQ(nullptr, clone_of_empty->getIntensityNormalizer()); + EXPECT_EQ(nullptr, clone_of_empty->getIntensityFunction()); delete clone_of_empty; } - -//TEST_F(ChiSquaredModuleTest, DefaultModule) -//{ -// EXPECT_FLOAT_EQ( 0.01, (float)m_chi_default.calculateChiSquared()); -//} - -//TEST_F(ChiSquaredModuleTest, CloneOfDefault) -//{ -// ChiSquaredModule *clone_of_default = m_chi_default.clone(); -// EXPECT_FLOAT_EQ( 0.01, (float)clone_of_default->calculateChiSquared()); -// clone_of_default->setNdegreeOfFreedom(1); -// EXPECT_FLOAT_EQ( 1.0, (float)clone_of_default->calculateChiSquared()); -// delete clone_of_default; -//} - -//TEST_F(ChiSquaredModuleTest, IsGISAXSLikeModule) -//{ -// ChiSquaredModule chi_isgisaxs; -// OutputData<double> real_data; -// OutputData<double> simul_data; -// const size_t nbins(5); -// real_data.addAxis(BornAgain::PHI_AXIS_NAME, nbins, 0.0, 1.0); -// simul_data.addAxis(BornAgain::PHI_AXIS_NAME, nbins, 0.0, 1.0); -// const double a_real_data[nbins] = {1., 10., 100., 10., 1. }; -// const double a_simul_data[nbins] = {10., 100., 1000., 100., 10. }; -// OutputData<double >::iterator it_real = real_data.begin(); -// OutputData<double >::iterator it_simul = simul_data.begin(); -// int index(0); -// while(it_real != real_data.end()) { -// *it_real = a_real_data[index]; -// *it_simul = a_simul_data[index]; -// ++index; ++it_real; ++it_simul; -// } -// chi_isgisaxs.setRealAndSimulatedData(real_data, simul_data); -// IntensityNormalizer normalizer(100., 0.0); -// chi_isgisaxs.setIntensityNormalizer( normalizer ); -// EXPECT_FLOAT_EQ( 0.0, (float)chi_isgisaxs.calculateChiSquared()); - -//// m_chi_isgisaxs.setChiSquaredFunction( SquaredFunctionWithSystematicError(1.0) ); -//// EXPECT_FLOAT_EQ( double(0.005), m_chi_isgisaxs.calculateChiSquared()); - -//// m_chi_isgisaxs.setOutputDataNormalizer( OutputDataNormalizerScaleAndShift() ); -//// EXPECT_FLOAT_EQ( double(0.005), m_chi_isgisaxs.calculateChiSquared()); -//} - - - - diff --git a/Tests/UnitTests/Core/Other/CumulativeValueTest.h b/Tests/UnitTests/Core/Other/CumulativeValueTest.h index 88545093b5e..00f5f61424e 100644 --- a/Tests/UnitTests/Core/Other/CumulativeValueTest.h +++ b/Tests/UnitTests/Core/Other/CumulativeValueTest.h @@ -1,13 +1,14 @@ +#include "google_test.h" #include "CumulativeValue.h" - class CumulativeValueTest : public ::testing::Test { - protected: - CumulativeValueTest(){} - virtual ~CumulativeValueTest(){} +protected: + ~CumulativeValueTest(); }; +CumulativeValueTest::~CumulativeValueTest() = default; + TEST_F(CumulativeValueTest, InitialState) { CumulativeValue cv; @@ -33,7 +34,6 @@ TEST_F(CumulativeValueTest, AddValue) EXPECT_EQ(1.0, cv2.getContent()); EXPECT_EQ(1.0, cv2.getAverage()); EXPECT_EQ(0.0, cv2.getRMS()); - } TEST_F(CumulativeValueTest, AddValues) @@ -61,14 +61,14 @@ TEST_F(CumulativeValueTest, AddValuesWithWeights) EXPECT_EQ(2, cv1.getNumberOfEntries()); EXPECT_DOUBLE_EQ(4.0, cv1.getContent()); EXPECT_DOUBLE_EQ(1.5, cv1.getAverage()); - EXPECT_DOUBLE_EQ(0.75, cv1.getRMS()*cv1.getRMS()); + EXPECT_DOUBLE_EQ(0.75, cv1.getRMS() * cv1.getRMS()); cv1.add(3.0); cv1.add(3.0); EXPECT_EQ(4, cv1.getNumberOfEntries()); EXPECT_DOUBLE_EQ(10.0, cv1.getContent()); EXPECT_DOUBLE_EQ(2.0, cv1.getAverage()); - EXPECT_DOUBLE_EQ(1.0, cv1.getRMS()); + EXPECT_DOUBLE_EQ(1.0, cv1.getRMS()); } TEST_F(CumulativeValueTest, Comparison) @@ -79,5 +79,4 @@ TEST_F(CumulativeValueTest, Comparison) EXPECT_TRUE(cv2 > cv1); EXPECT_TRUE(cv1 < cv2); - } diff --git a/Tests/UnitTests/Core/Other/GISASSimulationTest.h b/Tests/UnitTests/Core/Other/GISASSimulationTest.h index c0595f7feed..70ab42ef1c3 100644 --- a/Tests/UnitTests/Core/Other/GISASSimulationTest.h +++ b/Tests/UnitTests/Core/Other/GISASSimulationTest.h @@ -5,29 +5,23 @@ #include "Layer.h" #include "MultiLayer.h" #include "OutputData.h" -#include <memory> +#include "google_test.h" #include <cmath> +#include <memory> class GISASSimulationTest : public ::testing::Test { - protected: - GISASSimulationTest(); - virtual ~GISASSimulationTest(); +protected: + ~GISASSimulationTest(); GISASSimulation m_simulation; }; - -GISASSimulationTest::GISASSimulationTest() -{} - -GISASSimulationTest::~GISASSimulationTest() -{} - +GISASSimulationTest::~GISASSimulationTest() = default; TEST_F(GISASSimulationTest, SimulationInitialState) { - EXPECT_EQ( BornAgain::GISASSimulationType, m_simulation.getName()); - EXPECT_EQ( nullptr, m_simulation.sample()); + EXPECT_EQ(BornAgain::GISASSimulationType, m_simulation.getName()); + EXPECT_EQ(nullptr, m_simulation.sample()); EXPECT_EQ(0u, m_simulation.numberOfSimulationElements()); EXPECT_THROW(m_simulation.getDetectorIntensity(), std::runtime_error); EXPECT_EQ(1u, m_simulation.getChildren().size()); @@ -37,15 +31,15 @@ TEST_F(GISASSimulationTest, SimulationConstruction) { MultiLayer multi_layer; GISASSimulation simulation(multi_layer); - EXPECT_EQ( BornAgain::GISASSimulationType, simulation.getName()); - EXPECT_NE( nullptr, simulation.sample()); + EXPECT_EQ(BornAgain::GISASSimulationType, simulation.getName()); + EXPECT_NE(nullptr, simulation.sample()); EXPECT_EQ(0u, simulation.numberOfSimulationElements()); EXPECT_THROW(simulation.getDetectorIntensity(), std::runtime_error); EXPECT_EQ(2u, simulation.getChildren().size()); simulation.setDetectorParameters(10, -2.0, 2.0, 20, 0.0, 2.0); - EXPECT_EQ( BornAgain::GISASSimulationType, simulation.getName()); - EXPECT_NE( nullptr, simulation.sample()); + EXPECT_EQ(BornAgain::GISASSimulationType, simulation.getName()); + EXPECT_NE(nullptr, simulation.sample()); EXPECT_EQ(200u, simulation.numberOfSimulationElements()); EXPECT_NO_THROW(simulation.getDetectorIntensity()); EXPECT_EQ(2u, simulation.getChildren().size()); @@ -54,8 +48,8 @@ TEST_F(GISASSimulationTest, SimulationConstruction) TEST_F(GISASSimulationTest, SimulationClone) { auto p_clone = m_simulation.clone(); - EXPECT_EQ( BornAgain::GISASSimulationType, p_clone->getName()); - EXPECT_EQ( nullptr, p_clone->sample()); + EXPECT_EQ(BornAgain::GISASSimulationType, p_clone->getName()); + EXPECT_EQ(nullptr, p_clone->sample()); EXPECT_EQ(0u, p_clone->numberOfSimulationElements()); EXPECT_THROW(p_clone->getDetectorIntensity(), std::runtime_error); EXPECT_EQ(1u, p_clone->getChildren().size()); @@ -65,8 +59,8 @@ TEST_F(GISASSimulationTest, SimulationClone) GISASSimulation simulation(multi_layer); simulation.setDetectorParameters(10, -2.0, 2.0, 20, 0.0, 2.0); p_clone = simulation.clone(); - EXPECT_EQ( BornAgain::GISASSimulationType, p_clone->getName()); - EXPECT_NE( nullptr, p_clone->sample()); + EXPECT_EQ(BornAgain::GISASSimulationType, p_clone->getName()); + EXPECT_NE(nullptr, p_clone->sample()); EXPECT_EQ(200u, p_clone->numberOfSimulationElements()); EXPECT_NO_THROW(p_clone->getDetectorIntensity()); EXPECT_EQ(2u, p_clone->getChildren().size()); diff --git a/Tests/UnitTests/Core/Other/InstrumentTest.h b/Tests/UnitTests/Core/Other/InstrumentTest.h index 0f33c6de98e..13b2a7460ef 100644 --- a/Tests/UnitTests/Core/Other/InstrumentTest.h +++ b/Tests/UnitTests/Core/Other/InstrumentTest.h @@ -1,53 +1,51 @@ -#include "MathConstants.h" -#include "Instrument.h" +#include "google_test.h" #include "BornAgainNamespace.h" +#include "Instrument.h" +#include "MathConstants.h" +#include "OutputData.h" class InstrumentTest : public ::testing::Test { - protected: +protected: InstrumentTest(); - virtual ~InstrumentTest(); + ~InstrumentTest(); Instrument m_instrument; OutputData<double> m_data; }; - InstrumentTest::InstrumentTest() { m_data.addAxis(BornAgain::PHI_AXIS_NAME, 10, 0., 10.); m_data.addAxis("theta_f", 20, 0., 20.); } -InstrumentTest::~InstrumentTest() -{ -} +InstrumentTest::~InstrumentTest() = default; TEST_F(InstrumentTest, InstrumentInitialState) { - EXPECT_EQ( 1.0, m_instrument.getBeamIntensity()); + EXPECT_EQ(1.0, m_instrument.getBeamIntensity()); } - TEST_F(InstrumentTest, BeamManipulation) { double lambda(1), alpha(-1), phi(1); - double k = M_TWOPI/lambda; - double x = k*std::cos(alpha) * std::cos(phi); - double y = -k*std::cos(alpha) * std::sin(phi); - double z = k*std::sin(alpha); - m_instrument.setBeamParameters(lambda, -1.0*alpha, phi); - EXPECT_DOUBLE_EQ(x, m_instrument.getBeam().getCentralK().x() ); - EXPECT_DOUBLE_EQ(y, m_instrument.getBeam().getCentralK().y() ); - EXPECT_DOUBLE_EQ(z, m_instrument.getBeam().getCentralK().z() ); + double k = M_TWOPI / lambda; + double x = k * std::cos(alpha) * std::cos(phi); + double y = -k * std::cos(alpha) * std::sin(phi); + double z = k * std::sin(alpha); + m_instrument.setBeamParameters(lambda, -1.0 * alpha, phi); + EXPECT_DOUBLE_EQ(x, m_instrument.getBeam().getCentralK().x()); + EXPECT_DOUBLE_EQ(y, m_instrument.getBeam().getCentralK().y()); + EXPECT_DOUBLE_EQ(z, m_instrument.getBeam().getCentralK().z()); m_instrument.setBeamIntensity(10); - EXPECT_EQ( double(10), m_instrument.getBeamIntensity()); + EXPECT_EQ(double(10), m_instrument.getBeamIntensity()); } TEST_F(InstrumentTest, InstrumentClone) { Instrument clone(m_instrument); - EXPECT_EQ( size_t(0), clone.getDetectorDimension() ); - EXPECT_EQ( 1.0, clone.getBeamIntensity() ); + EXPECT_EQ(size_t(0), clone.getDetectorDimension()); + EXPECT_EQ(1.0, clone.getBeamIntensity()); } diff --git a/Tests/UnitTests/Core/Other/LayerFillLimitsTest.h b/Tests/UnitTests/Core/Other/LayerFillLimitsTest.h index 63adfc43b03..9e576b98bba 100644 --- a/Tests/UnitTests/Core/Other/LayerFillLimitsTest.h +++ b/Tests/UnitTests/Core/Other/LayerFillLimitsTest.h @@ -1,3 +1,4 @@ +#include "google_test.h" #include "LayerFillLimits.h" #include <stdexcept> @@ -5,25 +6,23 @@ class LayerFillLimitsTest : public ::testing::Test { protected: LayerFillLimitsTest(); - virtual ~LayerFillLimitsTest(); + ~LayerFillLimitsTest(); LayerFillLimits m_fill_limits; std::vector<double> layers_bottomz; }; -LayerFillLimitsTest::LayerFillLimitsTest() - : m_fill_limits( {} ) +LayerFillLimitsTest::LayerFillLimitsTest() : m_fill_limits({}) { - std::vector<double> layers_bottomz = { 0, -5, -20 }; + std::vector<double> layers_bottomz = {0, -5, -20}; m_fill_limits = LayerFillLimits(layers_bottomz); } -LayerFillLimitsTest::~LayerFillLimitsTest() -{} +LayerFillLimitsTest::~LayerFillLimitsTest() = default; TEST_F(LayerFillLimitsTest, LayerFillLimitsEmptyConstructor) { - LayerFillLimits layer_limits( {} ); + LayerFillLimits layer_limits({}); EXPECT_EQ(1u, layer_limits.layerZLimits().size()); EXPECT_EQ(layer_limits.layerZLimits()[0], ZLimits()); } @@ -40,7 +39,7 @@ TEST_F(LayerFillLimitsTest, LayerFillLimitsConstructor) TEST_F(LayerFillLimitsTest, LayerFillLimitsWrongUpdate) { - EXPECT_THROW(m_fill_limits.update( { 1, 0 }), std::runtime_error); + EXPECT_THROW(m_fill_limits.update({1, 0}), std::runtime_error); std::vector<ZLimits> limits = m_fill_limits.layerZLimits(); EXPECT_EQ(4u, limits.size()); EXPECT_EQ(limits[0], ZLimits()); @@ -51,7 +50,7 @@ TEST_F(LayerFillLimitsTest, LayerFillLimitsWrongUpdate) TEST_F(LayerFillLimitsTest, LayerFillLimitsUpdate) { - m_fill_limits.update( { 1, 1.5 }); + m_fill_limits.update({1, 1.5}); std::vector<ZLimits> limits = m_fill_limits.layerZLimits(); EXPECT_EQ(4u, limits.size()); EXPECT_EQ(limits[0], ZLimits(1, 1.5)); @@ -59,7 +58,7 @@ TEST_F(LayerFillLimitsTest, LayerFillLimitsUpdate) EXPECT_EQ(limits[2], ZLimits()); EXPECT_EQ(limits[3], ZLimits()); - m_fill_limits.update( { -6, -3 }); + m_fill_limits.update({-6, -3}); limits = m_fill_limits.layerZLimits(); EXPECT_EQ(4u, limits.size()); EXPECT_EQ(limits[0], ZLimits(1, 1.5)); @@ -67,7 +66,7 @@ TEST_F(LayerFillLimitsTest, LayerFillLimitsUpdate) EXPECT_EQ(limits[2], ZLimits(-1, 0)); EXPECT_EQ(limits[3], ZLimits()); - m_fill_limits.update( { -10, -7 }); + m_fill_limits.update({-10, -7}); limits = m_fill_limits.layerZLimits(); EXPECT_EQ(4u, limits.size()); EXPECT_EQ(limits[0], ZLimits(1, 1.5)); @@ -75,7 +74,7 @@ TEST_F(LayerFillLimitsTest, LayerFillLimitsUpdate) EXPECT_EQ(limits[2], ZLimits(-5, 0)); EXPECT_EQ(limits[3], ZLimits()); - m_fill_limits.update( { -30, -25 }); + m_fill_limits.update({-30, -25}); limits = m_fill_limits.layerZLimits(); EXPECT_EQ(4u, limits.size()); EXPECT_EQ(limits[0], ZLimits(1, 1.5)); @@ -83,4 +82,3 @@ TEST_F(LayerFillLimitsTest, LayerFillLimitsUpdate) EXPECT_EQ(limits[2], ZLimits(-5, 0)); EXPECT_EQ(limits[3], ZLimits(-10, -5)); } - diff --git a/Tests/UnitTests/Core/Other/MaterialTest.h b/Tests/UnitTests/Core/Other/MaterialTest.h index 775ebdbf412..47132fc06c1 100644 --- a/Tests/UnitTests/Core/Other/MaterialTest.h +++ b/Tests/UnitTests/Core/Other/MaterialTest.h @@ -1,23 +1,21 @@ -#include "MaterialFactoryFuncs.h" +#include "google_test.h" +#include "Exceptions.h" #include "MaterialBySLDImpl.h" +#include "MaterialFactoryFuncs.h" #include "RefractiveMaterialImpl.h" -#include "SlicedParticle.h" -#include "WavevectorInfo.h" #include "Rotations.h" +#include "SlicedParticle.h" #include "Units.h" -#include "Exceptions.h" +#include "WavevectorInfo.h" class MaterialTest : public ::testing::Test { public: - MaterialTest() - { - } - virtual ~MaterialTest() - { - } + ~MaterialTest(); }; +MaterialTest::~MaterialTest() = default; + TEST_F(MaterialTest, MaterialConstruction) { complex_t material_data = complex_t(0.0, 2.0); @@ -29,14 +27,14 @@ TEST_F(MaterialTest, MaterialConstruction) EXPECT_EQ(material_data, material.materialData()); EXPECT_EQ(magnetism, material.magnetization()); - Material material2 = HomogeneousMaterial("MagMaterial", material_data.real(), - material_data.imag(), magnetism); + Material material2 + = HomogeneousMaterial("MagMaterial", material_data.real(), material_data.imag(), magnetism); EXPECT_EQ("MagMaterial", material2.getName()); EXPECT_EQ(material_data, material2.materialData()); EXPECT_EQ(magnetism, material2.magnetization()); - Material material3 = MaterialBySLD("MagMaterial", material_data.real(), - material_data.imag(), magnetism); + Material material3 + = MaterialBySLD("MagMaterial", material_data.real(), material_data.imag(), magnetism); EXPECT_EQ("MagMaterial", material3.getName()); EXPECT_EQ(material_data, material3.materialData()); EXPECT_EQ(magnetism, material3.magnetization()); @@ -54,8 +52,7 @@ TEST_F(MaterialTest, MaterialConstruction) EXPECT_EQ(material_data, material5.materialData()); EXPECT_EQ(default_magnetism, material5.magnetization()); - Material material6 - = MaterialBySLD("Material", material_data.real(), material_data.imag()); + Material material6 = MaterialBySLD("Material", material_data.real(), material_data.imag()); EXPECT_EQ("Material", material6.getName()); EXPECT_EQ(material_data, material6.materialData()); EXPECT_EQ(default_magnetism, material6.magnetization()); @@ -85,7 +82,8 @@ TEST_F(MaterialTest, MaterialTransform) EXPECT_EQ(material_data, material2.materialData()); EXPECT_EQ(transformed_mag, material2.magnetization()); - Material material3 = MaterialBySLD("Material", material_data.real(), material_data.imag(), magnetism); + Material material3 + = MaterialBySLD("Material", material_data.real(), material_data.imag(), magnetism); Material material4 = material.transformedMaterial(transform.getTransform3D()); EXPECT_EQ("Material", material4.getName()); @@ -120,23 +118,26 @@ TEST_F(MaterialTest, ComputationTest) // Reference data for Fe taken from // https://sld-calculator.appspot.com/save // http://www.ati.ac.at/~neutropt/scattering/table.html - const double bc = 9.45e-6; // nm, bound coherent scattering length + const double bc = 9.45e-6; // nm, bound coherent scattering length const double abs_cs = 2.56e-10; // nm^2, absorption cross-section for 2200 m/s neutrons const double basic_wavelength = 0.1798197; // nm, wavelength of 2200 m/s neutrons - const double mol_mass = 55.845; // g/mol, Fe molar mass - const double avog_number = 6.022e+23; // mol^{-1}, Avogadro number - const double density = 7.874e-21; // g/nm^3, Fe material density + const double mol_mass = 55.845; // g/mol, Fe molar mass + const double avog_number = 6.022e+23; // mol^{-1}, Avogadro number + const double density = 7.874e-21; // g/nm^3, Fe material density const double number_density = avog_number * density / mol_mass; // 1/nm^3, Fe number density const double sld = number_density * bc; const double abs_term = number_density * abs_cs / basic_wavelength; - const complex_t sld_ref(8.0241e-04, -6.0448e-8); // nm^{-2}, reference data, wavelength-independent + const complex_t sld_ref(8.0241e-04, + -6.0448e-8); // nm^{-2}, reference data, wavelength-independent const double wl_factor_2200 = basic_wavelength * basic_wavelength / M_PI; const double wl_factor_1100 = 4.0 * basic_wavelength * basic_wavelength / M_PI; Material material = MaterialBySLD("Fe", sld, abs_term); - const complex_t sld_res_2200 = (1.0 - material.refractiveIndex2(basic_wavelength)) / wl_factor_2200; - const complex_t sld_res_1100 = (1.0 - material.refractiveIndex2(2.0 * basic_wavelength)) / wl_factor_1100; + const complex_t sld_res_2200 + = (1.0 - material.refractiveIndex2(basic_wavelength)) / wl_factor_2200; + const complex_t sld_res_1100 + = (1.0 - material.refractiveIndex2(2.0 * basic_wavelength)) / wl_factor_1100; EXPECT_NEAR(0.0, (sld_ref.real() - sld_res_2200.real()) / sld_ref.real(), 1e-3); EXPECT_NEAR(0.0, (sld_ref.imag() - sld_res_2200.imag()) / sld_ref.imag(), 1e-3); @@ -146,7 +147,8 @@ TEST_F(MaterialTest, ComputationTest) const complex_t refr_index = material.refractiveIndex(2.0 * basic_wavelength); WavevectorInfo wv_info(cvector_t{}, cvector_t{}, 2.0 * basic_wavelength); - Material material2 = HomogeneousMaterial("Fe", 1.0 - refr_index.real(), std::abs(refr_index.imag())); + Material material2 + = HomogeneousMaterial("Fe", 1.0 - refr_index.real(), std::abs(refr_index.imag())); const complex_t subtrSLD = material2.scalarSubtrSLD(wv_info); const complex_t subtrSLDWlIndep = material.scalarSubtrSLD(wv_info); EXPECT_NEAR(subtrSLD.real(), subtrSLDWlIndep.real(), 1e-10); @@ -155,10 +157,10 @@ TEST_F(MaterialTest, ComputationTest) TEST_F(MaterialTest, AveragedMaterialTest) { - kvector_t magnetization = kvector_t {1.0, 0.0, 0.0}; + kvector_t magnetization = kvector_t{1.0, 0.0, 0.0}; const Material material = HomogeneousMaterial("Material", 0.5, 0.5, magnetization); - const std::vector<HomogeneousRegion> regions = {HomogeneousRegion{0.25, material}, - HomogeneousRegion{0.25, material}}; + const std::vector<HomogeneousRegion> regions + = {HomogeneousRegion{0.25, material}, HomogeneousRegion{0.25, material}}; const Material material_avr = createAveragedMaterial(material, regions); EXPECT_EQ(material_avr.getName(), material.getName() + "_avg"); diff --git a/Tests/UnitTests/Core/Other/OrderedMapTest.h b/Tests/UnitTests/Core/Other/OrderedMapTest.h index ca159e69e1a..3d916ddaf75 100644 --- a/Tests/UnitTests/Core/Other/OrderedMapTest.h +++ b/Tests/UnitTests/Core/Other/OrderedMapTest.h @@ -1,18 +1,19 @@ -#include "OrderedMap.h" +#include "google_test.h" #include "INamed.h" +#include "OrderedMap.h" class OrderedMapTest : public ::testing::Test { protected: - OrderedMapTest(){} - virtual ~OrderedMapTest(){} + ~OrderedMapTest(); }; +OrderedMapTest::~OrderedMapTest() = default; TEST_F(OrderedMapTest, OrderedMapInsert) { OrderedMap<int, std::string> omap; - EXPECT_EQ( size_t(0), omap.size()); + EXPECT_EQ(size_t(0), omap.size()); std::vector<int> keys = {3, 2, 1}; std::vector<std::string> values = {"aaa", "bbb", "ccc"}; @@ -20,19 +21,19 @@ TEST_F(OrderedMapTest, OrderedMapInsert) omap.insert(keys[0], values[0]); omap.insert(keys[1], values[1]); omap.insert(keys[2], values[2]); - EXPECT_EQ( size_t(3), omap.size()); + EXPECT_EQ(size_t(3), omap.size()); // check that <key,value> are stored in the order of insertion and that there is no sorting // along key as in normal map - int npos(0); - for(OrderedMap<int, std::string>::const_iterator it = omap.begin(); it!= omap.end(); ++it) { + size_t npos(0); + for (OrderedMap<int, std::string>::const_iterator it = omap.begin(); it != omap.end(); ++it) { EXPECT_EQ(keys[npos], it->first); EXPECT_EQ(values[npos], it->second); npos++; } omap.clear(); - EXPECT_EQ( size_t(0), omap.size()); + EXPECT_EQ(size_t(0), omap.size()); } TEST_F(OrderedMapTest, OrderedMapErase) @@ -47,7 +48,8 @@ TEST_F(OrderedMapTest, OrderedMapErase) omap.insert(keys[2], values[2]); int npos(0); - for(OrderedMap<std::string, double>::const_iterator it = omap.begin(); it!= omap.end(); ++it) { + for (OrderedMap<std::string, double>::const_iterator it = omap.begin(); it != omap.end(); + ++it) { EXPECT_EQ(keys[npos], it->first); EXPECT_EQ(values[npos], it->second); npos++; @@ -64,7 +66,8 @@ TEST_F(OrderedMapTest, OrderedMapErase) keys = {"ccc", "aaa"}; values = {2.0, 3.0}; npos = 0; - for(OrderedMap<std::string, double>::const_iterator it = omap.begin(); it!= omap.end(); ++it) { + for (OrderedMap<std::string, double>::const_iterator it = omap.begin(); it != omap.end(); + ++it) { EXPECT_EQ(keys[npos], it->first); EXPECT_EQ(values[npos], it->second); npos++; @@ -80,7 +83,7 @@ TEST_F(OrderedMapTest, OrderedMapErase) TEST_F(OrderedMapTest, OrderedMapGetValue) { - OrderedMap<const INamed *, INamed *> omap; + OrderedMap<const INamed*, INamed*> omap; std::unique_ptr<INamed> key1(new INamed("key1")); std::unique_ptr<INamed> key2(new INamed("key2")); @@ -100,7 +103,7 @@ TEST_F(OrderedMapTest, OrderedMapGetValue) TEST_F(OrderedMapTest, OrderedMapFind) { - OrderedMap<const INamed *, std::string> omap; + OrderedMap<const INamed*, std::string> omap; std::unique_ptr<INamed> n1(new INamed("named1")); std::unique_ptr<INamed> n2(new INamed("named2")); @@ -110,7 +113,7 @@ TEST_F(OrderedMapTest, OrderedMapFind) omap.insert(n1.get(), "aaa"); omap.insert(n2.get(), "bbb"); omap.insert(n3.get(), "ccc"); - EXPECT_EQ( size_t(3), omap.size()); + EXPECT_EQ(size_t(3), omap.size()); EXPECT_EQ(omap.find(n1.get())->first, n1.get()); EXPECT_EQ(omap.find(n1.get())->first->getName(), "named1"); @@ -133,7 +136,7 @@ TEST_F(OrderedMapTest, OrderedMapReInsert) std::unique_ptr<INamed> P_n2(new INamed("named2")); std::unique_ptr<INamed> P_n3(new INamed("named3")); - OrderedMap<INamed *, double> omap; + OrderedMap<INamed*, double> omap; omap.insert(P_n1.get(), 1.0); omap.insert(P_n2.get(), 2.0); omap.insert(P_n3.get(), 3.0); diff --git a/Tests/UnitTests/Core/Other/RelDiffTest.h b/Tests/UnitTests/Core/Other/RelDiffTest.h index 08ba69166ad..46eb419a4ea 100644 --- a/Tests/UnitTests/Core/Other/RelDiffTest.h +++ b/Tests/UnitTests/Core/Other/RelDiffTest.h @@ -1,24 +1,23 @@ +#include "google_test.h" #include "Numeric.h" #include <algorithm> class RelDiffTest : public ::testing::Test { - protected: - RelDiffTest() {} - virtual ~RelDiffTest() {} +protected: + ~RelDiffTest(); }; +RelDiffTest::~RelDiffTest() = default; TEST_F(RelDiffTest, RelDiffAlmostEq) { - EXPECT_TRUE( Numeric::areAlmostEqual(+1e+120, +1e+120, 1.) ); - EXPECT_TRUE( Numeric::areAlmostEqual(+1e-120, +1e-120, 1.) ); - EXPECT_TRUE( Numeric::areAlmostEqual(0, 0, 1.) ); - EXPECT_TRUE( Numeric::areAlmostEqual(-1e-120, -1e-120, 1.) ); - EXPECT_TRUE( Numeric::areAlmostEqual(-1e+120, -1e+120, 1.) ); + EXPECT_TRUE(Numeric::areAlmostEqual(+1e+120, +1e+120, 1.)); + EXPECT_TRUE(Numeric::areAlmostEqual(+1e-120, +1e-120, 1.)); + EXPECT_TRUE(Numeric::areAlmostEqual(0, 0, 1.)); + EXPECT_TRUE(Numeric::areAlmostEqual(-1e-120, -1e-120, 1.)); + EXPECT_TRUE(Numeric::areAlmostEqual(-1e+120, -1e+120, 1.)); - EXPECT_FALSE( Numeric::areAlmostEqual(+1e+120, 0, 1.) ); -// EXPECT_FALSE( Numeric::areAlmostEqual(+1e-120, 0, 1.) ); -// EXPECT_FALSE( Numeric::areAlmostEqual(-1e-120, 0, 1.) ); - EXPECT_FALSE( Numeric::areAlmostEqual(-1e+120, 0, 1.) ); + EXPECT_FALSE(Numeric::areAlmostEqual(+1e+120, 0, 1.)); + EXPECT_FALSE(Numeric::areAlmostEqual(-1e+120, 0, 1.)); } diff --git a/Tests/UnitTests/Core/Other/SampleBuilderNoteTest.h b/Tests/UnitTests/Core/Other/SampleBuilderNoteTest.h index 176e4c20ea5..363a86f65a1 100644 --- a/Tests/UnitTests/Core/Other/SampleBuilderNoteTest.h +++ b/Tests/UnitTests/Core/Other/SampleBuilderNoteTest.h @@ -1,14 +1,16 @@ -#include "SampleBuilderNode.h" -#include "MultiLayer.h" +#include "google_test.h" #include "IMultiLayerBuilder.h" +#include "MultiLayer.h" #include "ParameterPool.h" -#include <memory> +#include "SampleBuilderNode.h" #include <iostream> +#include <memory> #include <stdexcept> -class SampleBuilderNoteTest : public ::testing::Test +class SampleBuilderNodeTest : public ::testing::Test { public: + ~SampleBuilderNodeTest(); //! Returns test multilayer. static std::unique_ptr<MultiLayer> testMultiLayer(double length) @@ -22,7 +24,7 @@ public: class TestBuilder : public IMultiLayerBuilder { public: - explicit TestBuilder(double length=42.0) : m_length(length) + explicit TestBuilder(double length = 42.0) : m_length(length) { setName("TestBuilder"); registerParameter("length", &m_length); @@ -31,14 +33,13 @@ public: MultiLayer* buildSample() const { return testMultiLayer(m_length).release(); } double m_length; }; - -protected: - SampleBuilderNoteTest() {} }; +SampleBuilderNodeTest::~SampleBuilderNodeTest() = default; + //! Checks children and pool parameters. -TEST_F(SampleBuilderNoteTest, builderParameters) +TEST_F(SampleBuilderNodeTest, builderParameters) { SampleBuilderNode builderNode; @@ -49,7 +50,7 @@ TEST_F(SampleBuilderNoteTest, builderParameters) EXPECT_EQ(bool(builderNode), false); // setting builder - std::shared_ptr<IMultiLayerBuilder> builder(new SampleBuilderNoteTest::TestBuilder(33.0)); + std::shared_ptr<IMultiLayerBuilder> builder(new SampleBuilderNodeTest::TestBuilder(33.0)); builderNode.setSampleBuilder(builder); EXPECT_EQ(bool(builderNode), true); @@ -75,10 +76,10 @@ TEST_F(SampleBuilderNoteTest, builderParameters) //! Checks assignment operator. -TEST_F(SampleBuilderNoteTest, assignmentOperator) +TEST_F(SampleBuilderNodeTest, assignmentOperator) { SampleBuilderNode builderNode; - std::shared_ptr<IMultiLayerBuilder> builder(new SampleBuilderNoteTest::TestBuilder(33.0)); + std::shared_ptr<IMultiLayerBuilder> builder(new SampleBuilderNodeTest::TestBuilder(33.0)); builderNode.setSampleBuilder(builder); // checking assignment diff --git a/Tests/UnitTests/Core/Other/SampleProviderTest.h b/Tests/UnitTests/Core/Other/SampleProviderTest.h index c14bef09882..bb4f341eb14 100644 --- a/Tests/UnitTests/Core/Other/SampleProviderTest.h +++ b/Tests/UnitTests/Core/Other/SampleProviderTest.h @@ -1,17 +1,16 @@ -#include "SampleProvider.h" -#include "MultiLayer.h" +#include "google_test.h" #include "IMultiLayerBuilder.h" +#include "MultiLayer.h" #include "ParameterPool.h" #include "RealParameter.h" +#include "SampleProvider.h" #include <memory> -#include <iostream> -#include <memory> -#include <iostream> - class SampleProviderTest : public ::testing::Test { public: + ~SampleProviderTest(); + //! Returns test multilayer. static std::unique_ptr<MultiLayer> testMultiLayer(double length) { @@ -30,8 +29,7 @@ public: registerChild(&m_provider); } - TestSimulation(const TestSimulation& other) - : m_provider(other.m_provider) + TestSimulation(const TestSimulation& other) : m_provider(other.m_provider) { setName("TestSimulation"); registerChild(&m_provider); @@ -39,15 +37,9 @@ public: void accept(INodeVisitor* visitor) const final { visitor->visit(this); } - std::vector<const INode*> getChildren() const - { - return m_provider.getChildren(); - } + std::vector<const INode*> getChildren() const { return m_provider.getChildren(); } - void setContainer(const SampleProvider& provider) - { - m_provider = provider; - } + void setContainer(const SampleProvider& provider) { m_provider = provider; } SampleProvider m_provider; }; @@ -55,7 +47,7 @@ public: class TestBuilder : public IMultiLayerBuilder { public: - explicit TestBuilder(double length=42.0) : m_length(length) + explicit TestBuilder(double length = 42.0) : m_length(length) { setName("TestBuilder"); registerParameter("length", &m_length); @@ -64,11 +56,10 @@ public: MultiLayer* buildSample() const { return testMultiLayer(m_length).release(); } double m_length; }; - -protected: - SampleProviderTest() {} }; +SampleProviderTest::~SampleProviderTest() = default; + //! Test initial state, assignment operator. TEST_F(SampleProviderTest, initialState) @@ -142,8 +133,6 @@ TEST_F(SampleProviderTest, sampleInSimulationContext) EXPECT_FALSE(sim.treeToString().empty()); EXPECT_FALSE(sim.parametersToString().empty()); -// std::cout << sim.treeToString() << std::endl; -// std::cout << sim.parametersToString() << std::endl; // creating second simulation via copy-construction SampleProviderTest::TestSimulation sim2(sim); @@ -158,7 +147,6 @@ TEST_F(SampleProviderTest, sampleInSimulationContext) std::unique_ptr<ParameterPool> pool(sim2.createParameterTree()); ASSERT_EQ(pool->size(), 4u); EXPECT_TRUE(pool->parameter("/TestSimulation/MultiLayer/CrossCorrelationLength") != nullptr); - } //! Test parentship of container and builder in simulation context. @@ -176,8 +164,6 @@ TEST_F(SampleProviderTest, builderInSimulationContext) EXPECT_EQ(provider.sample()->parent(), nullptr); ASSERT_EQ(provider.getChildren().size(), 1u); -// std::cout << sim.treeToString() << std::endl; -// std::cout << sim.parametersToString() << std::endl; EXPECT_FALSE(sim.treeToString().empty()); EXPECT_FALSE(sim.parametersToString().empty()); @@ -188,5 +174,4 @@ TEST_F(SampleProviderTest, builderInSimulationContext) std::unique_ptr<ParameterPool> pool(sim2.createParameterTree()); ASSERT_EQ(pool->size(), 1u); EXPECT_EQ(pool->parameter("/TestSimulation/TestBuilder/length")->value(), 33.0); - } diff --git a/Tests/UnitTests/Core/Other/Shape2DTest.h b/Tests/UnitTests/Core/Other/Shape2DTest.h index eaad672f541..56cec783aba 100644 --- a/Tests/UnitTests/Core/Other/Shape2DTest.h +++ b/Tests/UnitTests/Core/Other/Shape2DTest.h @@ -1,16 +1,19 @@ -#include "Rectangle.h" +#include "google_test.h" #include "Bin.h" #include "Ellipse.h" #include "Line.h" #include "MathConstants.h" +#include "Rectangle.h" #include "Units.h" #include <memory> class Shape2DTest : public ::testing::Test { public: + ~Shape2DTest(); }; +Shape2DTest::~Shape2DTest() = default; TEST_F(Shape2DTest, Rectangle) { @@ -56,7 +59,7 @@ TEST_F(Shape2DTest, Ellipse) EXPECT_FALSE(ellipse.contains(4.0, -2.0)); EXPECT_TRUE(ellipse.contains(6.0, -2.0)); - Ellipse ellipse2(10.0, 1.0, 8.0, 4.0, 45.0*Units::degree); + Ellipse ellipse2(10.0, 1.0, 8.0, 4.0, 45.0 * Units::degree); EXPECT_TRUE(ellipse2.contains(10.0, 1.0)); EXPECT_FALSE(ellipse2.contains(15.0, 0.0)); EXPECT_TRUE(ellipse2.contains(7.0, 3.0)); @@ -76,12 +79,12 @@ TEST_F(Shape2DTest, Line) EXPECT_FALSE(line.contains(1.01, 0.0)); Line line2(0.0, 0.0, 1.0, 1.0); - EXPECT_TRUE(line2.contains(Bin1D(0.5, 1.0),Bin1D(0.0, 0.5))); - EXPECT_FALSE(line2.contains(Bin1D(0.51, 1.0),Bin1D(0.0, 0.49))); + EXPECT_TRUE(line2.contains(Bin1D(0.5, 1.0), Bin1D(0.0, 0.5))); + EXPECT_FALSE(line2.contains(Bin1D(0.51, 1.0), Bin1D(0.0, 0.49))); std::unique_ptr<Line> clone(line2.clone()); - EXPECT_TRUE(clone->contains(Bin1D(0.5, 1.0),Bin1D(0.0, 0.5))); - EXPECT_FALSE(clone->contains(Bin1D(0.51, 1.0),Bin1D(0.0, 0.49))); + EXPECT_TRUE(clone->contains(Bin1D(0.5, 1.0), Bin1D(0.0, 0.5))); + EXPECT_FALSE(clone->contains(Bin1D(0.51, 1.0), Bin1D(0.0, 0.49))); } TEST_F(Shape2DTest, VerticalLine) diff --git a/Tests/UnitTests/Core/Other/TRangeTest.h b/Tests/UnitTests/Core/Other/TRangeTest.h index 892d28f5469..f0ec5cde743 100644 --- a/Tests/UnitTests/Core/Other/TRangeTest.h +++ b/Tests/UnitTests/Core/Other/TRangeTest.h @@ -1,29 +1,30 @@ +#include "google_test.h" #include "TRange.h" #include <algorithm> class TRangeTest : public ::testing::Test { - protected: +protected: TRangeTest(); virtual ~TRangeTest(); - const TRange<int> *intRange; - const TRange<float> *floatRange; - const TRange<double> *doubleRange; - const TSampledRange<int> *intSampledRange; - const TSampledRange<float> *floatSampledRange; - const TSampledRange<double> *doubleSampledRange; + const TRange<int>* intRange; + const TRange<float>* floatRange; + const TRange<double>* doubleRange; + const TSampledRange<int>* intSampledRange; + const TSampledRange<float>* floatSampledRange; + const TSampledRange<double>* doubleSampledRange; }; TRangeTest::TRangeTest() { - intRange = new TRange<int>(1,100); + intRange = new TRange<int>(1, 100); floatRange = new TRange<float>(101.0f, 200.0f); - doubleRange = new TRange<double>(201.0,300.0); + doubleRange = new TRange<double>(201.0, 300.0); intSampledRange = new TSampledRange<int>(4000u, 1, 100); floatSampledRange = new TSampledRange<float>(5000u, 101.0f, 200.0f); - doubleSampledRange = new TSampledRange<double>(6000u, 201.0,300.0); + doubleSampledRange = new TSampledRange<double>(6000u, 201.0, 300.0); } TRangeTest::~TRangeTest() @@ -48,7 +49,6 @@ TEST_F(TRangeTest, TRangeTestUpperBound) EXPECT_EQ(100, intRange->getUpperBound()); EXPECT_EQ(200.0f, floatRange->getUpperBound()); EXPECT_EQ(300.0, doubleRange->getUpperBound()); - } TEST_F(TRangeTest, TRangeTestDifference) @@ -79,7 +79,6 @@ TEST_F(TRangeTest, TRangeTestInRange) EXPECT_FALSE(intRange->inRange(101)); EXPECT_FALSE(floatRange->inRange(201.0f)); EXPECT_FALSE(doubleRange->inRange(301.0)); - } TEST_F(TRangeTest, TSampledRangeNSamples) diff --git a/Tests/UnitTests/Core/Other/ThreadInfoTest.h b/Tests/UnitTests/Core/Other/ThreadInfoTest.h index e7f484b12d6..985a5bd021d 100644 --- a/Tests/UnitTests/Core/Other/ThreadInfoTest.h +++ b/Tests/UnitTests/Core/Other/ThreadInfoTest.h @@ -1,30 +1,16 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/UnitTests/Core/Other/ThreadInfoTest.h -//! @brief Defines unit test for ThreadInfo class. -//! -//! @homepage http://bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - +#include "google_test.h" #include "ThreadInfo.h" - class ThreadInfoTest : public ::testing::Test { - protected: - ThreadInfoTest() - : thread_info() {} +protected: + ~ThreadInfoTest(); ThreadInfo thread_info; }; +ThreadInfoTest::~ThreadInfoTest() = default; + TEST_F(ThreadInfoTest, DefaultValues) { EXPECT_EQ(1, thread_info.n_batches); diff --git a/Tests/UnitTests/Core/Other/ZLimitsTest.h b/Tests/UnitTests/Core/Other/ZLimitsTest.h index 32742a22e9e..8f53542f0f5 100644 --- a/Tests/UnitTests/Core/Other/ZLimitsTest.h +++ b/Tests/UnitTests/Core/Other/ZLimitsTest.h @@ -1,18 +1,14 @@ +#include "google_test.h" #include "ZLimits.h" #include <stdexcept> class ZLimitsTest : public ::testing::Test { - protected: - ZLimitsTest(); - virtual ~ZLimitsTest(); +protected: + ~ZLimitsTest(); }; -ZLimitsTest::ZLimitsTest() -{} - -ZLimitsTest::~ZLimitsTest() -{} +ZLimitsTest::~ZLimitsTest() = default; TEST_F(ZLimitsTest, ZLimitsDefaultConstructor) { @@ -23,27 +19,27 @@ TEST_F(ZLimitsTest, ZLimitsDefaultConstructor) TEST_F(ZLimitsTest, ZLimitsMinMaxConstructor) { - ZLimits limits { -4.0, 1.5 }; + ZLimits limits{-4.0, 1.5}; EXPECT_FALSE(limits.lowerLimit().m_limitless); EXPECT_EQ(-4.0, limits.lowerLimit().m_value); EXPECT_FALSE(limits.upperLimit().m_limitless); EXPECT_EQ(1.5, limits.upperLimit().m_value); - limits = ZLimits { -4.0, -4.0 }; + limits = ZLimits{-4.0, -4.0}; EXPECT_FALSE(limits.lowerLimit().m_limitless); EXPECT_EQ(-4.0, limits.lowerLimit().m_value); EXPECT_FALSE(limits.upperLimit().m_limitless); EXPECT_EQ(-4.0, limits.upperLimit().m_value); - EXPECT_THROW(limits = ZLimits(-4.0, -5.0) , std::runtime_error); + EXPECT_THROW(limits = ZLimits(-4.0, -5.0), std::runtime_error); } TEST_F(ZLimitsTest, ZLimitsOneSidedLimitConstructor) { - ZLimits limits1 { { true, -4.0 }, { true, 1.5 } }; - ZLimits limits2 { { false, -4.0 }, { true, 1.5 } }; - ZLimits limits3 { { true, -4.0 }, { false, 1.5 } }; - ZLimits limits4 { { false, -4.0 }, { false, 1.5 } }; + ZLimits limits1{{true, -4.0}, {true, 1.5}}; + ZLimits limits2{{false, -4.0}, {true, 1.5}}; + ZLimits limits3{{true, -4.0}, {false, 1.5}}; + ZLimits limits4{{false, -4.0}, {false, 1.5}}; EXPECT_TRUE(limits1.lowerLimit().m_limitless); - EXPECT_TRUE( limits1.upperLimit().m_limitless); + EXPECT_TRUE(limits1.upperLimit().m_limitless); EXPECT_FALSE(limits2.lowerLimit().m_limitless); EXPECT_EQ(-4.0, limits2.lowerLimit().m_value); EXPECT_TRUE(limits2.upperLimit().m_limitless); @@ -54,10 +50,10 @@ TEST_F(ZLimitsTest, ZLimitsOneSidedLimitConstructor) EXPECT_EQ(-4.0, limits4.lowerLimit().m_value); EXPECT_FALSE(limits4.upperLimit().m_limitless); EXPECT_EQ(1.5, limits4.upperLimit().m_value); - EXPECT_NO_THROW(ZLimits limits5({ true, -4.0 }, { true, -5.0 }) ); - EXPECT_NO_THROW(ZLimits limits6({ false, -4.0 }, { true, -5.0 }) ); - EXPECT_NO_THROW(ZLimits limits7({ true, -4.0 }, { false, -5.0 }) ); - EXPECT_THROW(ZLimits limits8({ false, -4.0 }, { false, -5.0 }), std::runtime_error); + EXPECT_NO_THROW(ZLimits limits5({true, -4.0}, {true, -5.0})); + EXPECT_NO_THROW(ZLimits limits6({false, -4.0}, {true, -5.0})); + EXPECT_NO_THROW(ZLimits limits7({true, -4.0}, {false, -5.0})); + EXPECT_THROW(ZLimits limits8({false, -4.0}, {false, -5.0}), std::runtime_error); } TEST_F(ZLimitsTest, ZLimitsIsFinite) diff --git a/Tests/UnitTests/Core/Parameters/DistributionHandlerTest.h b/Tests/UnitTests/Core/Parameters/DistributionHandlerTest.h index 94bf4a8c834..e0b4a0d8205 100644 --- a/Tests/UnitTests/Core/Parameters/DistributionHandlerTest.h +++ b/Tests/UnitTests/Core/Parameters/DistributionHandlerTest.h @@ -1,6 +1,7 @@ -#include "IParameterized.h" +#include "google_test.h" #include "DistributionHandler.h" #include "Distributions.h" +#include "IParameterized.h" #include "ParameterPool.h" #include <cmath> @@ -8,10 +9,12 @@ class DistributionHandlerTest : public ::testing::Test { protected: DistributionHandlerTest() : m_value(99.0) {} - virtual ~DistributionHandlerTest(){} + ~DistributionHandlerTest(); double m_value; }; +DistributionHandlerTest::~DistributionHandlerTest() = default; + TEST_F(DistributionHandlerTest, DistributionHandlerConstructor) { DistributionHandler handler; @@ -20,22 +23,11 @@ TEST_F(DistributionHandlerTest, DistributionHandlerConstructor) EXPECT_EQ(size_t(1), handler.getTotalNumberOfSamples()); handler.addParameterDistribution(paraName, distribution, 2, 1.0); EXPECT_EQ(size_t(2), handler.getTotalNumberOfSamples()); - EXPECT_EQ("DistributionHandler",handler.getName()); + EXPECT_EQ("DistributionHandler", handler.getName()); - const DistributionHandler::Distributions_t &distr = handler.getDistributions(); + const DistributionHandler::Distributions_t& distr = handler.getDistributions(); ParameterDistribution distribution1 = distr[0]; EXPECT_EQ(distribution1.getName(), "ParameterDistribution"); EXPECT_EQ(distribution1.getNbrSamples(), size_t(2)); EXPECT_EQ(distribution1.getSigmaFactor(), 1.0); - - /* TEMPORARILY DISABLED getParameterPool() - ParameterPool* parameterPool = distribution1.getParameterPool(); - parameterPool->registerParameter("value",&m_value); - handler.setParameterValues(parameterPool, 0); - EXPECT_EQ(m_value, 1.0); - handler.setParameterValues(parameterPool, 1); - EXPECT_EQ(m_value, 2.0); - - delete parameterPool; - */ } diff --git a/Tests/UnitTests/Core/Parameters/DistributionsTest.h b/Tests/UnitTests/Core/Parameters/DistributionsTest.h index cabb52345a2..4b5dc669d29 100644 --- a/Tests/UnitTests/Core/Parameters/DistributionsTest.h +++ b/Tests/UnitTests/Core/Parameters/DistributionsTest.h @@ -1,23 +1,26 @@ -#include "MathConstants.h" +#include "google_test.h" #include "BornAgainNamespace.h" #include "Distributions.h" #include "Exceptions.h" -#include "RealParameter.h" +#include "MathConstants.h" #include "ParameterSample.h" +#include "RealParameter.h" #include <cmath> #include <memory> class DistributionsTest : public ::testing::Test { protected: - DistributionsTest() {} + ~DistributionsTest(); }; +DistributionsTest::~DistributionsTest() = default; + // -------------------------------------------------------------------------- // TEST_F(DistributionsTest, DistributionGateDefaultConstructor) { - std::unique_ptr<DistributionGate> P_distr_gate { new DistributionGate() }; + std::unique_ptr<DistributionGate> P_distr_gate{new DistributionGate()}; EXPECT_EQ(0.5, P_distr_gate->getMean()); EXPECT_EQ(0.0, P_distr_gate->getMin()); EXPECT_EQ(1.0, P_distr_gate->getMax()); @@ -67,11 +70,11 @@ TEST_F(DistributionsTest, DistributionGateConstructor) std::vector<ParameterSample> samples = distr2.equidistantSamples(3); EXPECT_EQ(samples.size(), size_t(3)); EXPECT_EQ(samples[0].value, 1.0); - EXPECT_EQ(samples[0].weight, 1./3.); + EXPECT_EQ(samples[0].weight, 1. / 3.); EXPECT_EQ(samples[1].value, 1.5); - EXPECT_EQ(samples[1].weight, 1./3.); + EXPECT_EQ(samples[1].weight, 1. / 3.); EXPECT_EQ(samples[2].value, 2.0); - EXPECT_EQ(samples[2].weight, 1./3.); + EXPECT_EQ(samples[2].weight, 1. / 3.); } TEST_F(DistributionsTest, DistributionGateParameters) @@ -95,7 +98,7 @@ TEST_F(DistributionsTest, DistributionGateParameters) TEST_F(DistributionsTest, DistributionGateClone) { DistributionGate gate(2.0, 3.0); - DistributionGate *clone = gate.clone(); + DistributionGate* clone = gate.clone(); EXPECT_EQ(gate.getName(), clone->getName()); EXPECT_EQ(gate.getMean(), clone->getMean()); EXPECT_EQ(gate.getMin(), clone->getMin()); @@ -103,16 +106,15 @@ TEST_F(DistributionsTest, DistributionGateClone) delete clone; } - // -------------------------------------------------------------------------- // TEST_F(DistributionsTest, DistributionLorentzDefaultConstructor) { - std::unique_ptr<DistributionLorentz> P_distr_lorentz { new DistributionLorentz() }; + std::unique_ptr<DistributionLorentz> P_distr_lorentz{new DistributionLorentz()}; EXPECT_EQ(0.0, P_distr_lorentz->getMean()); EXPECT_EQ(1.0, P_distr_lorentz->getHWHM()); EXPECT_EQ(BornAgain::DistributionLorentzType, P_distr_lorentz->getName()); - EXPECT_EQ(1/(M_TWOPI), P_distr_lorentz->probabilityDensity(1.0)); + EXPECT_EQ(1 / (M_TWOPI), P_distr_lorentz->probabilityDensity(1.0)); std::vector<double> list1 = P_distr_lorentz->equidistantPoints(1, 0.0); EXPECT_EQ(P_distr_lorentz->getMean(), list1[0]); @@ -135,7 +137,7 @@ TEST_F(DistributionsTest, DistributionLorentzConstructor) EXPECT_EQ(1.0, distr2.getMean()); EXPECT_EQ(1.0, distr2.getHWHM()); EXPECT_EQ(BornAgain::DistributionLorentzType, distr2.getName()); - EXPECT_EQ(1.0/M_PI, distr2.probabilityDensity(1.0)); + EXPECT_EQ(1.0 / M_PI, distr2.probabilityDensity(1.0)); std::vector<double> list2 = distr2.equidistantPoints(1, 0.0); EXPECT_EQ(distr2.getMean(), list2[0]); @@ -161,8 +163,8 @@ TEST_F(DistributionsTest, DistributionLorentzParameters) TEST_F(DistributionsTest, DistributionLorentzClone) { - std::unique_ptr<DistributionLorentz> P_distr_lorentz { new DistributionLorentz(1.0, 2.0) }; - std::unique_ptr<DistributionLorentz> P_clone { P_distr_lorentz->clone() }; + std::unique_ptr<DistributionLorentz> P_distr_lorentz{new DistributionLorentz(1.0, 2.0)}; + std::unique_ptr<DistributionLorentz> P_clone{P_distr_lorentz->clone()}; EXPECT_EQ(1.0, P_clone->getMean()); EXPECT_EQ(2.0, P_clone->getHWHM()); EXPECT_EQ(BornAgain::DistributionLorentzType, P_clone->getName()); @@ -179,21 +181,21 @@ TEST_F(DistributionsTest, DistributionLorentzSamples) std::vector<ParameterSample> samples = distr.equidistantSamples(nbr_samples, sigma_factor); EXPECT_EQ(samples.size(), size_t(nbr_samples)); - EXPECT_EQ(samples[0].value, 1.0 - sigma_factor*0.1); + EXPECT_EQ(samples[0].value, 1.0 - sigma_factor * 0.1); EXPECT_EQ(samples[1].value, 1.0); - EXPECT_EQ(samples[2].value, 1.0 + sigma_factor*0.1); + EXPECT_EQ(samples[2].value, 1.0 + sigma_factor * 0.1); double d1 = distr.probabilityDensity(samples[0].value); double d2 = distr.probabilityDensity(samples[1].value); double d3 = distr.probabilityDensity(samples[2].value); - EXPECT_EQ(samples[0].weight, d1/(d1+d2+d3)); - EXPECT_EQ(samples[1].weight, d2/(d1+d2+d3)); - EXPECT_EQ(samples[2].weight, d3/(d1+d2+d3)); + EXPECT_EQ(samples[0].weight, d1 / (d1 + d2 + d3)); + EXPECT_EQ(samples[1].weight, d2 / (d1 + d2 + d3)); + EXPECT_EQ(samples[2].weight, d3 / (d1 + d2 + d3)); // with Limits samples = distr.equidistantSamples(nbr_samples, sigma_factor, RealLimits::lowerLimited(0.99)); EXPECT_EQ(samples[0].value, 0.99); - EXPECT_EQ(samples[1].value, samples[0].value + (samples[2].value - samples[0].value)/2.0); - EXPECT_EQ(samples[2].value, 1.0 + sigma_factor*0.1); + EXPECT_EQ(samples[1].value, samples[0].value + (samples[2].value - samples[0].value) / 2.0); + EXPECT_EQ(samples[2].value, 1.0 + sigma_factor * 0.1); // with xmin, xmax samples = distr.equidistantSamplesInRange(nbr_samples, 0.8, 1.2); @@ -206,10 +208,10 @@ TEST_F(DistributionsTest, DistributionLorentzSamples) TEST_F(DistributionsTest, DistributionGaussianDefaultConstructor) { - std::unique_ptr<DistributionGaussian> P_distr_gauss { new DistributionGaussian() }; + std::unique_ptr<DistributionGaussian> P_distr_gauss{new DistributionGaussian()}; EXPECT_EQ(0.0, P_distr_gauss->getMean()); EXPECT_EQ(1.0, P_distr_gauss->getStdDev()); - EXPECT_EQ(std::exp(-1.0/2.0)/std::sqrt(M_TWOPI), P_distr_gauss->probabilityDensity(1.0)); + EXPECT_EQ(std::exp(-1.0 / 2.0) / std::sqrt(M_TWOPI), P_distr_gauss->probabilityDensity(1.0)); EXPECT_EQ(BornAgain::DistributionGaussianType, P_distr_gauss->getName()); std::vector<double> list1 = P_distr_gauss->equidistantPoints(1, 0.0); @@ -232,7 +234,7 @@ TEST_F(DistributionsTest, DistributionGaussianConstructor) DistributionGaussian distr2(1.0, 1.0); EXPECT_EQ(1.0, distr2.getMean()); EXPECT_EQ(1.0, distr2.getStdDev()); - EXPECT_EQ(1/std::sqrt(M_TWOPI), distr2.probabilityDensity(1.0)); + EXPECT_EQ(1 / std::sqrt(M_TWOPI), distr2.probabilityDensity(1.0)); EXPECT_EQ(BornAgain::DistributionGaussianType, distr2.getName()); std::vector<double> list2 = distr2.equidistantPoints(1, 0.0); @@ -259,11 +261,11 @@ TEST_F(DistributionsTest, DistributionGaussianParameters) TEST_F(DistributionsTest, DistributionGaussianClone) { - std::unique_ptr<DistributionGaussian> P_distr_gauss { new DistributionGaussian(1.0, 1.0) }; - std::unique_ptr<DistributionGaussian> P_clone { P_distr_gauss->clone() }; + std::unique_ptr<DistributionGaussian> P_distr_gauss{new DistributionGaussian(1.0, 1.0)}; + std::unique_ptr<DistributionGaussian> P_clone{P_distr_gauss->clone()}; EXPECT_EQ(1.0, P_clone->getMean()); EXPECT_EQ(1.0, P_clone->getStdDev()); - EXPECT_EQ(1/std::sqrt(M_TWOPI), P_clone->probabilityDensity(1.0)); + EXPECT_EQ(1 / std::sqrt(M_TWOPI), P_clone->probabilityDensity(1.0)); EXPECT_EQ(BornAgain::DistributionGaussianType, P_clone->getName()); std::vector<double> list1 = P_clone->equidistantPoints(1, 0.0); @@ -289,7 +291,7 @@ TEST_F(DistributionsTest, DistributionLogNormalConstructorWithOneParameter) EXPECT_EQ(1.0, distr2.getMedian()); EXPECT_EQ(1.0, distr2.getScalePar()); EXPECT_EQ(std::exp(0.5), distr2.getMean()); - EXPECT_EQ(1.0/std::sqrt(M_TWOPI), distr2.probabilityDensity(1.0)); + EXPECT_EQ(1.0 / std::sqrt(M_TWOPI), distr2.probabilityDensity(1.0)); EXPECT_EQ(BornAgain::DistributionLogNormalType, distr2.getName()); std::vector<double> list2 = distr2.equidistantPoints(1, 0.0); @@ -302,11 +304,11 @@ TEST_F(DistributionsTest, DistributionLogNormalConstructorWithOneParameter) TEST_F(DistributionsTest, DistributionLogNormalConstructorWithTwoParameter) { - std::unique_ptr<DistributionLogNormal> P_distr_lognormal { new DistributionLogNormal(1.0,1.0) }; + std::unique_ptr<DistributionLogNormal> P_distr_lognormal{new DistributionLogNormal(1.0, 1.0)}; EXPECT_EQ(1.0, P_distr_lognormal->getMedian()); EXPECT_EQ(1.0, P_distr_lognormal->getScalePar()); EXPECT_EQ(std::exp(0.5), P_distr_lognormal->getMean()); - EXPECT_EQ(1.0/std::sqrt(M_TWOPI), P_distr_lognormal->probabilityDensity(1.0)); + EXPECT_EQ(1.0 / std::sqrt(M_TWOPI), P_distr_lognormal->probabilityDensity(1.0)); EXPECT_EQ(BornAgain::DistributionLogNormalType, P_distr_lognormal->getName()); std::vector<double> list1 = P_distr_lognormal->equidistantPoints(1, 0.0); @@ -333,18 +335,18 @@ TEST_F(DistributionsTest, DistributionLogNormalParameters) TEST_F(DistributionsTest, DistributionLogNormalClone) { - std::unique_ptr<DistributionLogNormal> P_distr_lognormal { new DistributionLogNormal(1.0, 1.0) }; - std::unique_ptr<DistributionLogNormal> P_clone { P_distr_lognormal->clone() }; + std::unique_ptr<DistributionLogNormal> P_distr_lognormal{new DistributionLogNormal(1.0, 1.0)}; + std::unique_ptr<DistributionLogNormal> P_clone{P_distr_lognormal->clone()}; EXPECT_EQ(1.0, P_distr_lognormal->getMedian()); EXPECT_EQ(1.0, P_distr_lognormal->getScalePar()); EXPECT_EQ(std::exp(0.5), P_distr_lognormal->getMean()); - EXPECT_EQ(1/std::sqrt(M_TWOPI), P_distr_lognormal->probabilityDensity(1.0)); + EXPECT_EQ(1 / std::sqrt(M_TWOPI), P_distr_lognormal->probabilityDensity(1.0)); EXPECT_EQ(BornAgain::DistributionLogNormalType, P_distr_lognormal->getName()); std::vector<double> list1 = P_distr_lognormal->equidistantPoints(1, 0.0); EXPECT_EQ(P_distr_lognormal->getMedian(), list1[0]); - std::vector<double> list2 = P_distr_lognormal->equidistantPoints(2,0.0); + std::vector<double> list2 = P_distr_lognormal->equidistantPoints(2, 0.0); EXPECT_EQ(std::exp(-2), list2[0]); EXPECT_EQ(std::exp(-2) + std::exp(2) - std::exp(-2), list2[1]); } @@ -353,10 +355,10 @@ TEST_F(DistributionsTest, DistributionLogNormalClone) TEST_F(DistributionsTest, DistributionCosineDefaultConstructor) { - std::unique_ptr<DistributionCosine> P_distr_cosine { new DistributionCosine() }; + std::unique_ptr<DistributionCosine> P_distr_cosine{new DistributionCosine()}; EXPECT_EQ(0.0, P_distr_cosine->getMean()); EXPECT_EQ(1.0, P_distr_cosine->getSigma()); - EXPECT_DOUBLE_EQ((1.0+std::cos(1.0))/(M_TWOPI), P_distr_cosine->probabilityDensity(1.0)); + EXPECT_DOUBLE_EQ((1.0 + std::cos(1.0)) / (M_TWOPI), P_distr_cosine->probabilityDensity(1.0)); EXPECT_EQ(0, P_distr_cosine->probabilityDensity(100.0)); EXPECT_EQ(BornAgain::DistributionCosineType, P_distr_cosine->getName()); @@ -377,10 +379,10 @@ TEST_F(DistributionsTest, DistributionCosineConstructor) EXPECT_EQ(1.0, list1[0]); // Test distribution with sigma > 0.0: - DistributionCosine distr2(1.0,1.0); + DistributionCosine distr2(1.0, 1.0); EXPECT_EQ(1.0, distr2.getMean()); EXPECT_EQ(1.0, distr2.getSigma()); - EXPECT_EQ(2.0/(M_TWOPI), distr2.probabilityDensity(1.0)); + EXPECT_EQ(2.0 / (M_TWOPI), distr2.probabilityDensity(1.0)); EXPECT_EQ(0, distr2.probabilityDensity(100.0)); EXPECT_EQ(BornAgain::DistributionCosineType, distr2.getName()); @@ -388,8 +390,8 @@ TEST_F(DistributionsTest, DistributionCosineConstructor) EXPECT_EQ(distr2.getMean(), list2[0]); std::vector<double> list3 = distr2.equidistantPoints(2, 0.0); - EXPECT_EQ(1-M_PI, list3[0]); - EXPECT_EQ(1+M_PI, list3[1]); + EXPECT_EQ(1 - M_PI, list3[0]); + EXPECT_EQ(1 + M_PI, list3[1]); } TEST_F(DistributionsTest, DistributionCosineParameters) @@ -408,11 +410,11 @@ TEST_F(DistributionsTest, DistributionCosineParameters) TEST_F(DistributionsTest, DistributionCosineClone) { - std::unique_ptr<DistributionCosine> P_distr_cosine { new DistributionCosine(1.0,1.0) }; - std::unique_ptr<DistributionCosine> P_clone { P_distr_cosine->clone() }; + std::unique_ptr<DistributionCosine> P_distr_cosine{new DistributionCosine(1.0, 1.0)}; + std::unique_ptr<DistributionCosine> P_clone{P_distr_cosine->clone()}; EXPECT_EQ(1.0, P_clone->getMean()); EXPECT_EQ(1.0, P_clone->getSigma()); - EXPECT_EQ(2.0/(M_TWOPI), P_clone->probabilityDensity(1.0)); + EXPECT_EQ(2.0 / (M_TWOPI), P_clone->probabilityDensity(1.0)); EXPECT_EQ(0, P_distr_cosine->probabilityDensity(100.0)); EXPECT_EQ(BornAgain::DistributionCosineType, P_clone->getName()); @@ -420,6 +422,6 @@ TEST_F(DistributionsTest, DistributionCosineClone) EXPECT_EQ(P_clone->getMean(), list1[0]); std::vector<double> list2 = P_clone->equidistantPoints(2, 0.0); - EXPECT_EQ(1-M_PI, list2[0]); - EXPECT_EQ(1+M_PI, list2[1]); + EXPECT_EQ(1 - M_PI, list2[0]); + EXPECT_EQ(1 + M_PI, list2[1]); } diff --git a/Tests/UnitTests/Core/Parameters/FTDistributionsTest.h b/Tests/UnitTests/Core/Parameters/FTDistributionsTest.h index 5ecac31d5da..4e8d9a74c90 100644 --- a/Tests/UnitTests/Core/Parameters/FTDistributionsTest.h +++ b/Tests/UnitTests/Core/Parameters/FTDistributionsTest.h @@ -1,23 +1,26 @@ +#include "google_test.h" +#include "BornAgainNamespace.h" #include "FTDistributions1D.h" #include "FTDistributions2D.h" -#include "BornAgainNamespace.h" #include "MathConstants.h" #include <memory> class FTDistributionsTest : public ::testing::Test { protected: - FTDistributionsTest() {} + ~FTDistributionsTest(); }; +FTDistributionsTest::~FTDistributionsTest() = default; + // test 1D TEST_F(FTDistributionsTest, FTDistribution1DCauchyConstructor) { - std::unique_ptr<IFTDistribution1D> P_1d_cauchy { new FTDistribution1DCauchy(1.0) }; + std::unique_ptr<IFTDistribution1D> P_1d_cauchy{new FTDistribution1DCauchy(1.0)}; EXPECT_EQ(1.0, P_1d_cauchy->omega()); EXPECT_EQ(BornAgain::FTDistribution1DCauchyType, P_1d_cauchy->getName()); - EXPECT_NEAR(0.961538, P_1d_cauchy->evaluate(0.2),0.000001); + EXPECT_NEAR(0.961538, P_1d_cauchy->evaluate(0.2), 0.000001); P_1d_cauchy->setOmega(3.0); EXPECT_EQ(3.0, P_1d_cauchy->omega()); @@ -28,20 +31,20 @@ TEST_F(FTDistributionsTest, FTDistribution1DCauchyConstructor) TEST_F(FTDistributionsTest, FTDistribution1DCauchyClone) { - std::unique_ptr<IFTDistribution1D> P_1d_cauchy { new FTDistribution1DCauchy(5.0) }; - std::unique_ptr<IFTDistribution1D> P_clone { P_1d_cauchy->clone() }; + std::unique_ptr<IFTDistribution1D> P_1d_cauchy{new FTDistribution1DCauchy(5.0)}; + std::unique_ptr<IFTDistribution1D> P_clone{P_1d_cauchy->clone()}; EXPECT_EQ(5.0, P_clone->omega()); EXPECT_EQ(BornAgain::FTDistribution1DCauchyType, P_clone->getName()); - EXPECT_NEAR(0.5, P_clone->evaluate(0.2),0.000001); + EXPECT_NEAR(0.5, P_clone->evaluate(0.2), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution1DGaussConstructor) { - std::unique_ptr<IFTDistribution1D> P_1d_gauss { new FTDistribution1DGauss(1.0) }; + std::unique_ptr<IFTDistribution1D> P_1d_gauss{new FTDistribution1DGauss(1.0)}; EXPECT_EQ(1.0, P_1d_gauss->omega()); EXPECT_EQ(BornAgain::FTDistribution1DGaussType, P_1d_gauss->getName()); - EXPECT_NEAR(0.9801987, P_1d_gauss->evaluate(0.2),0.000001); + EXPECT_NEAR(0.9801987, P_1d_gauss->evaluate(0.2), 0.000001); P_1d_gauss->setOmega(3.0); EXPECT_EQ(3.0, P_1d_gauss->omega()); @@ -49,20 +52,20 @@ TEST_F(FTDistributionsTest, FTDistribution1DGaussConstructor) TEST_F(FTDistributionsTest, FTDistribution1DGaussClone) { - std::unique_ptr<IFTDistribution1D> P_1d_gauss { new FTDistribution1DGauss(5.0) }; - std::unique_ptr<IFTDistribution1D> P_clone { P_1d_gauss->clone() }; + std::unique_ptr<IFTDistribution1D> P_1d_gauss{new FTDistribution1DGauss(5.0)}; + std::unique_ptr<IFTDistribution1D> P_clone{P_1d_gauss->clone()}; EXPECT_EQ(5.0, P_clone->omega()); EXPECT_EQ(BornAgain::FTDistribution1DGaussType, P_clone->getName()); - EXPECT_NEAR(0.6065307, P_clone->evaluate(0.2),0.000001); + EXPECT_NEAR(0.6065307, P_clone->evaluate(0.2), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution1DGateConstructor) { - std::unique_ptr<IFTDistribution1D> P_1d_gate { new FTDistribution1DGate(1.0) }; + std::unique_ptr<IFTDistribution1D> P_1d_gate{new FTDistribution1DGate(1.0)}; EXPECT_EQ(1.0, P_1d_gate->omega()); EXPECT_EQ(BornAgain::FTDistribution1DGateType, P_1d_gate->getName()); - EXPECT_NEAR(0.993347, P_1d_gate->evaluate(0.2),0.000001); + EXPECT_NEAR(0.993347, P_1d_gate->evaluate(0.2), 0.000001); P_1d_gate->setOmega(3.0); EXPECT_EQ(3.0, P_1d_gate->omega()); @@ -70,20 +73,20 @@ TEST_F(FTDistributionsTest, FTDistribution1DGateConstructor) TEST_F(FTDistributionsTest, FTDistribution1DGateClone) { - std::unique_ptr<IFTDistribution1D> P_1d_gate { new FTDistribution1DGate(5.0) }; - std::unique_ptr<IFTDistribution1D> P_clone { P_1d_gate->clone() }; + std::unique_ptr<IFTDistribution1D> P_1d_gate{new FTDistribution1DGate(5.0)}; + std::unique_ptr<IFTDistribution1D> P_clone{P_1d_gate->clone()}; EXPECT_EQ(5.0, P_clone->omega()); EXPECT_EQ(BornAgain::FTDistribution1DGateType, P_clone->getName()); - EXPECT_NEAR(0.841471, P_clone->evaluate(0.2),0.000001); + EXPECT_NEAR(0.841471, P_clone->evaluate(0.2), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution1DTriangleConstructor) { - std::unique_ptr<IFTDistribution1D> P_1d_triangle { new FTDistribution1DTriangle(1.0) }; + std::unique_ptr<IFTDistribution1D> P_1d_triangle{new FTDistribution1DTriangle(1.0)}; EXPECT_EQ(1.0, P_1d_triangle->omega()); EXPECT_EQ(BornAgain::FTDistribution1DTriangleType, P_1d_triangle->getName()); - EXPECT_NEAR(0.996671, P_1d_triangle->evaluate(0.2),0.000001); + EXPECT_NEAR(0.996671, P_1d_triangle->evaluate(0.2), 0.000001); P_1d_triangle->setOmega(3.0); EXPECT_EQ(3.0, P_1d_triangle->omega()); @@ -91,20 +94,20 @@ TEST_F(FTDistributionsTest, FTDistribution1DTriangleConstructor) TEST_F(FTDistributionsTest, FTDistribution1DTriangleClone) { - std::unique_ptr<IFTDistribution1D> P_1d_triangle { new FTDistribution1DTriangle(5.0) }; - std::unique_ptr<IFTDistribution1D> P_clone { P_1d_triangle->clone() }; + std::unique_ptr<IFTDistribution1D> P_1d_triangle{new FTDistribution1DTriangle(5.0)}; + std::unique_ptr<IFTDistribution1D> P_clone{P_1d_triangle->clone()}; EXPECT_EQ(5.0, P_clone->omega()); EXPECT_EQ(BornAgain::FTDistribution1DTriangleType, P_clone->getName()); - EXPECT_NEAR(0.919395, P_clone->evaluate(0.2),0.000001); + EXPECT_NEAR(0.919395, P_clone->evaluate(0.2), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution1DCosineConstructor) { - std::unique_ptr<IFTDistribution1D> P_1d_cosine { new FTDistribution1DCosine(1.0) }; + std::unique_ptr<IFTDistribution1D> P_1d_cosine{new FTDistribution1DCosine(1.0)}; EXPECT_EQ(1.0, P_1d_cosine->omega()); EXPECT_EQ(BornAgain::FTDistribution1DCosineType, P_1d_cosine->getName()); - EXPECT_NEAR(0.997389, P_1d_cosine->evaluate(0.2),0.000001); + EXPECT_NEAR(0.997389, P_1d_cosine->evaluate(0.2), 0.000001); P_1d_cosine->setOmega(3.0); EXPECT_EQ(3.0, P_1d_cosine->omega()); @@ -112,20 +115,20 @@ TEST_F(FTDistributionsTest, FTDistribution1DCosineConstructor) TEST_F(FTDistributionsTest, FTDistribution1DCosineClone) { - std::unique_ptr<IFTDistribution1D> P_1d_cosine { new FTDistribution1DCosine(5.0) }; - std::unique_ptr<IFTDistribution1D> P_clone { P_1d_cosine->clone() }; + std::unique_ptr<IFTDistribution1D> P_1d_cosine{new FTDistribution1DCosine(5.0)}; + std::unique_ptr<IFTDistribution1D> P_clone{P_1d_cosine->clone()}; EXPECT_EQ(5.0, P_clone->omega()); EXPECT_EQ(BornAgain::FTDistribution1DCosineType, P_clone->getName()); - EXPECT_NEAR(0.936342, P_clone->evaluate(0.2),0.000001); + EXPECT_NEAR(0.936342, P_clone->evaluate(0.2), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution1DVoigtConstructor) { - std::unique_ptr<IFTDistribution1D> P_1d_voigt { new FTDistribution1DVoigt(1.0,1.7) }; + std::unique_ptr<IFTDistribution1D> P_1d_voigt{new FTDistribution1DVoigt(1.0, 1.7)}; EXPECT_EQ(1.0, P_1d_voigt->omega()); EXPECT_EQ(BornAgain::FTDistribution1DVoigtType, P_1d_voigt->getName()); - EXPECT_NEAR(0.993261, P_1d_voigt->evaluate(0.2),0.000001); + EXPECT_NEAR(0.993261, P_1d_voigt->evaluate(0.2), 0.000001); P_1d_voigt->setOmega(3.0); EXPECT_EQ(3.0, P_1d_voigt->omega()); @@ -133,27 +136,27 @@ TEST_F(FTDistributionsTest, FTDistribution1DVoigtConstructor) TEST_F(FTDistributionsTest, FTDistribution1DVoigtClone) { - std::unique_ptr<IFTDistribution1D> P_1d_voigt { new FTDistribution1DVoigt(5.0,-5.6) }; - std::unique_ptr<IFTDistribution1D> P_clone { P_1d_voigt->clone() }; + std::unique_ptr<IFTDistribution1D> P_1d_voigt{new FTDistribution1DVoigt(5.0, -5.6)}; + std::unique_ptr<IFTDistribution1D> P_clone{P_1d_voigt->clone()}; EXPECT_EQ(5.0, P_clone->omega()); EXPECT_EQ(BornAgain::FTDistribution1DVoigtType, P_clone->getName()); - EXPECT_NEAR(-0.096572, P_clone->evaluate(0.2),0.000001); + EXPECT_NEAR(-0.096572, P_clone->evaluate(0.2), 0.000001); } // test 2D TEST_F(FTDistributionsTest, FTDistribution2DCauchyConstructor) { - std::unique_ptr<IFTDistribution2D> P_2d_cauchy { new FTDistribution2DCauchy(1.0,2.0) }; + std::unique_ptr<IFTDistribution2D> P_2d_cauchy{new FTDistribution2DCauchy(1.0, 2.0)}; EXPECT_EQ(1.0, P_2d_cauchy->omegaX()); EXPECT_EQ(2.0, P_2d_cauchy->omegaY()); EXPECT_EQ(2.0, P_2d_cauchy->parameter(BornAgain::OmegaY)->value()); EXPECT_EQ(0, P_2d_cauchy->parameter(BornAgain::Gamma)->value()); - EXPECT_EQ(M_PI/2.0, P_2d_cauchy->delta()); + EXPECT_EQ(M_PI / 2.0, P_2d_cauchy->delta()); EXPECT_EQ(0.0, P_2d_cauchy->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DCauchyType, P_2d_cauchy->getName()); - EXPECT_NEAR(0.343206, P_2d_cauchy->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(0.343206, P_2d_cauchy->evaluate(0.2, 0.5), 0.000001); P_2d_cauchy->setGamma(3.0); EXPECT_EQ(3.0, P_2d_cauchy->gamma()); @@ -167,26 +170,26 @@ TEST_F(FTDistributionsTest, FTDistribution2DCauchyConstructor) TEST_F(FTDistributionsTest, FTDistribution2DCauchyClone) { - std::unique_ptr<IFTDistribution2D> P_2d_cauchy { new FTDistribution2DCauchy(5.0,2.3) }; - std::unique_ptr<IFTDistribution2D> P_clone { P_2d_cauchy->clone() }; + std::unique_ptr<IFTDistribution2D> P_2d_cauchy{new FTDistribution2DCauchy(5.0, 2.3)}; + std::unique_ptr<IFTDistribution2D> P_clone{P_2d_cauchy->clone()}; EXPECT_EQ(5.0, P_clone->omegaX()); EXPECT_EQ(2.3, P_clone->omegaY()); - EXPECT_EQ(M_PI/2.0, P_clone->delta()); + EXPECT_EQ(M_PI / 2.0, P_clone->delta()); EXPECT_EQ(0.0, P_clone->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DCauchyType, P_clone->getName()); - EXPECT_NEAR(0.165121078, P_clone->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(0.165121078, P_clone->evaluate(0.2, 0.5), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution2DGaussConstructor) { - std::unique_ptr<IFTDistribution2D> P_2d_gauss { new FTDistribution2DGauss(1.0,2.0) }; + std::unique_ptr<IFTDistribution2D> P_2d_gauss{new FTDistribution2DGauss(1.0, 2.0)}; EXPECT_EQ(1.0, P_2d_gauss->omegaX()); EXPECT_EQ(2.0, P_2d_gauss->omegaY()); - EXPECT_EQ(M_PI/2.0, P_2d_gauss->delta()); + EXPECT_EQ(M_PI / 2.0, P_2d_gauss->delta()); EXPECT_EQ(0.0, P_2d_gauss->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DGaussType, P_2d_gauss->getName()); - EXPECT_NEAR(0.5945205, P_2d_gauss->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(0.5945205, P_2d_gauss->evaluate(0.2, 0.5), 0.000001); P_2d_gauss->setGamma(3.0); EXPECT_EQ(3.0, P_2d_gauss->gamma()); @@ -194,26 +197,26 @@ TEST_F(FTDistributionsTest, FTDistribution2DGaussConstructor) TEST_F(FTDistributionsTest, FTDistribution2DGaussClone) { - std::unique_ptr<IFTDistribution2D> P_2d_gauss { new FTDistribution2DGauss(5.0,2.3) }; - std::unique_ptr<IFTDistribution2D> P_clone { P_2d_gauss->clone() }; + std::unique_ptr<IFTDistribution2D> P_2d_gauss{new FTDistribution2DGauss(5.0, 2.3)}; + std::unique_ptr<IFTDistribution2D> P_clone{P_2d_gauss->clone()}; EXPECT_EQ(5.0, P_clone->omegaX()); EXPECT_EQ(2.3, P_clone->omegaY()); - EXPECT_EQ(M_PI/2.0, P_clone->delta()); + EXPECT_EQ(M_PI / 2.0, P_clone->delta()); EXPECT_EQ(0.0, P_clone->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DGaussType, P_clone->getName()); - EXPECT_NEAR(0.3130945, P_clone->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(0.3130945, P_clone->evaluate(0.2, 0.5), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution2DGateConstructor) { - std::unique_ptr<IFTDistribution2D> P_2d_gate { new FTDistribution2DGate(1.0,2.0) }; + std::unique_ptr<IFTDistribution2D> P_2d_gate{new FTDistribution2DGate(1.0, 2.0)}; EXPECT_EQ(1.0, P_2d_gate->omegaX()); EXPECT_EQ(2.0, P_2d_gate->omegaY()); - EXPECT_EQ(M_PI/2.0, P_2d_gate->delta()); + EXPECT_EQ(M_PI / 2.0, P_2d_gate->delta()); EXPECT_EQ(0.0, P_2d_gate->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DGateType, P_2d_gate->getName()); - EXPECT_NEAR(0.875513, P_2d_gate->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(0.875513, P_2d_gate->evaluate(0.2, 0.5), 0.000001); P_2d_gate->setGamma(3.0); EXPECT_EQ(3.0, P_2d_gate->gamma()); @@ -221,26 +224,26 @@ TEST_F(FTDistributionsTest, FTDistribution2DGateConstructor) TEST_F(FTDistributionsTest, FTDistribution2DGateClone) { - std::unique_ptr<IFTDistribution2D> P_2d_gate { new FTDistribution2DGate(5.0,2.3) }; - std::unique_ptr<IFTDistribution2D> P_clone { P_2d_gate->clone() }; + std::unique_ptr<IFTDistribution2D> P_2d_gate{new FTDistribution2DGate(5.0, 2.3)}; + std::unique_ptr<IFTDistribution2D> P_clone{P_2d_gate->clone()}; EXPECT_EQ(5.0, P_clone->omegaX()); EXPECT_EQ(2.3, P_clone->omegaY()); - EXPECT_EQ(M_PI/2.0, P_clone->delta()); + EXPECT_EQ(M_PI / 2.0, P_clone->delta()); EXPECT_EQ(0.0, P_clone->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DGateType, P_clone->getName()); - EXPECT_NEAR(0.736461, P_clone->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(0.736461, P_clone->evaluate(0.2, 0.5), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution2DConeConstructor) { - std::unique_ptr<IFTDistribution2D> P_2d_cone { new FTDistribution2DCone(1.0,2.0) }; + std::unique_ptr<IFTDistribution2D> P_2d_cone{new FTDistribution2DCone(1.0, 2.0)}; EXPECT_EQ(1.0, P_2d_cone->omegaX()); EXPECT_EQ(2.0, P_2d_cone->omegaY()); - EXPECT_EQ(M_PI/2.0, P_2d_cone->delta()); + EXPECT_EQ(M_PI / 2.0, P_2d_cone->delta()); EXPECT_EQ(0.0, P_2d_cone->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DConeType, P_2d_cone->getName()); - EXPECT_NEAR(0.924374, P_2d_cone->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(0.924374, P_2d_cone->evaluate(0.2, 0.5), 0.000001); P_2d_cone->setGamma(3.0); EXPECT_EQ(3.0, P_2d_cone->gamma()); @@ -248,26 +251,26 @@ TEST_F(FTDistributionsTest, FTDistribution2DConeConstructor) TEST_F(FTDistributionsTest, FTDistribution2DConeClone) { - std::unique_ptr<IFTDistribution2D> P_2d_cone { new FTDistribution2DCone(5.0,2.3) }; - std::unique_ptr<IFTDistribution2D> P_clone { P_2d_cone->clone() }; + std::unique_ptr<IFTDistribution2D> P_2d_cone{new FTDistribution2DCone(5.0, 2.3)}; + std::unique_ptr<IFTDistribution2D> P_clone{P_2d_cone->clone()}; EXPECT_EQ(5.0, P_clone->omegaX()); EXPECT_EQ(2.3, P_clone->omegaY()); - EXPECT_EQ(M_PI/2.0, P_clone->delta()); + EXPECT_EQ(M_PI / 2.0, P_clone->delta()); EXPECT_EQ(0.0, P_clone->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DConeType, P_clone->getName()); - EXPECT_NEAR(0.837410, P_clone->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(0.837410, P_clone->evaluate(0.2, 0.5), 0.000001); } TEST_F(FTDistributionsTest, FTDistribution2DVoigtConstructor) { - std::unique_ptr<IFTDistribution2D> P_2d_voigt { new FTDistribution2DVoigt(1.0,2.0,3.5) }; + std::unique_ptr<IFTDistribution2D> P_2d_voigt{new FTDistribution2DVoigt(1.0, 2.0, 3.5)}; EXPECT_EQ(1.0, P_2d_voigt->omegaX()); EXPECT_EQ(2.0, P_2d_voigt->omegaY()); - EXPECT_EQ(M_PI/2.0, P_2d_voigt->delta()); + EXPECT_EQ(M_PI / 2.0, P_2d_voigt->delta()); EXPECT_EQ(0.0, P_2d_voigt->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DVoigtType, P_2d_voigt->getName()); - EXPECT_NEAR(1.2228072, P_2d_voigt->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(1.2228072, P_2d_voigt->evaluate(0.2, 0.5), 0.000001); P_2d_voigt->setGamma(3.0); EXPECT_EQ(3.0, P_2d_voigt->gamma()); @@ -275,13 +278,13 @@ TEST_F(FTDistributionsTest, FTDistribution2DVoigtConstructor) TEST_F(FTDistributionsTest, FTDistribution2DVoigtClone) { - std::unique_ptr<IFTDistribution2D> P_2d_voigt { new FTDistribution2DVoigt(5.0,2.3, -5.6) }; - std::unique_ptr<IFTDistribution2D> P_clone { P_2d_voigt->clone() }; + std::unique_ptr<IFTDistribution2D> P_2d_voigt{new FTDistribution2DVoigt(5.0, 2.3, -5.6)}; + std::unique_ptr<IFTDistribution2D> P_clone{P_2d_voigt->clone()}; EXPECT_EQ(5.0, P_clone->omegaX()); EXPECT_EQ(2.3, P_clone->omegaY()); - EXPECT_EQ(M_PI/2.0, P_clone->delta()); + EXPECT_EQ(M_PI / 2.0, P_clone->delta()); EXPECT_EQ(0.0, P_clone->gamma()); EXPECT_EQ(BornAgain::FTDistribution2DVoigtType, P_clone->getName()); - EXPECT_NEAR(-0.6635305, P_clone->evaluate(0.2, 0.5),0.000001); + EXPECT_NEAR(-0.6635305, P_clone->evaluate(0.2, 0.5), 0.000001); } diff --git a/Tests/UnitTests/Core/Parameters/IParameterizedTest.h b/Tests/UnitTests/Core/Parameters/IParameterizedTest.h index b2e9cc3dca4..d352bab1601 100644 --- a/Tests/UnitTests/Core/Parameters/IParameterizedTest.h +++ b/Tests/UnitTests/Core/Parameters/IParameterizedTest.h @@ -1,31 +1,38 @@ #include "IParameterized.h" +#include "google_test.h" #include <stdexcept> class IParameterizedTest : public ::testing::Test { protected: - IParameterizedTest() {} - virtual ~IParameterizedTest(){} + ~IParameterizedTest(); IParameterized m_initial_object; class ParameterizedObject : public IParameterized { public: - ParameterizedObject() : m_real_par1(0), m_real_par2(0) { - setName("Parameterized"); init_parameters(); } + ParameterizedObject() : m_real_par1(0), m_real_par2(0) + { + setName("Parameterized"); + init_parameters(); + } double m_real_par1; double m_real_par2; + protected: virtual void init_parameters() { - registerParameter("par1",&m_real_par1); - registerParameter("par2",&m_real_par2); + registerParameter("par1", &m_real_par1); + registerParameter("par2", &m_real_par2); } }; ParameterizedObject m_parameterized; }; +IParameterizedTest::~IParameterizedTest() = default; + +// TODO enable tests TEST_F(IParameterizedTest, InitialState) { @@ -36,7 +43,6 @@ TEST_F(IParameterizedTest, InitialState) */ } - TEST_F(IParameterizedTest, DealingWithPool) { /* TEMPORARILY DISABLED getParameterPool() @@ -55,20 +61,20 @@ TEST_F(IParameterizedTest, DealingWithPool) TEST_F(IParameterizedTest, SetParameterValue) { -// m_parameterized.m_real_par1 = 1.0; -// m_parameterized.m_real_par2 = 2.0; -// m_parameterized.setParameterValue("par1", 3.0); -// m_parameterized.setParameterValue("par2", 4.0); -// EXPECT_EQ( double(3.0), m_parameterized.m_real_par1); -// EXPECT_EQ( double(4.0), m_parameterized.m_real_par2); -// ASSERT_THROW( m_parameterized.setParameterValue("NotExistingParameterName", 4.0), -// std::runtime_error ); -// m_parameterized.setParameterValue("*par*", 5.0); -// EXPECT_EQ( double(5.0), m_parameterized.m_real_par1); -// EXPECT_EQ( double(5.0), m_parameterized.m_real_par2); -// m_parameterized.setParameterValue("/Parameterized/par1", 7.0); -// EXPECT_EQ( double(7.0), m_parameterized.m_real_par1); -// EXPECT_EQ( double(5.0), m_parameterized.m_real_par2); + // m_parameterized.m_real_par1 = 1.0; + // m_parameterized.m_real_par2 = 2.0; + // m_parameterized.setParameterValue("par1", 3.0); + // m_parameterized.setParameterValue("par2", 4.0); + // EXPECT_EQ( double(3.0), m_parameterized.m_real_par1); + // EXPECT_EQ( double(4.0), m_parameterized.m_real_par2); + // ASSERT_THROW( m_parameterized.setParameterValue("NotExistingParameterName", 4.0), + // std::runtime_error ); + // m_parameterized.setParameterValue("*par*", 5.0); + // EXPECT_EQ( double(5.0), m_parameterized.m_real_par1); + // EXPECT_EQ( double(5.0), m_parameterized.m_real_par2); + // m_parameterized.setParameterValue("/Parameterized/par1", 7.0); + // EXPECT_EQ( double(7.0), m_parameterized.m_real_par1); + // EXPECT_EQ( double(5.0), m_parameterized.m_real_par2); /* TEMPORARILY DISABLED getParameterPool() m_parameterized.clearParameterPool(); EXPECT_EQ( 0.0, m_parameterized.getParameterPool()->size()); diff --git a/Tests/UnitTests/Core/Parameters/ParameterDistributionTest.h b/Tests/UnitTests/Core/Parameters/ParameterDistributionTest.h index 67f613235aa..793e75cc6b6 100644 --- a/Tests/UnitTests/Core/Parameters/ParameterDistributionTest.h +++ b/Tests/UnitTests/Core/Parameters/ParameterDistributionTest.h @@ -1,26 +1,27 @@ -#include "ParameterDistribution.h" +#include "google_test.h" #include "Distributions.h" #include "Exceptions.h" -#include "ParameterSample.h" #include "IParameterized.h" +#include "ParameterDistribution.h" +#include "ParameterSample.h" #include "ParameterUtils.h" #include <cmath> class ParameterDistributionTest : public ::testing::Test { - protected: - ParameterDistributionTest() {} + ~ParameterDistributionTest(); }; +ParameterDistributionTest::~ParameterDistributionTest() = default; + TEST_F(ParameterDistributionTest, ParameterDistributionConstructor) { std::string name = "MainParameterName"; DistributionGate distribution(1.0, 2.0); EXPECT_THROW(ParameterDistribution(name, distribution, 1, -1.0), Exceptions::RuntimeErrorException); - EXPECT_THROW(ParameterDistribution(name, distribution, 0), - Exceptions::RuntimeErrorException); + EXPECT_THROW(ParameterDistribution(name, distribution, 0), Exceptions::RuntimeErrorException); // Sigma constructor ParameterDistribution pardistr(name, distribution, 1); @@ -66,7 +67,8 @@ TEST_F(ParameterDistributionTest, ParameterDistributionCopyConstructor) EXPECT_EQ(1.5, pcopy.getDistribution()->getMean()); EXPECT_EQ(pardistr.getDistribution()->getName(), pcopy.getDistribution()->getName()); - EXPECT_EQ(pardistr.getDistribution()->probabilityDensity(1), pcopy.getDistribution()->probabilityDensity(1)); + EXPECT_EQ(pardistr.getDistribution()->probabilityDensity(1), + pcopy.getDistribution()->probabilityDensity(1)); EXPECT_EQ(pardistr.getMainParameterName(), pcopy.getMainParameterName()); EXPECT_EQ(pardistr.getNbrSamples(), pcopy.getNbrSamples()); EXPECT_EQ(pardistr.getSigmaFactor(), pcopy.getSigmaFactor()); @@ -90,7 +92,8 @@ TEST_F(ParameterDistributionTest, ParameterDistributionAssignment) EXPECT_EQ(1.5, pcopy.getDistribution()->getMean()); EXPECT_EQ(pardistr.getDistribution()->getName(), pcopy.getDistribution()->getName()); - EXPECT_EQ(pardistr.getDistribution()->probabilityDensity(1), pcopy.getDistribution()->probabilityDensity(1)); + EXPECT_EQ(pardistr.getDistribution()->probabilityDensity(1), + pcopy.getDistribution()->probabilityDensity(1)); EXPECT_EQ(pardistr.getMainParameterName(), pcopy.getMainParameterName()); EXPECT_EQ(pardistr.getNbrSamples(), pcopy.getNbrSamples()); EXPECT_EQ(pardistr.getSigmaFactor(), pcopy.getSigmaFactor()); @@ -116,17 +119,18 @@ TEST_F(ParameterDistributionTest, GenerateSamples) ParameterDistribution pardistr(name, distribution, nbr_samples, sigma_factor); std::vector<ParameterSample> sample_values = pardistr.generateSamples(); EXPECT_EQ(sample_values.size(), size_t(3)); - EXPECT_EQ(sample_values[0].value, mean-sigma_factor*sigma); + EXPECT_EQ(sample_values[0].value, mean - sigma_factor * sigma); EXPECT_EQ(sample_values[1].value, mean); - EXPECT_EQ(sample_values[2].value, mean+sigma_factor*sigma); + EXPECT_EQ(sample_values[2].value, mean + sigma_factor * sigma); // with Limits - ParameterDistribution pardistr2(name, distribution, nbr_samples, sigma_factor, RealLimits::lowerLimited(mean)); + ParameterDistribution pardistr2(name, distribution, nbr_samples, sigma_factor, + RealLimits::lowerLimited(mean)); sample_values = pardistr2.generateSamples(); EXPECT_EQ(sample_values.size(), size_t(3)); EXPECT_EQ(sample_values[0].value, mean); - EXPECT_EQ(sample_values[1].value, mean+sigma_factor*sigma/2.0); - EXPECT_EQ(sample_values[2].value, mean+sigma_factor*sigma); + EXPECT_EQ(sample_values[1].value, mean + sigma_factor * sigma / 2.0); + EXPECT_EQ(sample_values[2].value, mean + sigma_factor * sigma); // with xmin, xmax defined double xmin(-1.0); @@ -135,7 +139,7 @@ TEST_F(ParameterDistributionTest, GenerateSamples) sample_values = pardistr3.generateSamples(); EXPECT_EQ(sample_values.size(), size_t(3)); EXPECT_EQ(sample_values[0].value, xmin); - EXPECT_EQ(sample_values[1].value, xmin + (xmax-xmin)/2.0); + EXPECT_EQ(sample_values[1].value, xmin + (xmax - xmin) / 2.0); EXPECT_EQ(sample_values[2].value, xmax); } diff --git a/Tests/UnitTests/Core/Parameters/ParameterPatternTest.h b/Tests/UnitTests/Core/Parameters/ParameterPatternTest.h index 28c14ab1c8e..1ff6594d19a 100644 --- a/Tests/UnitTests/Core/Parameters/ParameterPatternTest.h +++ b/Tests/UnitTests/Core/Parameters/ParameterPatternTest.h @@ -1,16 +1,14 @@ -#ifndef PARAMETERPATTERNTEST_H -#define PARAMETERPATTERNTEST_H - +#include "google_test.h" #include "ParameterPattern.h" #include <string> class ParameterPatternTest : public ::testing::Test { - protected: - ParameterPatternTest(){} - virtual ~ParameterPatternTest(){} +protected: + ~ParameterPatternTest(); }; +ParameterPatternTest::~ParameterPatternTest() = default; TEST_F(ParameterPatternTest, declarationTest) { @@ -21,7 +19,6 @@ TEST_F(ParameterPatternTest, declarationTest) EXPECT_EQ("/home", p2.toStdString()); } - TEST_F(ParameterPatternTest, beginsWithTest) { ParameterPattern p1("Downloads"); @@ -31,7 +28,6 @@ TEST_F(ParameterPatternTest, beginsWithTest) EXPECT_EQ("Desktop", p1.toStdString()); } - TEST_F(ParameterPatternTest, addTest) { ParameterPattern p1("Desktop"); @@ -47,7 +43,6 @@ TEST_F(ParameterPatternTest, addTest) EXPECT_EQ("user", p1.toStdString()); } - TEST_F(ParameterPatternTest, copyTest) { ParameterPattern p1("Desktop"); @@ -69,10 +64,3 @@ TEST_F(ParameterPatternTest, copyTest) ParameterPattern p4 = ParameterPattern(p2); EXPECT_EQ("/Desktop/BornAgain/Core/Tests", p4.toStdString()); } - - - - -#endif // PARAMETERPATTERNTEST_H - - diff --git a/Tests/UnitTests/Core/Parameters/ParameterPoolTest.h b/Tests/UnitTests/Core/Parameters/ParameterPoolTest.h index 4aa80118d6c..e04538ec948 100644 --- a/Tests/UnitTests/Core/Parameters/ParameterPoolTest.h +++ b/Tests/UnitTests/Core/Parameters/ParameterPoolTest.h @@ -1,14 +1,16 @@ +#include "google_test.h" +#include "Exceptions.h" #include "ParameterPool.h" #include "RealParameter.h" -#include "Exceptions.h" class ParameterPoolTest : public ::testing::Test { - protected: - ParameterPoolTest(){} - virtual ~ParameterPoolTest(){} +protected: + ~ParameterPoolTest(); }; +ParameterPoolTest::~ParameterPoolTest() = default; + TEST_F(ParameterPoolTest, initialState) { ParameterPool pool; @@ -20,8 +22,8 @@ TEST_F(ParameterPoolTest, addParameter) { double par1(1.0), par2(2.0); ParameterPool pool; - RealParameter *rp1 = new RealParameter("rp1", &par1); - RealParameter *rp2 = new RealParameter("rp2", &par2); + RealParameter* rp1 = new RealParameter("rp1", &par1); + RealParameter* rp2 = new RealParameter("rp2", &par2); EXPECT_EQ(&pool.addParameter(rp1), rp1); EXPECT_EQ(&pool.addParameter(rp2), rp2); @@ -38,7 +40,7 @@ TEST_F(ParameterPoolTest, addParameter) EXPECT_EQ(pool.parameter("rp3"), nullptr); // vector of parameter names - std::vector<std::string> names{"rp1","rp2"}; + std::vector<std::string> names{"rp1", "rp2"}; EXPECT_EQ(pool.parameterNames(), names); // cleaning the pool @@ -50,9 +52,9 @@ TEST_F(ParameterPoolTest, matchedParameters) { double par1(1.0), par2(2.0), par3(3.0); ParameterPool pool; - RealParameter *rp1 = new RealParameter("par1", &par1); - RealParameter *rp2 = new RealParameter("xxx", &par2); - RealParameter *rp3 = new RealParameter("par3", &par3); + RealParameter* rp1 = new RealParameter("par1", &par1); + RealParameter* rp2 = new RealParameter("xxx", &par2); + RealParameter* rp3 = new RealParameter("par3", &par3); pool.addParameter(rp1); pool.addParameter(rp2); @@ -99,7 +101,7 @@ TEST_F(ParameterPoolTest, setValue) TEST_F(ParameterPoolTest, clone) { double par1(1.0), par2(2.0), par3(3.0); - ParameterPool *pool = new ParameterPool; + ParameterPool* pool = new ParameterPool; pool->addParameter(new RealParameter("par1", &par1)); pool->addParameter(new RealParameter("xxx", &par2)); pool->addParameter(new RealParameter("par3", &par3)); @@ -118,7 +120,7 @@ TEST_F(ParameterPoolTest, clone) TEST_F(ParameterPoolTest, copyToExternalPool) { double par1(1.0), par2(2.0); - ParameterPool *pool = new ParameterPool; + ParameterPool* pool = new ParameterPool; pool->addParameter(new RealParameter("par1", &par1)); pool->addParameter(new RealParameter("par2", &par2)); @@ -141,7 +143,7 @@ TEST_F(ParameterPoolTest, copyToExternalPool) TEST_F(ParameterPoolTest, removeParameter) { double par1(1.0), par2(2.0); - ParameterPool pool ; + ParameterPool pool; pool.addParameter(new RealParameter("par1", &par1)); pool.addParameter(new RealParameter("par2", &par2)); EXPECT_EQ(pool.size(), 2u); @@ -151,4 +153,3 @@ TEST_F(ParameterPoolTest, removeParameter) EXPECT_EQ(pool.size(), 1u); EXPECT_TRUE(pool.parameter("par1") == nullptr); } - diff --git a/Tests/UnitTests/Core/Parameters/RealParameterTest.h b/Tests/UnitTests/Core/Parameters/RealParameterTest.h index 02b7d045af2..19a0963e170 100644 --- a/Tests/UnitTests/Core/Parameters/RealParameterTest.h +++ b/Tests/UnitTests/Core/Parameters/RealParameterTest.h @@ -1,15 +1,17 @@ +#include "google_test.h" #include "IParameterized.h" #include "RealParameter.h" -#include <stdexcept> #include <iostream> +#include <stdexcept> class RealParameterTest : public ::testing::Test { - protected: - RealParameterTest() {} - virtual ~RealParameterTest() {} +protected: + ~RealParameterTest(); }; +RealParameterTest::~RealParameterTest() = default; + TEST_F(RealParameterTest, simpleConstructor) { double value(42.0); @@ -41,8 +43,7 @@ TEST_F(RealParameterTest, extendedConstructor) { double value(42.0); bool is_changed(false); - RealParameter par("name", &value, "parent_name", - [&](){is_changed=true;}, + RealParameter par("name", &value, "parent_name", [&]() { is_changed = true; }, RealLimits::limited(1.0, 43.0), Attributes::free()); EXPECT_EQ(par.getName(), "name"); @@ -61,9 +62,9 @@ TEST_F(RealParameterTest, clone) { double value(42.0); bool is_changed(false); - std::unique_ptr<RealParameter> par(new RealParameter("name", &value, "parent_name", - [&](){is_changed=true;}, - RealLimits::limited(1.0, 43.0), Attributes::free())); + std::unique_ptr<RealParameter> par( + new RealParameter("name", &value, "parent_name", [&]() { is_changed = true; }, + RealLimits::limited(1.0, 43.0), Attributes::free())); // cloning and deleting original std::unique_ptr<RealParameter> clone(par->clone()); diff --git a/Tests/UnitTests/Core/Sample/CrystalTest.h b/Tests/UnitTests/Core/Sample/CrystalTest.h index f6a4e938cf0..5e22f442c0e 100644 --- a/Tests/UnitTests/Core/Sample/CrystalTest.h +++ b/Tests/UnitTests/Core/Sample/CrystalTest.h @@ -1,13 +1,17 @@ +#include "google_test.h" +#include "BornAgainNamespace.h" #include "Crystal.h" #include "Lattice.h" -#include "BornAgainNamespace.h" +#include "ParticleComposition.h" class CrystalTest : public ::testing::Test { protected: - CrystalTest(){} + ~CrystalTest(); }; +CrystalTest::~CrystalTest() = default; + TEST_F(CrystalTest, getChildren) { Lattice lattice = Lattice::createTrigonalLattice(1.0, 2.0); diff --git a/Tests/UnitTests/Core/Sample/FormFactorBasicTest.h b/Tests/UnitTests/Core/Sample/FormFactorBasicTest.h index 9107d63ef03..6fa85204b90 100644 --- a/Tests/UnitTests/Core/Sample/FormFactorBasicTest.h +++ b/Tests/UnitTests/Core/Sample/FormFactorBasicTest.h @@ -1,74 +1,60 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file Tests/UnitTests/Core/Sample/FormFactorBasicTest.h -//! @brief Trvial and basic unit tests for particle-shape form factors. -//! -//! @homepage http://bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2015-16 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke -// -// ************************************************************************** // - -#include "MathConstants.h" +#include "google_test.h" #include "BornAgainNamespace.h" -#include "IFormFactorBorn.h" #include "HardParticles.h" +#include "IFormFactorBorn.h" +#include "MathConstants.h" class FormFactorBasicTest : public ::testing::Test { protected: - FormFactorBasicTest() {} - void test_eps_q( const IFormFactorBorn* p, cvector_t qdir, double eps ) + ~FormFactorBasicTest(); + void test_eps_q(const IFormFactorBorn* p, cvector_t qdir, double eps) { - cvector_t q = eps*qdir; - complex_t ff = p->evaluate_for_q( q ); - //std::cout<<"q="<<q<<" -> "<<std::setprecision(16)<<" ff0="<<V<<", ff ="<<ff<<"\n"; - EXPECT_LE( real(ff), V*(1+4e-16) ); - if ( R*R*R<V/20 || R*R*R>20*V ) + cvector_t q = eps * qdir; + complex_t ff = p->evaluate_for_q(q); + // std::cout<<"q="<<q<<" -> "<<std::setprecision(16)<<" ff0="<<V<<", ff ="<<ff<<"\n"; + EXPECT_LE(real(ff), V * (1 + 4e-16)); + if (R * R * R < V / 20 || R * R * R > 20 * V) // very excentric shape, the following tests cannot be expected to pass return; - EXPECT_GT( real(ff), V*(1-std::max(3e-16,2*eps*R*eps*R)) ); - EXPECT_LT( std::abs(imag(ff)), 2*eps*V*R ); + EXPECT_GT(real(ff), V * (1 - std::max(3e-16, 2 * eps * R * eps * R))); + EXPECT_LT(std::abs(imag(ff)), 2 * eps * V * R); } - void test_small_q( const IFormFactorBorn* p, complex_t x, complex_t y, complex_t z ) + void test_small_q(const IFormFactorBorn* p, complex_t x, complex_t y, complex_t z) { cvector_t q(x, y, z); - test_eps_q( p, q, 1e-14 ); - test_eps_q( p, q, 1e-11 ); - test_eps_q( p, q, 1e-8 ); - test_eps_q( p, q, 1e-5 ); + test_eps_q(p, q, 1e-14); + test_eps_q(p, q, 1e-11); + test_eps_q(p, q, 1e-8); + test_eps_q(p, q, 1e-5); } - void test_ff( const IFormFactorBorn* p ) + void test_ff(const IFormFactorBorn* p) { - complex_t ff0 = p->evaluate_for_q( cvector_t(0.,0.,0.) ); - EXPECT_EQ( imag(ff0), 0. ); + complex_t ff0 = p->evaluate_for_q(cvector_t(0., 0., 0.)); + EXPECT_EQ(imag(ff0), 0.); V = real(ff0); - EXPECT_NEAR( p->volume(), V, 3e-16*V ); + EXPECT_NEAR(p->volume(), V, 3e-16 * V); R = p->radialExtension(); - if ( R*R*R<V/20 || R*R*R>20*V ) { - std::cerr<<"WARNING: very elongated particle, or wrong radius; some tests disabled\n"; - std::cerr<<std::setprecision(16)<<" V ="<<V<<"\n R^3="<<R*R*R<<"\n"; + if (R * R * R < V / 20 || R * R * R > 20 * V) { + std::cerr << "WARNING: very elongated particle, or wrong radius; some tests disabled\n"; + std::cerr << std::setprecision(16) << " V =" << V << "\n R^3=" << R * R * R << "\n"; } - test_small_q( p, 1, 0, 0 ); - test_small_q( p, -1, 0, 0 ); - test_small_q( p, 0, 1, 0 ); - test_small_q( p, 0,-1, 0 ); - test_small_q( p, 0, 0, 1 ); - test_small_q( p, 0, 0,-1 ); - test_small_q( p, 1, 1, 0 ); - test_small_q( p, 0, 1, 1 ); - test_small_q( p, 1, 0, 1 ); - test_small_q( p, 1,-1, 0 ); - test_small_q( p, 0, 1,-1 ); - test_small_q( p, -1, 0, 1 ); - test_small_q( p, 1, 1, 1 ); - test_small_q( p, .7,.8,.9 ); + test_small_q(p, 1, 0, 0); + test_small_q(p, -1, 0, 0); + test_small_q(p, 0, 1, 0); + test_small_q(p, 0, -1, 0); + test_small_q(p, 0, 0, 1); + test_small_q(p, 0, 0, -1); + test_small_q(p, 1, 1, 0); + test_small_q(p, 0, 1, 1); + test_small_q(p, 1, 0, 1); + test_small_q(p, 1, -1, 0); + test_small_q(p, 0, 1, -1); + test_small_q(p, -1, 0, 1); + test_small_q(p, 1, 1, 1); + test_small_q(p, .7, .8, .9); IFormFactorBorn* clone = p->clone(); EXPECT_EQ(clone->getName(), p->getName()); @@ -79,6 +65,8 @@ protected: double V, R; }; +FormFactorBasicTest::~FormFactorBasicTest() = default; + TEST_F(FormFactorBasicTest, AnisoPyramid) { double length = 12.; @@ -86,8 +74,8 @@ TEST_F(FormFactorBasicTest, AnisoPyramid) double width = 14.; double alpha = 0.8; double tga = std::tan(alpha); - double volume = height* - (length*width - (length + width)*height/tga + 4.0/3.0*height*height/(tga*tga)); + double volume = height * (length * width - (length + width) * height / tga + + 4.0 / 3.0 * height * height / (tga * tga)); FormFactorAnisoPyramid anisopyramid(length, width, height, alpha); @@ -98,7 +86,7 @@ TEST_F(FormFactorBasicTest, AnisoPyramid) EXPECT_EQ(5., anisopyramid.getHeight()); EXPECT_EQ(0.8, anisopyramid.getAlpha()); - test_ff( &anisopyramid ); + test_ff(&anisopyramid); } TEST_F(FormFactorBasicTest, HemiEllipsoid) @@ -107,7 +95,7 @@ TEST_F(FormFactorBasicTest, HemiEllipsoid) double radius_b = 7.; double height = 5.; - double volume = M_TWOPI*radius_a*radius_b*height/3.; + double volume = M_TWOPI * radius_a * radius_b * height / 3.; FormFactorHemiEllipsoid hemiellipsoid(radius_a, radius_b, height); @@ -117,7 +105,7 @@ TEST_F(FormFactorBasicTest, HemiEllipsoid) EXPECT_EQ(5., hemiellipsoid.getHeight()); EXPECT_DOUBLE_EQ(volume, hemiellipsoid.volume()); - test_ff( &hemiellipsoid ); + test_ff(&hemiellipsoid); } TEST_F(FormFactorBasicTest, Box) @@ -125,7 +113,7 @@ TEST_F(FormFactorBasicTest, Box) double length = 6.; double height = 5.; double width = 7.; - double volume = length*height*width; + double volume = length * height * width; FormFactorBox box(length, width, height); @@ -135,7 +123,7 @@ TEST_F(FormFactorBasicTest, Box) EXPECT_EQ(3., box.radialExtension()); EXPECT_DOUBLE_EQ(volume, box.volume()); - test_ff( &box ); + test_ff(&box); } TEST_F(FormFactorBasicTest, Cone) @@ -144,9 +132,9 @@ TEST_F(FormFactorBasicTest, Cone) double height = 5.; double alpha = 0.8; double tga = std::tan(alpha); - double HdivRtga = height/tga/radius; - double volume = M_PI/3.*tga*radius*radius*radius* - (1. - (1.- HdivRtga)*(1.- HdivRtga)*(1.- HdivRtga)); + double HdivRtga = height / tga / radius; + double volume = M_PI / 3. * tga * radius * radius * radius + * (1. - (1. - HdivRtga) * (1. - HdivRtga) * (1. - HdivRtga)); FormFactorCone cone(radius, height, alpha); @@ -156,7 +144,7 @@ TEST_F(FormFactorBasicTest, Cone) EXPECT_EQ(0.8, cone.getAlpha()); EXPECT_DOUBLE_EQ(volume, cone.volume()); - test_ff( &cone ); + test_ff(&cone); } TEST_F(FormFactorBasicTest, Cone6) @@ -165,9 +153,9 @@ TEST_F(FormFactorBasicTest, Cone6) double height = 5.; double alpha = 0.8; double tga = std::tan(alpha); - double HdivRtga = 2.*height/tga/base_edge/std::sqrt(3.); - double volume = 3./4.*tga*base_edge*base_edge*base_edge* - (1. - (1.- HdivRtga)*(1.- HdivRtga)*(1.- HdivRtga)); + double HdivRtga = 2. * height / tga / base_edge / std::sqrt(3.); + double volume = 3. / 4. * tga * base_edge * base_edge * base_edge + * (1. - (1. - HdivRtga) * (1. - HdivRtga) * (1. - HdivRtga)); FormFactorCone6 cone6(base_edge, height, alpha); @@ -177,7 +165,7 @@ TEST_F(FormFactorBasicTest, Cone6) EXPECT_EQ(0.8, cone6.getAlpha()); EXPECT_DOUBLE_EQ(volume, cone6.volume()); - test_ff( &cone6 ); + test_ff(&cone6); } TEST_F(FormFactorBasicTest, Cuboctahedron) @@ -188,11 +176,11 @@ TEST_F(FormFactorBasicTest, Cuboctahedron) double alpha = 0.8; double tga = std::tan(alpha); - double H2divLtga = height*2./length/tga; - double ratioH2divLtga = height_ratio*height*2./length/tga; - double volume = 1./6.*tga*length*length*length* - ( 2. - (1. - H2divLtga)*(1. - H2divLtga)*(1. - H2divLtga) - - (1. - ratioH2divLtga)*(1. - ratioH2divLtga)*(1. - ratioH2divLtga)); + double H2divLtga = height * 2. / length / tga; + double ratioH2divLtga = height_ratio * height * 2. / length / tga; + double volume = 1. / 6. * tga * length * length * length + * (2. - (1. - H2divLtga) * (1. - H2divLtga) * (1. - H2divLtga) + - (1. - ratioH2divLtga) * (1. - ratioH2divLtga) * (1. - ratioH2divLtga)); FormFactorCuboctahedron cuboctahedron(length, height, height_ratio, alpha); @@ -203,36 +191,36 @@ TEST_F(FormFactorBasicTest, Cuboctahedron) EXPECT_EQ(0.8, cuboctahedron.getAlpha()); EXPECT_DOUBLE_EQ(volume, cuboctahedron.volume()); - test_ff( &cuboctahedron ); + test_ff(&cuboctahedron); } TEST_F(FormFactorBasicTest, Cylinder) { double radius = 3.; double height = 5.; - double volume = M_PI*radius*radius*height; + double volume = M_PI * radius * radius * height; - FormFactorCylinder cylinder(radius,height); + FormFactorCylinder cylinder(radius, height); EXPECT_EQ(BornAgain::FFCylinderType, cylinder.getName()); EXPECT_EQ(5., cylinder.getHeight()); EXPECT_EQ(3., cylinder.getRadius()); EXPECT_DOUBLE_EQ(volume, cylinder.volume()); - test_ff( &cylinder ); + test_ff(&cylinder); } TEST_F(FormFactorBasicTest, Dodecahedron) { double edge = 3.; - double volume = (15+7*sqrt(5))/4*pow(edge,3); + double volume = (15 + 7 * sqrt(5)) / 4 * pow(edge, 3); FormFactorDodecahedron dodecahedron(edge); EXPECT_EQ(BornAgain::FFDodecahedronType, dodecahedron.getName()); EXPECT_EQ(edge, dodecahedron.getEdge()); EXPECT_DOUBLE_EQ(volume, dodecahedron.volume()); - test_ff( &dodecahedron ); + test_ff(&dodecahedron); } TEST_F(FormFactorBasicTest, EllipsoidalCylinder) @@ -240,7 +228,7 @@ TEST_F(FormFactorBasicTest, EllipsoidalCylinder) double radius_a = 3.; double radius_b = 5.; double height = 4; - double volume = M_PI*radius_a*radius_b*height; + double volume = M_PI * radius_a * radius_b * height; FormFactorEllipsoidalCylinder ellipscyl(radius_a, radius_b, height); @@ -250,42 +238,42 @@ TEST_F(FormFactorBasicTest, EllipsoidalCylinder) EXPECT_EQ(5., ellipscyl.getRadiusY()); EXPECT_DOUBLE_EQ(volume, ellipscyl.volume()); - test_ff( &ellipscyl ); + test_ff(&ellipscyl); } TEST_F(FormFactorBasicTest, FullSphere) { double radius = 5.; - double volume = 4./3.*M_PI*radius*radius*radius; + double volume = 4. / 3. * M_PI * radius * radius * radius; FormFactorFullSphere fullsphere(radius); EXPECT_EQ(BornAgain::FFFullSphereType, fullsphere.getName()); EXPECT_EQ(5., fullsphere.getRadius()); EXPECT_DOUBLE_EQ(volume, fullsphere.volume()); - test_ff( &fullsphere ); + test_ff(&fullsphere); } TEST_F(FormFactorBasicTest, FullSpheroid) { double radius = 3.; double height = 5.; - double volume = 2./3.*M_PI*radius*radius*height; + double volume = 2. / 3. * M_PI * radius * radius * height; - FormFactorFullSpheroid fullspheroid(radius,height); + FormFactorFullSpheroid fullspheroid(radius, height); EXPECT_EQ(BornAgain::FFFullSpheroidType, fullspheroid.getName()); EXPECT_EQ(3., fullspheroid.getRadius()); EXPECT_EQ(5., fullspheroid.getHeight()); EXPECT_DOUBLE_EQ(volume, fullspheroid.volume()); - test_ff( &fullspheroid ); + test_ff(&fullspheroid); } TEST_F(FormFactorBasicTest, Icosahedron) { double edge = 7.; - double volume = 5*(3+sqrt(5))/12*pow(edge,3); + double volume = 5 * (3 + sqrt(5)) / 12 * pow(edge, 3); FormFactorIcosahedron icosahedron(edge); @@ -293,14 +281,14 @@ TEST_F(FormFactorBasicTest, Icosahedron) EXPECT_EQ(edge, icosahedron.getEdge()); EXPECT_DOUBLE_EQ(volume, icosahedron.volume()); - test_ff( &icosahedron ); + test_ff(&icosahedron); } TEST_F(FormFactorBasicTest, Prism3) { double height = 4.; double base_edge = 6.; - double volume = sqrt(3.)/4.*height*base_edge*base_edge; + double volume = sqrt(3.) / 4. * height * base_edge * base_edge; FormFactorPrism3 prism3(base_edge, height); @@ -309,14 +297,14 @@ TEST_F(FormFactorBasicTest, Prism3) EXPECT_EQ(6., prism3.getBaseEdge()); EXPECT_DOUBLE_EQ(volume, prism3.volume()); - test_ff( &prism3 ); + test_ff(&prism3); } TEST_F(FormFactorBasicTest, Prism6) { double height = 4.; double base_edge = 3.; - double volume = 3.*sqrt(3.)/2.*height*base_edge*base_edge; + double volume = 3. * sqrt(3.) / 2. * height * base_edge * base_edge; FormFactorPrism6 prism6(base_edge, height); @@ -325,7 +313,7 @@ TEST_F(FormFactorBasicTest, Prism6) EXPECT_EQ(3., prism6.getBaseEdge()); EXPECT_DOUBLE_EQ(volume, prism6.volume()); - test_ff( &prism6 ); + test_ff(&prism6); } TEST_F(FormFactorBasicTest, Pyramid) @@ -334,9 +322,9 @@ TEST_F(FormFactorBasicTest, Pyramid) double length = 10.; double alpha = 0.8; double tga = std::tan(alpha); - double H2divLtga = height*2./length/tga; - double volume = 1./6.*tga*length* length*length* - ( 1. - (1. - H2divLtga)*(1. - H2divLtga)*(1. - H2divLtga)); + double H2divLtga = height * 2. / length / tga; + double volume = 1. / 6. * tga * length * length * length + * (1. - (1. - H2divLtga) * (1. - H2divLtga) * (1. - H2divLtga)); FormFactorPyramid pyramid(length, height, alpha); @@ -346,16 +334,16 @@ TEST_F(FormFactorBasicTest, Pyramid) EXPECT_EQ(0.8, pyramid.getAlpha()); EXPECT_DOUBLE_EQ(volume, pyramid.volume()); - test_ff( &pyramid ); + test_ff(&pyramid); } TEST_F(FormFactorBasicTest, TruncatedSphere) { double radius = 5.; double height = 3.; - double HdivR = height/radius; - double volume = M_PI/3.*radius*radius*radius* - (3.*HdivR -1. - (HdivR - 1.)*(HdivR - 1.)*(HdivR - 1.)); + double HdivR = height / radius; + double volume = M_PI / 3. * radius * radius * radius + * (3. * HdivR - 1. - (HdivR - 1.) * (HdivR - 1.) * (HdivR - 1.)); FormFactorTruncatedSphere trsphere(radius, height); @@ -363,7 +351,7 @@ TEST_F(FormFactorBasicTest, TruncatedSphere) EXPECT_EQ(3., trsphere.getHeight()); EXPECT_DOUBLE_EQ(volume, trsphere.volume()); - test_ff( &trsphere ); + test_ff(&trsphere); } TEST_F(FormFactorBasicTest, TruncatedSpheroid) @@ -371,8 +359,8 @@ TEST_F(FormFactorBasicTest, TruncatedSpheroid) double radius = 3.; double height = 5.; double flattening = 1.5; - double volume = M_PI*radius*height*height/flattening* - (1.-height/(3.*flattening*radius)); + double volume + = M_PI * radius * height * height / flattening * (1. - height / (3. * flattening * radius)); FormFactorTruncatedSpheroid trspheroid(radius, height, flattening); @@ -381,7 +369,7 @@ TEST_F(FormFactorBasicTest, TruncatedSpheroid) EXPECT_EQ(3., trspheroid.getRadius()); EXPECT_DOUBLE_EQ(volume, trspheroid.volume()); - test_ff( &trspheroid ); + test_ff(&trspheroid); } TEST_F(FormFactorBasicTest, Tetrahedron) @@ -390,9 +378,9 @@ TEST_F(FormFactorBasicTest, Tetrahedron) double height = 4.; double alpha = 0.8; double tga = std::tan(alpha); - double sqrt3H2divLtga = std::sqrt(3.)*2.*height/base_edge/tga; - double volume = tga/24.*base_edge*base_edge*base_edge*( - 1.- (1. - sqrt3H2divLtga)*(1. - sqrt3H2divLtga)*(1. - sqrt3H2divLtga)); + double sqrt3H2divLtga = std::sqrt(3.) * 2. * height / base_edge / tga; + double volume = tga / 24. * base_edge * base_edge * base_edge + * (1. - (1. - sqrt3H2divLtga) * (1. - sqrt3H2divLtga) * (1. - sqrt3H2divLtga)); FormFactorTetrahedron tetrahedron(base_edge, height, alpha); @@ -402,7 +390,7 @@ TEST_F(FormFactorBasicTest, Tetrahedron) EXPECT_EQ(0.8, tetrahedron.getAlpha()); EXPECT_DOUBLE_EQ(volume, tetrahedron.volume()); - test_ff( &tetrahedron ); + test_ff(&tetrahedron); } TEST_F(FormFactorBasicTest, Ripple1) @@ -410,7 +398,7 @@ TEST_F(FormFactorBasicTest, Ripple1) double width = 20.; double height = 4.; double length = 100.0; - double volume = 0.5*height*width*length; + double volume = 0.5 * height * width * length; FormFactorRipple1 ripple1(length, width, height); @@ -420,23 +408,23 @@ TEST_F(FormFactorBasicTest, Ripple1) EXPECT_EQ(100., ripple1.getLength()); EXPECT_DOUBLE_EQ(volume, ripple1.volume()); - test_ff( &ripple1 ); + test_ff(&ripple1); } TEST_F(FormFactorBasicTest, TruncatedCube) { double length = 15.; double t = 6.; // side length of removed trirectangular tetrahedron at each vertex - double volume = length*length*length - 4./3.*t*t*t; + double volume = length * length * length - 4. / 3. * t * t * t; FormFactorTruncatedCube trcube(length, t); - EXPECT_EQ(BornAgain::FFTruncatedCubeType,trcube.getName()); + EXPECT_EQ(BornAgain::FFTruncatedCubeType, trcube.getName()); EXPECT_EQ(length, trcube.getLength()); EXPECT_DOUBLE_EQ(t, trcube.getRemovedLength()); EXPECT_DOUBLE_EQ(trcube.volume(), volume); - test_ff( &trcube ); + test_ff(&trcube); } TEST_F(FormFactorBasicTest, Ripple2) @@ -445,7 +433,7 @@ TEST_F(FormFactorBasicTest, Ripple2) double height = 4.; double length = 100.0; double d = 0.3; // asymmetry - double volume = 0.5*height*width*length; + double volume = 0.5 * height * width * length; FormFactorRipple2 ripple2(length, width, height, d); diff --git a/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.h b/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.h index f6e74bc1f5d..469ef216968 100644 --- a/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.h +++ b/Tests/UnitTests/Core/Sample/FormFactorCoherentSumTest.h @@ -1,17 +1,19 @@ +#include "google_test.h" +#include "Exceptions.h" #include "FormFactorCoherentSum.h" #include "FormFactorDot.h" -#include "Exceptions.h" class FormFactorCoherentSumTest : public ::testing::Test { protected: - FormFactorCoherentSumTest() {} - virtual ~FormFactorCoherentSumTest() {} + ~FormFactorCoherentSumTest(); }; +FormFactorCoherentSumTest::~FormFactorCoherentSumTest() = default; + TEST_F(FormFactorCoherentSumTest, RelAbundance) { - const double epsilon=1e-12; + const double epsilon = 1e-12; auto p_ff = new FormFactorDot(); FormFactorCoherentSum ffw(1.0); FormFactorCoherentPart part(p_ff); diff --git a/Tests/UnitTests/Core/Sample/INodeTest.h b/Tests/UnitTests/Core/Sample/INodeTest.h index 9829418c458..be0db14330c 100644 --- a/Tests/UnitTests/Core/Sample/INodeTest.h +++ b/Tests/UnitTests/Core/Sample/INodeTest.h @@ -1,24 +1,26 @@ -#ifndef INODETEST_H -#define INODETEST_H - +#include "google_test.h" +#include "Exceptions.h" #include "INode.h" #include "NodeUtils.h" -#include "Exceptions.h" #include "ParameterPool.h" #include "RealParameter.h" #include <memory> -namespace { - const std::string test_class_name = "TestClass"; - const std::string another_test_class_name = "AnotherTestClass"; - const double test_par1_value(1.0); +namespace +{ +const std::string test_class_name = "TestClass"; +const std::string another_test_class_name = "AnotherTestClass"; +const double test_par1_value(1.0); } class INodeTest : public ::testing::Test { public: - class TestClass : public INode { - public: + ~INodeTest(); + + class TestClass : public INode + { + public: TestClass(const std::string& name = test_class_name, double value = test_par1_value) : m_parameter1(value) { @@ -28,27 +30,29 @@ public: virtual ~TestClass() { - for(auto child : m_nodes) + for (auto child : m_nodes) delete child; } void accept(INodeVisitor* visitor) const final { visitor->visit(this); } - void appendChild(INode *node) { m_nodes.push_back(node); registerChild(node); } + void appendChild(INode* node) + { + m_nodes.push_back(node); + registerChild(node); + } virtual std::vector<const INode*> getChildren() const { return {m_nodes.begin(), m_nodes.end()}; } - std::vector<INode *> m_nodes; + std::vector<INode*> m_nodes; double m_parameter1; }; - -protected: - INodeTest(){} - virtual ~INodeTest(){} }; +INodeTest::~INodeTest() = default; + TEST_F(INodeTest, initialState) { INodeTest::TestClass node; @@ -78,7 +82,7 @@ TEST_F(INodeTest, parentship) INodeTest::TestClass node; EXPECT_EQ(node.parent(), nullptr); - INodeTest::TestClass *child = new INodeTest::TestClass(); + INodeTest::TestClass* child = new INodeTest::TestClass(); node.appendChild(child); EXPECT_EQ(child->parent(), &node); } @@ -92,18 +96,18 @@ TEST_F(INodeTest, displayName) EXPECT_EQ(node.getName(), node.displayName()); // Adding first child and checking its displayName - INodeTest::TestClass *child0 = new INodeTest::TestClass(); + INodeTest::TestClass* child0 = new INodeTest::TestClass(); node.appendChild(child0); EXPECT_EQ(child0->displayName(), test_class_name); // Adding second child with same name and checking change in displayName - INodeTest::TestClass *child1 = new INodeTest::TestClass(); + INodeTest::TestClass* child1 = new INodeTest::TestClass(); node.appendChild(child1); - EXPECT_EQ(child0->displayName(), test_class_name+"0"); - EXPECT_EQ(child1->displayName(), test_class_name+"1"); + EXPECT_EQ(child0->displayName(), test_class_name + "0"); + EXPECT_EQ(child1->displayName(), test_class_name + "1"); // Adding second child with another name and checking - INodeTest::TestClass *child2 = new INodeTest::TestClass(another_test_class_name); + INodeTest::TestClass* child2 = new INodeTest::TestClass(another_test_class_name); node.appendChild(child2); EXPECT_EQ(child2->displayName(), another_test_class_name); } @@ -117,18 +121,18 @@ TEST_F(INodeTest, nodePath) EXPECT_EQ(NodeUtils::nodePath(root), "/root"); // adding first child - INodeTest::TestClass *child0 = new INodeTest::TestClass("child"); + INodeTest::TestClass* child0 = new INodeTest::TestClass("child"); root.appendChild(child0); EXPECT_EQ(NodeUtils::nodePath(*child0), "/root/child"); // adding second child with the same name - INodeTest::TestClass *child1 = new INodeTest::TestClass("child"); + INodeTest::TestClass* child1 = new INodeTest::TestClass("child"); root.appendChild(child1); EXPECT_EQ(NodeUtils::nodePath(*child0), "/root/child0"); EXPECT_EQ(NodeUtils::nodePath(*child1), "/root/child1"); // adding grandchild - INodeTest::TestClass *grandchild = new INodeTest::TestClass("grandchild"); + INodeTest::TestClass* grandchild = new INodeTest::TestClass("grandchild"); child0->appendChild(grandchild); EXPECT_EQ(NodeUtils::nodePath(*grandchild), "/root/child0/grandchild"); @@ -137,7 +141,6 @@ TEST_F(INodeTest, nodePath) // Check if exception is thrown when grandchild doesn't belong to child's branch EXPECT_THROW(NodeUtils::nodePath(*grandchild, child1), Exceptions::RuntimeErrorException); - } //! Checking parameter tree for INode structure. @@ -151,7 +154,7 @@ TEST_F(INodeTest, createParameterTree) EXPECT_EQ(pool->parameter("/root/par1")->value(), test_par1_value); // adding first child - INodeTest::TestClass *child0 = new INodeTest::TestClass("child", 99.0); + INodeTest::TestClass* child0 = new INodeTest::TestClass("child", 99.0); root.appendChild(child0); pool.reset(root.createParameterTree()); @@ -165,13 +168,13 @@ TEST_F(INodeTest, createParameterTree) TEST_F(INodeTest, createChildParameterTree) { INodeTest::TestClass root("root"); - INodeTest::TestClass *child = new INodeTest::TestClass("child", 1.0); + INodeTest::TestClass* child = new INodeTest::TestClass("child", 1.0); root.appendChild(child); - INodeTest::TestClass *grand = new INodeTest::TestClass("grand", 2.0); + INodeTest::TestClass* grand = new INodeTest::TestClass("grand", 2.0); child->appendChild(grand); - INodeTest::TestClass *grandgrand = new INodeTest::TestClass("grandgrand", 3.0); + INodeTest::TestClass* grandgrand = new INodeTest::TestClass("grandgrand", 3.0); grand->appendChild(grandgrand); std::unique_ptr<ParameterPool> pool(grand->createParameterTree()); @@ -179,5 +182,3 @@ TEST_F(INodeTest, createChildParameterTree) EXPECT_EQ(pool->parameter("/grand/par1")->value(), 2.0); EXPECT_EQ(pool->parameter("/grand/grandgrand/par1")->value(), 3.0); } - -#endif // INODETEST_H diff --git a/Tests/UnitTests/Core/Sample/Lattice2DTest.h b/Tests/UnitTests/Core/Sample/Lattice2DTest.h index 2a200bdfe93..ff628f77eeb 100644 --- a/Tests/UnitTests/Core/Sample/Lattice2DTest.h +++ b/Tests/UnitTests/Core/Sample/Lattice2DTest.h @@ -1,14 +1,14 @@ -#include "Lattice2D.h" +#include "google_test.h" #include "BornAgainNamespace.h" - -#include <iostream> +#include "Lattice2D.h" class Lattice2DTest : public ::testing::Test { protected: - Lattice2DTest(){} + ~Lattice2DTest(); }; +Lattice2DTest::~Lattice2DTest() = default; TEST_F(Lattice2DTest, basicLattice) { @@ -52,7 +52,7 @@ TEST_F(Lattice2DTest, squareLatticeClone) std::unique_ptr<Lattice2D> clone(lattice.clone()); EXPECT_EQ(clone->length1(), length); EXPECT_EQ(clone->length2(), length); - EXPECT_DOUBLE_EQ(clone->latticeAngle(), M_PI/2.0); + EXPECT_DOUBLE_EQ(clone->latticeAngle(), M_PI / 2.0); EXPECT_EQ(clone->rotationAngle(), xi); EXPECT_EQ(clone->getName(), BornAgain::SquareLatticeType); @@ -73,7 +73,7 @@ TEST_F(Lattice2DTest, hexagonalLatticeClone) std::unique_ptr<Lattice2D> clone(lattice.clone()); EXPECT_EQ(clone->length1(), length); EXPECT_EQ(clone->length2(), length); - EXPECT_DOUBLE_EQ(clone->latticeAngle(), 2.*M_PI/3.0); + EXPECT_DOUBLE_EQ(clone->latticeAngle(), 2. * M_PI / 3.0); EXPECT_EQ(clone->rotationAngle(), xi); EXPECT_EQ(clone->getName(), BornAgain::HexagonalLatticeType); @@ -88,7 +88,8 @@ TEST_F(Lattice2DTest, hexagonalLatticeClone) TEST_F(Lattice2DTest, onChange) { - class Parent : public INode{ + class Parent : public INode + { public: Parent() : m_changed(false) {} void accept(INodeVisitor* visitor) const final { visitor->visit(this); } diff --git a/Tests/UnitTests/Core/Sample/LatticeTest.h b/Tests/UnitTests/Core/Sample/LatticeTest.h index bd296f9613c..cc962327b72 100644 --- a/Tests/UnitTests/Core/Sample/LatticeTest.h +++ b/Tests/UnitTests/Core/Sample/LatticeTest.h @@ -1,23 +1,20 @@ -#ifndef LATTICETEST_H -#define LATTICETEST_H - -#include "Lattice.h" #include "google_test.h" +#include "Lattice.h" #include "MathConstants.h" #include "Transform3D.h" class LatticeTest : public ::testing::Test { - protected: - LatticeTest(){} - virtual ~LatticeTest(){} +protected: + ~LatticeTest(); }; +LatticeTest::~LatticeTest() = default; // tests the declaration of Lattice object, copy constructor and the getBasisVector_() functions TEST_F(LatticeTest, declarationTest) { - kvector_t a1(1,0,0), a2(0,1,0), a3(0,0,1); + kvector_t a1(1, 0, 0), a2(0, 1, 0), a3(0, 0, 1); Lattice l1(a1, a2, a3); EXPECT_EQ(a1, l1.getBasisVectorA()); @@ -42,21 +39,19 @@ TEST_F(LatticeTest, declarationTest) EXPECT_EQ(a3, l4.getBasisVectorC()); } - // tests volume of the unit cell TEST_F(LatticeTest, volumeTest) { - kvector_t a1(4,0,0), a2(0,2.1,0), a3(0,0,1); + kvector_t a1(4, 0, 0), a2(0, 2.1, 0), a3(0, 0, 1); Lattice l1(a1, a2, a3); EXPECT_EQ(8.4, l1.volume()); // 8.4 is the expected volume for the given lattice vectors } - // tests whether reciprocal lattice basis vectors have been initialized or not TEST_F(LatticeTest, reciprocalTest) { - kvector_t a1(1,0,0), a2(0,1,0), a3(0,0,1); + kvector_t a1(1, 0, 0), a2(0, 1, 0), a3(0, 0, 1); Lattice l1(a1, a2, a3); kvector_t b1, b2, b3, m_ra, m_rb, m_rc; @@ -65,9 +60,9 @@ TEST_F(LatticeTest, reciprocalTest) kvector_t a23 = a2.cross(a3); kvector_t a31 = a3.cross(a1); kvector_t a12 = a1.cross(a2); - m_ra = M_TWOPI/a1.dot(a23)*a23; - m_rb = M_TWOPI/a2.dot(a31)*a31; - m_rc = M_TWOPI/a3.dot(a12)*a12; + m_ra = M_TWOPI / a1.dot(a23) * a23; + m_rb = M_TWOPI / a2.dot(a31) * a31; + m_rc = M_TWOPI / a3.dot(a12) * a12; l1.initialize(); l1.getReciprocalLatticeBasis(b1, b2, b3); @@ -76,15 +71,14 @@ TEST_F(LatticeTest, reciprocalTest) EXPECT_EQ(m_rc, b3); } - // tests whether Lattice has been transformed correctly TEST_F(LatticeTest, transformTest) { - kvector_t a1(1,0,0), a2(0,1,0), a3(0,0,1); + kvector_t a1(1, 0, 0), a2(0, 1, 0), a3(0, 0, 1); Lattice l1(a1, a2, a3); // use rotation by 90 degrees around z axis as a transformation - Transform3D tr = Transform3D::createRotateZ(M_TWOPI/4); + Transform3D tr = Transform3D::createRotateZ(M_TWOPI / 4); Lattice ltr = l1.createTransformedLattice(tr); // use EXPECT_NEAR as transform (matrix multiplication) uses double value for rotation angle @@ -98,89 +92,84 @@ TEST_F(LatticeTest, transformTest) EXPECT_EQ(a3, ltr.getBasisVectorC()); } - // REAL = real/physical // tests the nearest REAL LATTICE point to a given REAL SPACE vector TEST_F(LatticeTest, NearestRealLatticeVectorCoordinatesTest) { - kvector_t a1(1,0,0), a2(0,1,0), a3(0,0,1); + kvector_t a1(1, 0, 0), a2(0, 1, 0), a3(0, 0, 1); Lattice l1(a1, a2, a3); // vector_in is in REAL SPACE coordinates - kvector_t vector_in(3.01,1.51,1.49); + kvector_t vector_in(3.01, 1.51, 1.49); // point_expected is in REAL LATTICE coordinates - ivector_t point_expected(3,2,1); + ivector_t point_expected(3, 2, 1); EXPECT_EQ(point_expected, l1.getNearestLatticeVectorCoordinates(vector_in)); } - // REC. = reciprocal // tests the nearest REC. LATTICE point to a given REC. SPACE vector TEST_F(LatticeTest, NearestReciprocalLatticeVectorCoordinatesTest) { - kvector_t a1(1,0,0), a2(0,1,0), a3(0,0,1); + kvector_t a1(1, 0, 0), a2(0, 1, 0), a3(0, 0, 1); Lattice l1(a1, a2, a3); // vector_in is in REC. SPACE coordinates - kvector_t vector_in(2.8*M_TWOPI,0,0); + kvector_t vector_in(2.8 * M_TWOPI, 0, 0); // point_expected is in REC. LATTICE coordinates - ivector_t point_expected(3,0,0); + ivector_t point_expected(3, 0, 0); EXPECT_EQ(point_expected, l1.getNearestReciprocalLatticeVectorCoordinates(vector_in)); } - // tests the list of REC. LATTICE vectors (in REC. SPACE coords) computed within a specified // radius of a given REC. SPACE vector TEST_F(LatticeTest, reciprocalLatticeVectorsWithinRadiusTest) { - kvector_t a1(1,0,0), a2(0,1,0), a3(0,0,1); + kvector_t a1(1, 0, 0), a2(0, 1, 0), a3(0, 0, 1); Lattice l1(a1, a2, a3); kvector_t b1, b2, b3; l1.getReciprocalLatticeBasis(b1, b2, b3); // vector_in is in REC. SPACE coordinates - kvector_t vector_in(2.5*M_TWOPI,0,0); + kvector_t vector_in(2.5 * M_TWOPI, 0, 0); // list of REC. LATTICE vectors expected within given radius std::vector<kvector_t> vectors_expected; - kvector_t expected_1 = 2*b1; - kvector_t expected_2 = 3*b1; + kvector_t expected_1 = 2 * b1; + kvector_t expected_2 = 3 * b1; vectors_expected.push_back(expected_1); vectors_expected.push_back(expected_2); EXPECT_EQ(vectors_expected, l1.reciprocalLatticeVectorsWithinRadius(vector_in, M_TWOPI)); - EXPECT_EQ(vectors_expected, l1.reciprocalLatticeVectorsWithinRadius(vector_in, M_TWOPI-0.1)); + EXPECT_EQ(vectors_expected, l1.reciprocalLatticeVectorsWithinRadius(vector_in, M_TWOPI - 0.1)); } - // tests FCC lattice creation TEST_F(LatticeTest, FCCLatticeTest) { // creates FCC lattice onto a new Lattice instance l1 Lattice l1 = Lattice::createFCCLattice(1); - kvector_t fcc1(0,0.5,0.5), fcc2(0.5,0,0.5), fcc3(0.5,0.5,0); + kvector_t fcc1(0, 0.5, 0.5), fcc2(0.5, 0, 0.5), fcc3(0.5, 0.5, 0); EXPECT_EQ(fcc1, l1.getBasisVectorA()); EXPECT_EQ(fcc2, l1.getBasisVectorB()); EXPECT_EQ(fcc3, l1.getBasisVectorC()); } - // tests trigonal lattice creation TEST_F(LatticeTest, TrigonalLatticeTest) { - Lattice l1 = Lattice::createTrigonalLattice(1,4); + Lattice l1 = Lattice::createTrigonalLattice(1, 4); kvector_t tri1(1, 0.0, 0.0); - kvector_t tri2(-1/2.0, std::sqrt(3.0)*1/2.0, 0); + kvector_t tri2(-1 / 2.0, std::sqrt(3.0) * 1 / 2.0, 0); kvector_t tri3(0.0, 0.0, 4); EXPECT_EQ(tri1, l1.getBasisVectorA()); @@ -188,12 +177,11 @@ TEST_F(LatticeTest, TrigonalLatticeTest) EXPECT_EQ(tri3, l1.getBasisVectorC()); } - // tests whether basis and reciprocal vectors are returned correctly when the basis // vectors are manually changed using the setVectorValue method TEST_F(LatticeTest, onChangeTest) { - kvector_t a1(1,0,0), a2(0,1,0), a3(0,0,1); + kvector_t a1(1, 0, 0), a2(0, 1, 0), a3(0, 0, 1); Lattice l1(a1, a2, a3); kvector_t b1, b2, b3, m_ra, m_rb, m_rc; @@ -202,18 +190,18 @@ TEST_F(LatticeTest, onChangeTest) kvector_t a23 = a2.cross(a3); kvector_t a31 = a3.cross(a1); kvector_t a12 = a1.cross(a2); - m_ra = M_TWOPI/a1.dot(a23)*a23; - m_rb = M_TWOPI/a2.dot(a31)*a31; - m_rc = M_TWOPI/a3.dot(a12)*a12; + m_ra = M_TWOPI / a1.dot(a23) * a23; + m_rb = M_TWOPI / a2.dot(a31) * a31; + m_rc = M_TWOPI / a3.dot(a12) * a12; - //l1.initialize(); + // l1.initialize(); l1.getReciprocalLatticeBasis(b1, b2, b3); EXPECT_EQ(m_ra, b1); EXPECT_EQ(m_rb, b2); EXPECT_EQ(m_rc, b3); // The new changed lattice vectors - kvector_t c1(2,0,0), c2(0,2,0), c3(0,0,2); + kvector_t c1(2, 0, 0), c2(0, 2, 0), c3(0, 0, 2); l1.setVectorValue(BornAgain::BasisVector_A, c1); l1.setVectorValue(BornAgain::BasisVector_B, c2); @@ -228,14 +216,12 @@ TEST_F(LatticeTest, onChangeTest) kvector_t c23 = c2.cross(c3); kvector_t c31 = c3.cross(c1); kvector_t c12 = c1.cross(c2); - mc_ra = M_TWOPI/c1.dot(c23)*c23; - mc_rb = M_TWOPI/c2.dot(c31)*c31; - mc_rc = M_TWOPI/c3.dot(c12)*c12; + mc_ra = M_TWOPI / c1.dot(c23) * c23; + mc_rb = M_TWOPI / c2.dot(c31) * c31; + mc_rc = M_TWOPI / c3.dot(c12) * c12; l1.getReciprocalLatticeBasis(d1, d2, d3); EXPECT_EQ(mc_ra, d1); EXPECT_EQ(mc_rb, d2); EXPECT_EQ(mc_rc, d3); } - -#endif // LATTICETEST_H diff --git a/Tests/UnitTests/Core/Sample/LayerInterfaceTest.h b/Tests/UnitTests/Core/Sample/LayerInterfaceTest.h index 76054f62f75..4872a977bd2 100644 --- a/Tests/UnitTests/Core/Sample/LayerInterfaceTest.h +++ b/Tests/UnitTests/Core/Sample/LayerInterfaceTest.h @@ -1,24 +1,26 @@ +#include "google_test.h" +#include "BornAgainNamespace.h" #include "Layer.h" #include "LayerInterface.h" #include "LayerRoughness.h" -#include "BornAgainNamespace.h" #include "MaterialFactoryFuncs.h" #include <memory> class LayerInterfaceTest : public ::testing::Test { - protected: - LayerInterfaceTest(){} - virtual ~LayerInterfaceTest(){} +protected: + ~LayerInterfaceTest(); }; +LayerInterfaceTest::~LayerInterfaceTest() = default; + TEST_F(LayerInterfaceTest, createSmoothInterface) { std::unique_ptr<Layer> layer0(new Layer(HomogeneousMaterial("air", 0.0, 0.0))); std::unique_ptr<Layer> layer1(new Layer(HomogeneousMaterial("air", 0.0, 0.0))); std::unique_ptr<LayerInterface> interface( - LayerInterface::createSmoothInterface(layer0.get(), layer1.get())); + LayerInterface::createSmoothInterface(layer0.get(), layer1.get())); EXPECT_EQ(interface->topLayer(), layer0.get()); EXPECT_EQ(interface->bottomLayer(), layer1.get()); @@ -37,7 +39,7 @@ TEST_F(LayerInterfaceTest, createRoughInterface) EXPECT_EQ(interface->topLayer(), layer0.get()); EXPECT_EQ(interface->bottomLayer(), layer1.get()); EXPECT_EQ(interface->getRoughness()->getSigma(), 1.0); - std::vector<const INode*> children =interface->getChildren(); + std::vector<const INode*> children = interface->getChildren(); EXPECT_EQ(children.size(), 1u); EXPECT_EQ(children.at(0)->getName(), BornAgain::LayerBasicRoughnessType); } diff --git a/Tests/UnitTests/Core/Sample/LayerRoughnessTest.h b/Tests/UnitTests/Core/Sample/LayerRoughnessTest.h index a061eecb5cb..5334666c8f6 100644 --- a/Tests/UnitTests/Core/Sample/LayerRoughnessTest.h +++ b/Tests/UnitTests/Core/Sample/LayerRoughnessTest.h @@ -1,23 +1,26 @@ -#include "LayerRoughness.h" +#include "google_test.h" #include "BornAgainNamespace.h" +#include "LayerRoughness.h" #include "ParameterPattern.h" class LayerRoughnessTest : public ::testing::Test { - protected: - LayerRoughnessTest(){} +protected: + ~LayerRoughnessTest(); }; -TEST_F(LayerRoughnessTest , LayerRoughnessInitial) +LayerRoughnessTest::~LayerRoughnessTest() = default; + +TEST_F(LayerRoughnessTest, LayerRoughnessInitial) { - //test with default parameter + // test with default parameter LayerRoughness roughness; EXPECT_EQ(0.0, roughness.getSigma()); EXPECT_EQ(0.0, roughness.getHurstParameter()); EXPECT_EQ(0.0, roughness.getLatteralCorrLength()); EXPECT_EQ(BornAgain::LayerBasicRoughnessType, roughness.getName()); - //set new parameter + // set new parameter roughness.setSigma(1.1); EXPECT_EQ(1.1, roughness.getSigma()); @@ -27,7 +30,7 @@ TEST_F(LayerRoughnessTest , LayerRoughnessInitial) roughness.setLatteralCorrLength(1.3); EXPECT_EQ(1.3, roughness.getLatteralCorrLength()); - //test with given parameter + // test with given parameter LayerRoughness roughness2(2.1, 2.2, 2.3); EXPECT_EQ(2.1, roughness2.getSigma()); EXPECT_EQ(2.2, roughness2.getHurstParameter()); @@ -35,12 +38,12 @@ TEST_F(LayerRoughnessTest , LayerRoughnessInitial) EXPECT_EQ(BornAgain::LayerBasicRoughnessType, roughness.getName()); } -//test clone LayerRoughness -TEST_F(LayerRoughnessTest , LayerRoughnessClone) +// test clone LayerRoughness +TEST_F(LayerRoughnessTest, LayerRoughnessClone) { LayerRoughness original(3.1, 3.2, 3.3); - LayerRoughness *clone = original.clone(); + LayerRoughness* clone = original.clone(); EXPECT_EQ(clone->getSigma(), original.getSigma()); EXPECT_EQ(clone->getHurstParameter(), original.getHurstParameter()); EXPECT_EQ(clone->getLatteralCorrLength(), original.getLatteralCorrLength()); @@ -48,8 +51,8 @@ TEST_F(LayerRoughnessTest , LayerRoughnessClone) delete clone; } -//test parameter pool -TEST_F(LayerRoughnessTest , LayerRoughnessPool) +// test parameter pool +TEST_F(LayerRoughnessTest, LayerRoughnessPool) { LayerRoughness roughnessPool; EXPECT_EQ(0.0, roughnessPool.getSigma()); diff --git a/Tests/UnitTests/Core/Sample/LayerTest.h b/Tests/UnitTests/Core/Sample/LayerTest.h index 7e6358f874e..5e937d6c955 100644 --- a/Tests/UnitTests/Core/Sample/LayerTest.h +++ b/Tests/UnitTests/Core/Sample/LayerTest.h @@ -1,3 +1,4 @@ +#include "google_test.h" #include "Layer.h" #include "MaterialFactoryFuncs.h" #include "ParticleLayout.h" @@ -5,15 +6,16 @@ class LayerTest : public ::testing::Test { - protected: - LayerTest(){} - virtual ~LayerTest(){} +protected: + virtual ~LayerTest(); }; +LayerTest::~LayerTest() = default; + TEST_F(LayerTest, LayerGetAndSet) { - Material air = HomogeneousMaterial("air",0,0); - Layer layer(air, 10*Units::nanometer); + Material air = HomogeneousMaterial("air", 0, 0); + Layer layer(air, 10 * Units::nanometer); EXPECT_EQ(air, *layer.material()); EXPECT_EQ(0u, layer.layouts().size()); EXPECT_EQ(10, layer.thickness()); @@ -33,13 +35,12 @@ TEST_F(LayerTest, LayerGetAndSet) EXPECT_EQ(BornAgain::LayerType, clone->getName()); } - TEST_F(LayerTest, LayerAndDecoration) { - Material air = HomogeneousMaterial("air",0,0); + Material air = HomogeneousMaterial("air", 0, 0); std::unique_ptr<ParticleLayout> layout1(new ParticleLayout()); - Layer layer(air, 10*Units::nanometer); + Layer layer(air, 10 * Units::nanometer); layer.addLayout(*layout1); EXPECT_EQ(layer.numberOfLayouts(), 1u); diff --git a/Tests/UnitTests/Core/Sample/MesoCrystalTest.h b/Tests/UnitTests/Core/Sample/MesoCrystalTest.h index 256cab21b18..8d678f0cf97 100644 --- a/Tests/UnitTests/Core/Sample/MesoCrystalTest.h +++ b/Tests/UnitTests/Core/Sample/MesoCrystalTest.h @@ -1,15 +1,19 @@ +#include "google_test.h" +#include "BornAgainNamespace.h" #include "Crystal.h" +#include "FormFactorFullSphere.h" #include "Lattice.h" #include "MesoCrystal.h" -#include "FormFactorFullSphere.h" -#include "BornAgainNamespace.h" +#include "ParticleComposition.h" class MesoCrystalTest : public ::testing::Test { protected: - MesoCrystalTest(){} + ~MesoCrystalTest(); }; +MesoCrystalTest::~MesoCrystalTest() = default; + TEST_F(MesoCrystalTest, getChildren) { Lattice lattice = Lattice::createTrigonalLattice(1.0, 2.0); diff --git a/Tests/UnitTests/Core/Sample/MultiLayerTest.h b/Tests/UnitTests/Core/Sample/MultiLayerTest.h index b399b3110f9..024761461d3 100644 --- a/Tests/UnitTests/Core/Sample/MultiLayerTest.h +++ b/Tests/UnitTests/Core/Sample/MultiLayerTest.h @@ -1,5 +1,4 @@ -//! Trivial construct/clone/get tests for class MultiLayer. No physics tested here. - +#include "google_test.h" #include "BornAgainNamespace.h" #include "Layer.h" #include "Layer.h" @@ -9,41 +8,49 @@ #include "MathConstants.h" #include "MultiLayer.h" #include "ParticleLayout.h" +#include "Units.h" class MultiLayerTest : public ::testing::Test { protected: MultiLayerTest() // The following delta, beta are all unphysical. Values don't matter here. - : air(HomogeneousMaterial("air", 1e-6, 9e-4)) - , iron(HomogeneousMaterial("iron", 2e-5, 8e-5)) - , chromium(HomogeneousMaterial("chromium", 3e-7, 7e-6)) - , stone(HomogeneousMaterial("stone", 4e-4, 8e-7)) - , topLayer(air, 0*Units::nanometer) - , layer1(iron, 20*Units::nanometer) - , layer2(chromium, 40*Units::nanometer) - , substrate(stone, 0*Units::nanometer) {} - void set_four() { + : air(HomogeneousMaterial("air", 1e-6, 9e-4)), + iron(HomogeneousMaterial("iron", 2e-5, 8e-5)), + chromium(HomogeneousMaterial("chromium", 3e-7, 7e-6)), + stone(HomogeneousMaterial("stone", 4e-4, 8e-7)), + topLayer(air, 0 * Units::nanometer), + layer1(iron, 20 * Units::nanometer), + layer2(chromium, 40 * Units::nanometer), + substrate(stone, 0 * Units::nanometer) + { + } + void set_four() + { mLayer.addLayer(topLayer); mLayer.addLayer(layer1); mLayer.addLayer(layer2); mLayer.addLayer(substrate); } + ~MultiLayerTest(); + MultiLayer mLayer; const Material air, iron, chromium, stone; Layer topLayer, layer1, layer2, substrate; }; +MultiLayerTest::~MultiLayerTest() = default; + TEST_F(MultiLayerTest, BasicProperty) { - //check default properties + // check default properties EXPECT_EQ(BornAgain::MultiLayerType, mLayer.getName()); EXPECT_EQ(0.0, mLayer.crossCorrLength()); EXPECT_EQ(size_t(0), mLayer.numberOfLayers()); EXPECT_EQ(size_t(0), mLayer.numberOfInterfaces()); - //set parameter + // set parameter mLayer.setParameterValue(BornAgain::CrossCorrelationLength, 2.54); EXPECT_EQ(2.54, mLayer.crossCorrLength()); @@ -63,14 +70,14 @@ TEST_F(MultiLayerTest, LayerThicknesses) { set_four(); - //check layer thickness - EXPECT_EQ( 0.0, mLayer.layerThickness(0)); + // check layer thickness + EXPECT_EQ(0.0, mLayer.layerThickness(0)); EXPECT_EQ(20.0, mLayer.layerThickness(1)); EXPECT_EQ(40.0, mLayer.layerThickness(2)); - EXPECT_EQ( 0.0, mLayer.layerThickness(3)); + EXPECT_EQ(0.0, mLayer.layerThickness(3)); - //check bottomZ value - EXPECT_EQ( 0.0, mLayer.layerBottomZ(0)); + // check bottomZ value + EXPECT_EQ(0.0, mLayer.layerBottomZ(0)); EXPECT_EQ(-20.0, mLayer.layerBottomZ(1)); EXPECT_EQ(-60.0, mLayer.layerBottomZ(2)); EXPECT_EQ(-60.0, mLayer.layerBottomZ(3)); @@ -80,7 +87,7 @@ TEST_F(MultiLayerTest, CheckAllLayers) { set_four(); - //check individual layer + // check individual layer const Layer* got0 = mLayer.layer(0); EXPECT_EQ(BornAgain::LayerType, got0->getName()); EXPECT_EQ(0, got0->thickness()); @@ -106,60 +113,50 @@ TEST_F(MultiLayerTest, LayerInterfaces) { set_four(); - //check interfaces + // check interfaces const LayerInterface* interface0 = mLayer.layerInterface(0); - EXPECT_TRUE(nullptr!=interface0); + EXPECT_TRUE(nullptr != interface0); EXPECT_EQ(BornAgain::LayerInterfaceType, interface0->getName()); EXPECT_EQ(nullptr, interface0->getRoughness()); - EXPECT_EQ(topLayer.material()->getName(), - interface0->topLayer()->material()->getName()); - EXPECT_EQ(layer1.material()->getName(), - interface0->bottomLayer()->material()->getName()); + EXPECT_EQ(topLayer.material()->getName(), interface0->topLayer()->material()->getName()); + EXPECT_EQ(layer1.material()->getName(), interface0->bottomLayer()->material()->getName()); const LayerInterface* interface1 = mLayer.layerInterface(1); - EXPECT_TRUE(nullptr!=interface1); + EXPECT_TRUE(nullptr != interface1); EXPECT_EQ(BornAgain::LayerInterfaceType, interface1->getName()); EXPECT_EQ(nullptr, interface1->getRoughness()); - EXPECT_EQ(layer1.material()->getName(), - interface1->topLayer()->material()->getName()); - EXPECT_EQ(layer2.material()->getName(), - interface1->bottomLayer()->material()->getName()); + EXPECT_EQ(layer1.material()->getName(), interface1->topLayer()->material()->getName()); + EXPECT_EQ(layer2.material()->getName(), interface1->bottomLayer()->material()->getName()); const LayerInterface* interface2 = mLayer.layerInterface(2); - EXPECT_TRUE(nullptr!=interface2); + EXPECT_TRUE(nullptr != interface2); EXPECT_EQ(BornAgain::LayerInterfaceType, interface2->getName()); EXPECT_EQ(nullptr, interface2->getRoughness()); - EXPECT_EQ(layer2.material()->getName(), - interface2->topLayer()->material()->getName()); - EXPECT_EQ(substrate.material()->getName(), - interface2->bottomLayer()->material()->getName()); + EXPECT_EQ(layer2.material()->getName(), interface2->topLayer()->material()->getName()); + EXPECT_EQ(substrate.material()->getName(), interface2->bottomLayer()->material()->getName()); - //bottom interface + // bottom interface const LayerInterface* interfaceBottom = mLayer.layerBottomInterface(0); - EXPECT_TRUE(nullptr!=interfaceBottom); + EXPECT_TRUE(nullptr != interfaceBottom); EXPECT_EQ(BornAgain::LayerInterfaceType, interfaceBottom->getName()); EXPECT_EQ(nullptr, interfaceBottom->getRoughness()); - EXPECT_EQ(topLayer.material()->getName(), - interfaceBottom->topLayer()->material()->getName()); - EXPECT_EQ(layer1.material()->getName(), - interfaceBottom->bottomLayer()->material()->getName()); + EXPECT_EQ(topLayer.material()->getName(), interfaceBottom->topLayer()->material()->getName()); + EXPECT_EQ(layer1.material()->getName(), interfaceBottom->bottomLayer()->material()->getName()); - //top interface + // top interface const LayerInterface* interfaceTop = mLayer.layerTopInterface(3); - EXPECT_TRUE(nullptr!=interfaceTop); + EXPECT_TRUE(nullptr != interfaceTop); EXPECT_EQ(BornAgain::LayerInterfaceType, interfaceTop->getName()); EXPECT_EQ(nullptr, interfaceTop->getRoughness()); - EXPECT_EQ(layer2.material()->getName(), - interfaceTop->topLayer()->material()->getName()); - EXPECT_EQ(substrate.material()->getName(), - interfaceTop->bottomLayer()->material()->getName()); + EXPECT_EQ(layer2.material()->getName(), interfaceTop->topLayer()->material()->getName()); + EXPECT_EQ(substrate.material()->getName(), interfaceTop->bottomLayer()->material()->getName()); - //null interface + // null interface const LayerInterface* interfaceTopNull = mLayer.layerTopInterface(0); - EXPECT_TRUE(nullptr==interfaceTopNull); + EXPECT_TRUE(nullptr == interfaceTopNull); const LayerInterface* interfaceBottomNull = mLayer.layerBottomInterface(3); - EXPECT_TRUE(nullptr==interfaceBottomNull); + EXPECT_TRUE(nullptr == interfaceBottomNull); } TEST_F(MultiLayerTest, Clone) @@ -168,25 +165,25 @@ TEST_F(MultiLayerTest, Clone) MultiLayer* mLayerClone = mLayer.clone(); - //check properties + // check properties EXPECT_EQ(BornAgain::MultiLayerType, mLayerClone->getName()); - EXPECT_EQ(0.0,mLayerClone->crossCorrLength()); + EXPECT_EQ(0.0, mLayerClone->crossCorrLength()); EXPECT_EQ(size_t(4), mLayerClone->numberOfLayers()); EXPECT_EQ(size_t(3), mLayerClone->numberOfInterfaces()); - //check layer thickness + // check layer thickness EXPECT_EQ(topLayer.thickness(), mLayerClone->layerThickness(0)); EXPECT_EQ(layer1.thickness(), mLayerClone->layerThickness(1)); EXPECT_EQ(layer2.thickness(), mLayerClone->layerThickness(2)); EXPECT_EQ(substrate.thickness(), mLayerClone->layerThickness(3)); - //check bottomZ value + // check bottomZ value EXPECT_EQ(mLayer.layerBottomZ(0), mLayerClone->layerBottomZ(0)); EXPECT_EQ(mLayer.layerBottomZ(1), mLayerClone->layerBottomZ(1)); EXPECT_EQ(mLayer.layerBottomZ(2), mLayerClone->layerBottomZ(2)); EXPECT_EQ(mLayer.layerBottomZ(3), mLayerClone->layerBottomZ(3)); - //check individual layer + // check individual layer const Layer* layerCopy0 = mLayerClone->layer(0); EXPECT_EQ(topLayer.getName(), layerCopy0->getName()); EXPECT_EQ(topLayer.thickness(), layerCopy0->thickness()); @@ -207,50 +204,50 @@ TEST_F(MultiLayerTest, Clone) EXPECT_EQ(substrate.thickness(), layerCopy3->thickness()); EXPECT_EQ(substrate.material()->getName(), layerCopy3->material()->getName()); - //check interfaces + // check interfaces const LayerInterface* interface0 = mLayerClone->layerInterface(0); - EXPECT_TRUE(nullptr!=interface0); + EXPECT_TRUE(nullptr != interface0); EXPECT_EQ(BornAgain::LayerInterfaceType, interface0->getName()); EXPECT_EQ(nullptr, interface0->getRoughness()); EXPECT_EQ(topLayer.material()->getName(), interface0->topLayer()->material()->getName()); EXPECT_EQ(layer1.material()->getName(), interface0->bottomLayer()->material()->getName()); const LayerInterface* interface1 = mLayerClone->layerInterface(1); - EXPECT_TRUE(nullptr!=interface1); + EXPECT_TRUE(nullptr != interface1); EXPECT_EQ(BornAgain::LayerInterfaceType, interface1->getName()); EXPECT_EQ(nullptr, interface1->getRoughness()); EXPECT_EQ(layer1.material()->getName(), interface1->topLayer()->material()->getName()); EXPECT_EQ(layer2.material()->getName(), interface1->bottomLayer()->material()->getName()); const LayerInterface* interface2 = mLayerClone->layerInterface(2); - EXPECT_TRUE(nullptr!=interface2); + EXPECT_TRUE(nullptr != interface2); EXPECT_EQ(BornAgain::LayerInterfaceType, interface2->getName()); EXPECT_EQ(nullptr, interface2->getRoughness()); EXPECT_EQ(layer2.material()->getName(), interface2->topLayer()->material()->getName()); EXPECT_EQ(substrate.material()->getName(), interface2->bottomLayer()->material()->getName()); - //top interface + // top interface const LayerInterface* interfaceBottom = mLayerClone->layerTopInterface(1); - EXPECT_TRUE(nullptr!=interfaceBottom); + EXPECT_TRUE(nullptr != interfaceBottom); EXPECT_EQ(BornAgain::LayerInterfaceType, interfaceBottom->getName()); EXPECT_EQ(nullptr, interfaceBottom->getRoughness()); EXPECT_EQ(topLayer.material()->getName(), interfaceBottom->topLayer()->material()->getName()); EXPECT_EQ(layer1.material()->getName(), interfaceBottom->bottomLayer()->material()->getName()); - //Bottom interface + // Bottom interface const LayerInterface* interfaceTop = mLayerClone->layerBottomInterface(2); - EXPECT_TRUE(nullptr!=interfaceTop); + EXPECT_TRUE(nullptr != interfaceTop); EXPECT_EQ(BornAgain::LayerInterfaceType, interfaceTop->getName()); EXPECT_EQ(nullptr, interfaceTop->getRoughness()); EXPECT_EQ(layer2.material()->getName(), interfaceTop->topLayer()->material()->getName()); EXPECT_EQ(substrate.material()->getName(), interfaceTop->bottomLayer()->material()->getName()); - //null interface + // null interface const LayerInterface* interfaceTopNull = mLayerClone->layerTopInterface(0); - EXPECT_TRUE(nullptr==interfaceTopNull); + EXPECT_TRUE(nullptr == interfaceTopNull); const LayerInterface* interfaceBottomNull = mLayerClone->layerBottomInterface(3); - EXPECT_TRUE(nullptr==interfaceBottomNull); + EXPECT_TRUE(nullptr == interfaceBottomNull); delete mLayerClone; } @@ -261,25 +258,25 @@ TEST_F(MultiLayerTest, CloneInvertB) MultiLayer* mLayerClone = mLayer.cloneInvertB(); - //check properties + // check properties EXPECT_EQ(BornAgain::MultiLayerType, mLayerClone->getName()); - EXPECT_EQ(0.0,mLayerClone->crossCorrLength()); + EXPECT_EQ(0.0, mLayerClone->crossCorrLength()); EXPECT_EQ(size_t(4), mLayerClone->numberOfLayers()); EXPECT_EQ(size_t(3), mLayerClone->numberOfInterfaces()); - //check layer thickness + // check layer thickness EXPECT_EQ(topLayer.thickness(), mLayerClone->layerThickness(0)); EXPECT_EQ(layer1.thickness(), mLayerClone->layerThickness(1)); EXPECT_EQ(layer2.thickness(), mLayerClone->layerThickness(2)); EXPECT_EQ(substrate.thickness(), mLayerClone->layerThickness(3)); - //check bottomZ value + // check bottomZ value EXPECT_EQ(mLayer.layerBottomZ(0), mLayerClone->layerBottomZ(0)); EXPECT_EQ(mLayer.layerBottomZ(1), mLayerClone->layerBottomZ(1)); EXPECT_EQ(mLayer.layerBottomZ(2), mLayerClone->layerBottomZ(2)); EXPECT_EQ(mLayer.layerBottomZ(3), mLayerClone->layerBottomZ(3)); - //check individual layer + // check individual layer const Layer* layerCopy0 = mLayerClone->layer(0); EXPECT_EQ(topLayer.getName(), layerCopy0->getName()); EXPECT_EQ(topLayer.thickness(), layerCopy0->thickness()); @@ -300,60 +297,60 @@ TEST_F(MultiLayerTest, CloneInvertB) EXPECT_EQ(substrate.thickness(), layerCopy3->thickness()); EXPECT_EQ(substrate.material()->getName(), layerCopy3->material()->getName()); - //check interfaces + // check interfaces const LayerInterface* interface0 = mLayerClone->layerInterface(0); - EXPECT_TRUE(nullptr!=interface0); + EXPECT_TRUE(nullptr != interface0); EXPECT_EQ(BornAgain::LayerInterfaceType, interface0->getName()); EXPECT_EQ(nullptr, interface0->getRoughness()); EXPECT_EQ(topLayer.material()->getName(), interface0->topLayer()->material()->getName()); EXPECT_EQ(layer1.material()->getName(), interface0->bottomLayer()->material()->getName()); const LayerInterface* interface1 = mLayerClone->layerInterface(1); - EXPECT_TRUE(nullptr!=interface1); + EXPECT_TRUE(nullptr != interface1); EXPECT_EQ(BornAgain::LayerInterfaceType, interface1->getName()); EXPECT_EQ(nullptr, interface1->getRoughness()); EXPECT_EQ(layer1.material()->getName(), interface1->topLayer()->material()->getName()); EXPECT_EQ(layer2.material()->getName(), interface1->bottomLayer()->material()->getName()); const LayerInterface* interface2 = mLayerClone->layerInterface(2); - EXPECT_TRUE(nullptr!=interface2); + EXPECT_TRUE(nullptr != interface2); EXPECT_EQ(BornAgain::LayerInterfaceType, interface2->getName()); EXPECT_EQ(nullptr, interface2->getRoughness()); EXPECT_EQ(layer2.material()->getName(), interface2->topLayer()->material()->getName()); EXPECT_EQ(substrate.material()->getName(), interface2->bottomLayer()->material()->getName()); - //top interface + // top interface const LayerInterface* interfaceBottom = mLayerClone->layerTopInterface(1); - EXPECT_TRUE(nullptr!=interfaceBottom); + EXPECT_TRUE(nullptr != interfaceBottom); EXPECT_EQ(BornAgain::LayerInterfaceType, interfaceBottom->getName()); EXPECT_EQ(nullptr, interfaceBottom->getRoughness()); EXPECT_EQ(topLayer.material()->getName(), interfaceBottom->topLayer()->material()->getName()); EXPECT_EQ(layer1.material()->getName(), interfaceBottom->bottomLayer()->material()->getName()); - //Bottom interface + // Bottom interface const LayerInterface* interfaceTop = mLayerClone->layerBottomInterface(2); - EXPECT_TRUE(nullptr!=interfaceTop); + EXPECT_TRUE(nullptr != interfaceTop); EXPECT_EQ(BornAgain::LayerInterfaceType, interfaceTop->getName()); EXPECT_EQ(nullptr, interfaceTop->getRoughness()); EXPECT_EQ(layer2.material()->getName(), interfaceTop->topLayer()->material()->getName()); EXPECT_EQ(substrate.material()->getName(), interfaceTop->bottomLayer()->material()->getName()); - //null interface + // null interface const LayerInterface* interfaceTopNull = mLayerClone->layerTopInterface(0); - EXPECT_TRUE(nullptr==interfaceTopNull); + EXPECT_TRUE(nullptr == interfaceTopNull); const LayerInterface* interfaceBottomNull = mLayerClone->layerBottomInterface(3); - EXPECT_TRUE(nullptr==interfaceBottomNull); + EXPECT_TRUE(nullptr == interfaceBottomNull); delete mLayerClone; } TEST_F(MultiLayerTest, WithRoughness) { - //LayerRoughness(double sigma, double hurstParameter, double lateralCorrLength); + // LayerRoughness(double sigma, double hurstParameter, double lateralCorrLength); LayerRoughness lr(1.1, -7.3, 0.1); mLayer.addLayer(topLayer); - mLayer.addLayerWithTopRoughness(layer1,lr); + mLayer.addLayerWithTopRoughness(layer1, lr); mLayer.addLayer(substrate); const LayerInterface* interface0 = mLayer.layerInterface(0); @@ -376,8 +373,8 @@ TEST_F(MultiLayerTest, CloneWithRoughness) LayerRoughness lr1(1.1, -7.3, 0.1); mLayer.addLayer(topLayer); - mLayer.addLayerWithTopRoughness(layer1,lr0); - mLayer.addLayerWithTopRoughness(substrate,lr1); + mLayer.addLayerWithTopRoughness(layer1, lr0); + mLayer.addLayerWithTopRoughness(substrate, lr1); MultiLayer* mLayerClone = mLayer.clone(); @@ -389,29 +386,29 @@ TEST_F(MultiLayerTest, CloneWithRoughness) EXPECT_TRUE(roughness0); EXPECT_TRUE(roughness1); - EXPECT_EQ( -2.1, roughness0->getSigma()); - EXPECT_EQ( 7.3, roughness0->getHurstParameter()); - EXPECT_EQ( 12.1, roughness0->getLatteralCorrLength()); + EXPECT_EQ(-2.1, roughness0->getSigma()); + EXPECT_EQ(7.3, roughness0->getHurstParameter()); + EXPECT_EQ(12.1, roughness0->getLatteralCorrLength()); - EXPECT_EQ( 1.1, roughness1->getSigma()); - EXPECT_EQ( -7.3, roughness1->getHurstParameter()); - EXPECT_EQ( 0.1, roughness1->getLatteralCorrLength()); + EXPECT_EQ(1.1, roughness1->getSigma()); + EXPECT_EQ(-7.3, roughness1->getHurstParameter()); + EXPECT_EQ(0.1, roughness1->getLatteralCorrLength()); delete mLayerClone; } TEST_F(MultiLayerTest, CloneInvertBWithRoughness) { - Layer layer1(iron, 20*Units::nanometer); - Layer layer2(stone, 5*Units::nanometer); + Layer layer1(iron, 20 * Units::nanometer); + Layer layer2(stone, 5 * Units::nanometer); - //LayerRoughness(double sigma, double hurstParameter, double lateralCorrLength); - LayerRoughness lr0(-2.1, 7.3, 12.1); + // LayerRoughness(double sigma, double hurstParameter, double lateralCorrLength); + LayerRoughness lr0(-2.1, 7.3, 12.1); LayerRoughness lr1(1.1, -7.3, 0.1); mLayer.addLayer(topLayer); - mLayer.addLayerWithTopRoughness(layer1,lr0); - mLayer.addLayerWithTopRoughness(layer2,lr1); + mLayer.addLayerWithTopRoughness(layer1, lr0); + mLayer.addLayerWithTopRoughness(layer2, lr1); MultiLayer* mLayerClone = mLayer.cloneInvertB(); @@ -420,13 +417,13 @@ TEST_F(MultiLayerTest, CloneInvertBWithRoughness) const LayerRoughness* roughness0 = interface0->getRoughness(); const LayerRoughness* roughness1 = interface1->getRoughness(); - EXPECT_EQ( -2.1, roughness0->getSigma()); - EXPECT_EQ( 7.3, roughness0->getHurstParameter()); - EXPECT_EQ( 12.1, roughness0->getLatteralCorrLength()); + EXPECT_EQ(-2.1, roughness0->getSigma()); + EXPECT_EQ(7.3, roughness0->getHurstParameter()); + EXPECT_EQ(12.1, roughness0->getLatteralCorrLength()); - EXPECT_EQ( 1.1, roughness1->getSigma()); - EXPECT_EQ( -7.3, roughness1->getHurstParameter()); - EXPECT_EQ( 0.1, roughness1->getLatteralCorrLength()); + EXPECT_EQ(1.1, roughness1->getSigma()); + EXPECT_EQ(-7.3, roughness1->getHurstParameter()); + EXPECT_EQ(0.1, roughness1->getLatteralCorrLength()); delete mLayerClone; } @@ -437,10 +434,10 @@ TEST_F(MultiLayerTest, WithMagneticMaterial) Material magMaterial0 = HomogeneousMaterial("MagMat0", 6e-4, 2e-8, magnetic_field); Material magMaterial1 = HomogeneousMaterial("MagMat1", -5.6, 10, magnetic_field); - Layer layer1(iron, 20*Units::nanometer); - Layer layer2(stone, 30*Units::nanometer); - Layer layer3(magMaterial0, 20*Units::nanometer); - Layer layer4(magMaterial1, 0*Units::nanometer); + Layer layer1(iron, 20 * Units::nanometer); + Layer layer2(stone, 30 * Units::nanometer); + Layer layer3(magMaterial0, 20 * Units::nanometer); + Layer layer4(magMaterial1, 0 * Units::nanometer); mLayer.addLayer(topLayer); mLayer.addLayer(layer1); @@ -457,8 +454,8 @@ TEST_F(MultiLayerTest, CloneWithMagneticMaterial) kvector_t magnetic_field(1.1, 2.1, -5.1); Material magMaterial0 = HomogeneousMaterial("MagMat0", 6e-4, 2e-8, magnetic_field); - Layer layer1(iron, 20*Units::nanometer); - Layer layer2(magMaterial0, 20*Units::nanometer); + Layer layer1(iron, 20 * Units::nanometer); + Layer layer2(magMaterial0, 20 * Units::nanometer); mLayer.addLayer(topLayer); mLayer.addLayer(layer1); mLayer.addLayer(layer2); @@ -473,8 +470,8 @@ TEST_F(MultiLayerTest, CloneInvertBMagneticMaterial) kvector_t magnetic_field(0.0, 0.0, 1.0); Material magMaterial0 = HomogeneousMaterial("MagMat0", 6e-4, 2e-8, magnetic_field); - Layer layer1(iron, 20*Units::nanometer); - Layer layer2(magMaterial0, 20*Units::nanometer); + Layer layer1(iron, 20 * Units::nanometer); + Layer layer2(magMaterial0, 20 * Units::nanometer); mLayer.addLayer(topLayer); mLayer.addLayer(layer1); @@ -492,10 +489,10 @@ TEST_F(MultiLayerTest, MultiLayerCompositeTest) Material magMaterial0 = HomogeneousMaterial("MagMat0", 6e-4, 2e-8, magnetic_field); Material magMaterial1 = HomogeneousMaterial("MagMat1", -5.6, 10, magnetic_field); - Layer layer1(iron, 10*Units::nanometer); - Layer layer2(magMaterial0, 20*Units::nanometer); - Layer layer3(magMaterial1, 30*Units::nanometer); - Layer layer4(stone, 40*Units::nanometer); + Layer layer1(iron, 10 * Units::nanometer); + Layer layer2(magMaterial0, 20 * Units::nanometer); + Layer layer3(magMaterial1, 30 * Units::nanometer); + Layer layer4(stone, 40 * Units::nanometer); mLayer.addLayer(topLayer); mLayer.addLayer(layer1); @@ -503,33 +500,31 @@ TEST_F(MultiLayerTest, MultiLayerCompositeTest) mLayer.addLayer(layer3); mLayer.addLayer(layer4); - std::vector<const Layer *> layer_buffer; - std::vector<const LayerInterface *> interface_buffer; + std::vector<const Layer*> layer_buffer; + std::vector<const LayerInterface*> interface_buffer; int counter(0); std::vector<const INode*> children = mLayer.getChildren(); - for(size_t index=0; index<children.size();++index) - { - const INode *sample = children[index]; - if(counter%2 == 1) - { - const LayerInterface *interface = dynamic_cast<const LayerInterface *>(sample); + for (size_t index = 0; index < children.size(); ++index) { + const INode* sample = children[index]; + if (counter % 2 == 1) { + const LayerInterface* interface = dynamic_cast<const LayerInterface*>(sample); EXPECT_TRUE(nullptr != interface); interface_buffer.push_back(interface); } else { - const Layer *layer = dynamic_cast<const Layer *>(sample); + const Layer* layer = dynamic_cast<const Layer*>(sample); EXPECT_TRUE(nullptr != layer); layer_buffer.push_back(layer); } counter++; } - EXPECT_EQ( size_t(5), layer_buffer.size()); - EXPECT_EQ( size_t(4), interface_buffer.size()); - for(size_t i=0; i<layer_buffer.size(); ++i) { - EXPECT_EQ( double(i*10), layer_buffer[i]->thickness()); + EXPECT_EQ(size_t(5), layer_buffer.size()); + EXPECT_EQ(size_t(4), interface_buffer.size()); + for (size_t i = 0; i < layer_buffer.size(); ++i) { + EXPECT_EQ(double(i * 10), layer_buffer[i]->thickness()); } - for(size_t i=0; i<interface_buffer.size(); ++i) { - EXPECT_EQ( double((i+1)*10), interface_buffer[i]->bottomLayer()->thickness()); + for (size_t i = 0; i < interface_buffer.size(); ++i) { + EXPECT_EQ(double((i + 1) * 10), interface_buffer[i]->bottomLayer()->thickness()); } } @@ -546,10 +541,10 @@ TEST_F(MultiLayerTest, MultiLayerZtoIndex) // index_3 // ----------------- -60.0 // index_4 - Layer layer1(air, 10*Units::nanometer); - Layer layer2(air, 20*Units::nanometer); - Layer layer3(air, 30*Units::nanometer); - Layer layer4(air, 0*Units::nanometer); + Layer layer1(air, 10 * Units::nanometer); + Layer layer2(air, 20 * Units::nanometer); + Layer layer3(air, 30 * Units::nanometer); + Layer layer4(air, 0 * Units::nanometer); mLayer.addLayer(topLayer); mLayer.addLayer(layer1); mLayer.addLayer(layer2); diff --git a/Tests/UnitTests/Core/Sample/ParticleCompositionTest.h b/Tests/UnitTests/Core/Sample/ParticleCompositionTest.h index f6cf54c8ff3..df82c4bfcd8 100644 --- a/Tests/UnitTests/Core/Sample/ParticleCompositionTest.h +++ b/Tests/UnitTests/Core/Sample/ParticleCompositionTest.h @@ -1,18 +1,19 @@ +#include "google_test.h" +#include "BornAgainNamespace.h" #include "FormFactorFullSphere.h" #include "MaterialFactoryFuncs.h" #include "MathConstants.h" #include "Particle.h" #include "ParticleComposition.h" -#include "BornAgainNamespace.h" -#include <iostream> class ParticleCompositionTest : public ::testing::Test { protected: - ParticleCompositionTest(){} - virtual ~ParticleCompositionTest(){} + ~ParticleCompositionTest(); }; +ParticleCompositionTest::~ParticleCompositionTest() = default; + TEST_F(ParticleCompositionTest, ParticleCompositionDefaultConstructor) { std::unique_ptr<ParticleComposition> composition(new ParticleComposition()); diff --git a/Tests/UnitTests/Core/Sample/ParticleCoreShellTest.h b/Tests/UnitTests/Core/Sample/ParticleCoreShellTest.h index 565f0070134..312ec38d292 100644 --- a/Tests/UnitTests/Core/Sample/ParticleCoreShellTest.h +++ b/Tests/UnitTests/Core/Sample/ParticleCoreShellTest.h @@ -1,24 +1,22 @@ -#include "HardParticles.h" -#include "ParticleCoreShell.h" +#include "google_test.h" #include "BornAgainNamespace.h" +#include "HardParticles.h" #include "MaterialFactoryFuncs.h" #include "MathConstants.h" #include "Particle.h" +#include "ParticleCoreShell.h" #include "Rotations.h" -#include <iostream> - class ParticleCoreShellTest : public ::testing::Test { protected: ParticleCoreShellTest(); virtual ~ParticleCoreShellTest(); - ParticleCoreShell *mp_coreshell; + ParticleCoreShell* mp_coreshell; }; -ParticleCoreShellTest::ParticleCoreShellTest() - : mp_coreshell(nullptr) +ParticleCoreShellTest::ParticleCoreShellTest() : mp_coreshell(nullptr) { Particle core; Particle shell; @@ -26,10 +24,7 @@ ParticleCoreShellTest::ParticleCoreShellTest() mp_coreshell = new ParticleCoreShell(shell, core, position); } -ParticleCoreShellTest::~ParticleCoreShellTest() -{ - delete mp_coreshell; -} +ParticleCoreShellTest::~ParticleCoreShellTest() { delete mp_coreshell; } TEST_F(ParticleCoreShellTest, InitialState) { @@ -42,7 +37,7 @@ TEST_F(ParticleCoreShellTest, InitialState) TEST_F(ParticleCoreShellTest, Clone) { - ParticleCoreShell *p_clone = mp_coreshell->clone(); + ParticleCoreShell* p_clone = mp_coreshell->clone(); EXPECT_EQ(nullptr, p_clone->createFormFactor()); EXPECT_EQ(nullptr, p_clone->rotation()); EXPECT_EQ(BornAgain::ParticleCoreShellType, p_clone->getName()); @@ -59,18 +54,18 @@ TEST_F(ParticleCoreShellTest, ComplexCoreShellClone) double shell_length(50); double shell_width(20); double shell_height(10); - double core_length = shell_length/2; - double core_width = shell_width/2; - double core_height = shell_height/2; + double core_length = shell_length / 2; + double core_width = shell_width / 2; + double core_height = shell_height / 2; Particle core(mCore, FormFactorBox(core_length, core_width, core_height)); Particle shell(mShell, FormFactorBox(shell_length, shell_width, shell_height)); - kvector_t relative_pos(0, 0, (shell_height-core_height)/2); + kvector_t relative_pos(0, 0, (shell_height - core_height) / 2); ParticleCoreShell coreshell(shell, core, relative_pos); - coreshell.setRotation(RotationY(90*Units::degree)); - coreshell.setPosition(kvector_t(0,0,-10)); + coreshell.setRotation(RotationY(90 * Units::degree)); + coreshell.setPosition(kvector_t(0, 0, -10)); - ParticleCoreShell *clone = coreshell.clone(); + ParticleCoreShell* clone = coreshell.clone(); EXPECT_EQ(coreshell.coreParticle()->position(), relative_pos); EXPECT_EQ(clone->coreParticle()->position(), relative_pos); } diff --git a/Tests/UnitTests/Core/Sample/ParticleDistributionTest.h b/Tests/UnitTests/Core/Sample/ParticleDistributionTest.h index a8bdb50aa8a..3ea2d0b106f 100644 --- a/Tests/UnitTests/Core/Sample/ParticleDistributionTest.h +++ b/Tests/UnitTests/Core/Sample/ParticleDistributionTest.h @@ -1,20 +1,24 @@ -#include "Particle.h" -#include "ParticleDistribution.h" -#include "MaterialFactoryFuncs.h" -#include "Distributions.h" +#include "google_test.h" #include "BornAgainNamespace.h" +#include "Distributions.h" +#include "MaterialFactoryFuncs.h" #include "ParameterUtils.h" +#include "Particle.h" +#include "ParticleDistribution.h" #include "Units.h" +#include "FormFactors.h" class ParticleDistributionTest : public ::testing::Test { protected: - ParticleDistributionTest(){} + ~ParticleDistributionTest(); }; +ParticleDistributionTest::~ParticleDistributionTest() = default; + TEST_F(ParticleDistributionTest, getChildren) { - Particle particle(HomogeneousMaterial("Air",0.0, 0.0), FormFactorFullSphere(1.0)); + Particle particle(HomogeneousMaterial("Air", 0.0, 0.0), FormFactorFullSphere(1.0)); ParameterDistribution parameter("name", DistributionGate(1.0, 2.0), 5, 0.0, 1.0); ParticleDistribution distr(particle, parameter); @@ -26,7 +30,7 @@ TEST_F(ParticleDistributionTest, getChildren) TEST_F(ParticleDistributionTest, mainParameterUnits) { - Material mat = HomogeneousMaterial("Air",0.0, 0.0); + Material mat = HomogeneousMaterial("Air", 0.0, 0.0); DistributionGate gate(1.0, 2.0); ParameterDistribution par("/Particle/FullSphere/Radius", gate, 5); @@ -34,7 +38,6 @@ TEST_F(ParticleDistributionTest, mainParameterUnits) EXPECT_EQ(ParameterUtils::mainParUnits(distr), BornAgain::UnitsNm); par = ParameterDistribution("/Particle/Cone/Alpha", gate, 5); - ParticleDistribution distr2(Particle(mat, FormFactorCone(10.0, 20.0, 70.0*Units::deg)), par); + ParticleDistribution distr2(Particle(mat, FormFactorCone(10.0, 20.0, 70.0 * Units::deg)), par); EXPECT_EQ(ParameterUtils::mainParUnits(distr2), BornAgain::UnitsRad); - } diff --git a/Tests/UnitTests/Core/Sample/ParticleLayoutTest.h b/Tests/UnitTests/Core/Sample/ParticleLayoutTest.h index 1f58e9be630..fab3cdea849 100644 --- a/Tests/UnitTests/Core/Sample/ParticleLayoutTest.h +++ b/Tests/UnitTests/Core/Sample/ParticleLayoutTest.h @@ -1,16 +1,21 @@ -#include "ParticleLayout.h" +#include "google_test.h" +#include "BornAgainNamespace.h" #include "IAbstractParticle.h" #include "INodeUtils.h" -#include "InterferenceFunctionNone.h" #include "InterferenceFunction1DLattice.h" -#include "BornAgainNamespace.h" +#include "InterferenceFunctionNone.h" +#include "ParticleLayout.h" +#include "Particle.h" -class ParticleLayoutTest : public :: testing :: Test { +class ParticleLayoutTest : public ::testing::Test +{ protected: - ParticleLayoutTest(){} + ~ParticleLayoutTest(); }; +ParticleLayoutTest::~ParticleLayoutTest() = default; + TEST_F(ParticleLayoutTest, ParticleLayoutInitial) { ParticleLayout particleDecoration; @@ -34,9 +39,8 @@ TEST_F(ParticleLayoutTest, ParticleLayoutInitByValue) EXPECT_EQ(size_t(1), particles.size()); EXPECT_EQ(nullptr, p_iff); - - const IAbstractParticle * p_particle = particles[0]; - EXPECT_TRUE(nullptr!=p_particle); + const IAbstractParticle* p_particle = particles[0]; + EXPECT_TRUE(nullptr != p_particle); EXPECT_EQ(2.0, particleDecoration.getTotalAbundance()); } @@ -52,8 +56,8 @@ TEST_F(ParticleLayoutTest, ParticleLayoutInitByRef) EXPECT_EQ(size_t(1), particles.size()); EXPECT_EQ(nullptr, p_iff); - const IAbstractParticle * p_particle = particles[0]; - EXPECT_TRUE(nullptr!=p_particle); + const IAbstractParticle* p_particle = particles[0]; + EXPECT_TRUE(nullptr != p_particle); EXPECT_EQ(-2.0, particleDecoration.getTotalAbundance()); } @@ -66,32 +70,31 @@ TEST_F(ParticleLayoutTest, ParticleLayoutAddParticle) Particle particle3; Particle particle4; - RotationZ transform3(45.*Units::degree); - RotationZ transform4(45.*Units::degree); + RotationZ transform3(45. * Units::degree); + RotationZ transform4(45. * Units::degree); particleDecoration.addParticle(particle1); particleDecoration.addParticle(particle2, 2.2); - particleDecoration.addParticle(particle3, 1.0, kvector_t(0,0,0), transform3); - particleDecoration.addParticle(particle4, -4.2, kvector_t(0,0,0), transform4); + particleDecoration.addParticle(particle3, 1.0, kvector_t(0, 0, 0), transform3); + particleDecoration.addParticle(particle4, -4.2, kvector_t(0, 0, 0), transform4); auto particles = INodeUtils::ChildNodesOfType<IAbstractParticle>(particleDecoration); - EXPECT_EQ(size_t(4), particles.size()); - const IAbstractParticle * p_particle1 = particles[0]; - EXPECT_TRUE(nullptr!=p_particle1); + const IAbstractParticle* p_particle1 = particles[0]; + EXPECT_TRUE(nullptr != p_particle1); EXPECT_EQ(1.0, p_particle1->abundance()); - const IAbstractParticle * p_particle2 = particles[1]; - EXPECT_TRUE(nullptr!=p_particle2); + const IAbstractParticle* p_particle2 = particles[1]; + EXPECT_TRUE(nullptr != p_particle2); EXPECT_EQ(2.2, p_particle2->abundance()); - const IAbstractParticle * p_particle3 = particles[2]; - EXPECT_TRUE(nullptr!=p_particle3); + const IAbstractParticle* p_particle3 = particles[2]; + EXPECT_TRUE(nullptr != p_particle3); EXPECT_EQ(1.0, p_particle3->abundance()); - const IAbstractParticle * p_particle4 = particles[3]; - EXPECT_TRUE(nullptr!=p_particle4); + const IAbstractParticle* p_particle4 = particles[3]; + EXPECT_TRUE(nullptr != p_particle4); EXPECT_EQ(-4.2, p_particle4->abundance()); } @@ -104,13 +107,13 @@ TEST_F(ParticleLayoutTest, ParticleLayoutAbundanceFraction) Particle particle3; Particle particle4; - RotationY transform3(45.*Units::degree); - RotationZ transform4(45.*Units::degree); + RotationY transform3(45. * Units::degree); + RotationZ transform4(45. * Units::degree); particleDecoration.addParticle(particle1); particleDecoration.addParticle(particle2, 2.0); - particleDecoration.addParticle(particle3, 1.0, kvector_t(0,0,0), transform3); - particleDecoration.addParticle(particle4, 4.0, kvector_t(0,0,0), transform4); + particleDecoration.addParticle(particle3, 1.0, kvector_t(0, 0, 0), transform3); + particleDecoration.addParticle(particle4, 4.0, kvector_t(0, 0, 0), transform4); EXPECT_EQ(8.0, particleDecoration.getTotalAbundance()); } @@ -123,13 +126,13 @@ TEST_F(ParticleLayoutTest, ParticleLayoutClone) Particle particle3; Particle particle4; - RotationY transform3(45.*Units::degree); - RotationZ transform4(45.*Units::degree); + RotationY transform3(45. * Units::degree); + RotationZ transform4(45. * Units::degree); particleDecoration.addParticle(particle1); particleDecoration.addParticle(particle2, 2.0); - particleDecoration.addParticle(particle3, 1.0, kvector_t(0,0,0), transform3); - particleDecoration.addParticle(particle4, 4.0, kvector_t(0,0,0), transform4); + particleDecoration.addParticle(particle3, 1.0, kvector_t(0, 0, 0), transform3); + particleDecoration.addParticle(particle4, 4.0, kvector_t(0, 0, 0), transform4); Material mat5 = HomogeneousMaterial("core", 0, 0); Particle particle5(mat5); @@ -140,34 +143,34 @@ TEST_F(ParticleLayoutTest, ParticleLayoutClone) particleDecoration.setInterferenceFunction(iff_none); particleDecoration.setInterferenceFunction(iff_none); - ParticleLayout * clone = particleDecoration.clone(); + ParticleLayout* clone = particleDecoration.clone(); auto particles = INodeUtils::ChildNodesOfType<IAbstractParticle>(*clone); EXPECT_EQ(BornAgain::ParticleLayoutType, clone->getName()); - const IAbstractParticle * p_particle1 = particles[0]; - EXPECT_TRUE(nullptr!=p_particle1); + const IAbstractParticle* p_particle1 = particles[0]; + EXPECT_TRUE(nullptr != p_particle1); EXPECT_EQ(1.0, p_particle1->abundance()); - const IAbstractParticle * p_particle2 = particles[1]; - EXPECT_TRUE(nullptr!=p_particle2); + const IAbstractParticle* p_particle2 = particles[1]; + EXPECT_TRUE(nullptr != p_particle2); EXPECT_EQ(2.0, p_particle2->abundance()); - const IAbstractParticle * p_particle3 = particles[2]; - EXPECT_TRUE(nullptr!=p_particle3); + const IAbstractParticle* p_particle3 = particles[2]; + EXPECT_TRUE(nullptr != p_particle3); EXPECT_EQ(1.0, p_particle3->abundance()); - const IAbstractParticle * p_particle4 = particles[3]; - EXPECT_TRUE(nullptr!=p_particle4); + const IAbstractParticle* p_particle4 = particles[3]; + EXPECT_TRUE(nullptr != p_particle4); EXPECT_EQ(4.0, p_particle4->abundance()); - const IAbstractParticle * p_particle5 = particles[4]; - EXPECT_TRUE(nullptr!=p_particle5); + const IAbstractParticle* p_particle5 = particles[4]; + EXPECT_TRUE(nullptr != p_particle5); EXPECT_EQ(0.0, p_particle5->abundance()); auto p_iff = INodeUtils::OnlyChildOfType<IInterferenceFunction>(*clone); - EXPECT_TRUE(nullptr!=p_iff); + EXPECT_TRUE(nullptr != p_iff); } TEST_F(ParticleLayoutTest, ParticleLayoutInterferenceFunction) @@ -178,7 +181,7 @@ TEST_F(ParticleLayoutTest, ParticleLayoutInterferenceFunction) particleDecoration.setInterferenceFunction(iff_none); auto p_iff = INodeUtils::OnlyChildOfType<IInterferenceFunction>(particleDecoration); - EXPECT_TRUE(nullptr!=p_iff); + EXPECT_TRUE(nullptr != p_iff); } TEST_F(ParticleLayoutTest, getChildren) diff --git a/Tests/UnitTests/Core/Sample/ParticleTest.h b/Tests/UnitTests/Core/Sample/ParticleTest.h index f11b4284ec4..07f49ec569b 100644 --- a/Tests/UnitTests/Core/Sample/ParticleTest.h +++ b/Tests/UnitTests/Core/Sample/ParticleTest.h @@ -1,17 +1,19 @@ -#include "Particle.h" +#include "google_test.h" #include "BornAgainNamespace.h" +#include "FormFactorFullSphere.h" #include "MaterialFactoryFuncs.h" #include "MathConstants.h" -#include "FormFactorFullSphere.h" - -#include <iostream> +#include "Particle.h" +#include "Units.h" class ParticleTest : public ::testing::Test { protected: - ParticleTest(){} + ~ParticleTest(); }; +ParticleTest::~ParticleTest() = default; + TEST_F(ParticleTest, InitialState) { Particle particle; @@ -33,34 +35,34 @@ TEST_F(ParticleTest, Clone) TEST_F(ParticleTest, Constructors) { - Material mat = HomogeneousMaterial("Air",0,0); + Material mat = HomogeneousMaterial("Air", 0, 0); FormFactorFullSphere sphere(1.0); - RotationZ transform(45.*Units::degree); + RotationZ transform(45. * Units::degree); // construction with material std::unique_ptr<Particle> p1(new Particle(mat)); EXPECT_EQ(mat, *p1->material()); EXPECT_EQ(nullptr, p1->createFormFactor()); - EXPECT_EQ( nullptr, p1->rotation()); + EXPECT_EQ(nullptr, p1->rotation()); // construction with formfactor std::unique_ptr<Particle> p2(new Particle(mat, sphere)); EXPECT_EQ(mat, *p2->material()); - EXPECT_TRUE(dynamic_cast<FormFactorDecoratorMaterial *>(p2->createFormFactor())); - EXPECT_EQ( nullptr, p2->rotation()); + EXPECT_TRUE(dynamic_cast<FormFactorDecoratorMaterial*>(p2->createFormFactor())); + EXPECT_EQ(nullptr, p2->rotation()); // construction with transformation std::unique_ptr<Particle> p3(new Particle(mat, sphere, transform)); EXPECT_EQ(mat, *p3->material()); - EXPECT_TRUE(dynamic_cast<FormFactorDecoratorMaterial *>(p3->createFormFactor())); + EXPECT_TRUE(dynamic_cast<FormFactorDecoratorMaterial*>(p3->createFormFactor())); EXPECT_EQ(BornAgain::ZRotationType, p3->rotation()->getName()); } TEST_F(ParticleTest, setters) { - Material mat = HomogeneousMaterial("Air",0,0); + Material mat = HomogeneousMaterial("Air", 0, 0); FormFactorFullSphere sphere(2.1); - RotationY transform(45.*Units::degree); + RotationY transform(45. * Units::degree); Particle particle; Material vacuum = HomogeneousMaterial(); @@ -78,7 +80,7 @@ TEST_F(ParticleTest, setters) TEST_F(ParticleTest, getChildren) { - Material mat = HomogeneousMaterial("Air",0,0); + Material mat = HomogeneousMaterial("Air", 0, 0); FormFactorFullSphere sphere(2.1); // Checking children of particle (no rotation) diff --git a/Tests/UnitTests/Core/Sample/RTTest.h b/Tests/UnitTests/Core/Sample/RTTest.h index 80b03f343dc..6110eaaaaf8 100644 --- a/Tests/UnitTests/Core/Sample/RTTest.h +++ b/Tests/UnitTests/Core/Sample/RTTest.h @@ -1,5 +1,4 @@ -//! Numeric tests of scalar RT computation. - +#include "google_test.h" #include "BornAgainNamespace.h" #include "Layer.h" #include "Layer.h" @@ -11,23 +10,23 @@ #include "ParticleLayout.h" #include "SpecularMatrix.h" -#include <iostream> // for debug phases - class RTTest : public ::testing::Test { protected: - RTTest() {} - void printCoeffs(const std::vector<ScalarRTCoefficients>& coeffs) { // for debug phases - for (size_t i=0; i<coeffs.size(); ++i) { + ~RTTest(); + void printCoeffs(const std::vector<ScalarRTCoefficients>& coeffs) + { // for debug phases + for (size_t i = 0; i < coeffs.size(); ++i) { const ScalarRTCoefficients& coeff = coeffs[i]; std::cout << i << " " << coeff.t_r(0) << " " << coeff.t_r(1) << "\n"; } } - void compareCoeffs(const ScalarRTCoefficients& coeff1, const ScalarRTCoefficients& coeff2) { - EXPECT_NEAR(abs(coeff1.t_r(0)), abs(coeff2.t_r(0)), 1e-14); + void compareCoeffs(const ScalarRTCoefficients& coeff1, const ScalarRTCoefficients& coeff2) + { + EXPECT_NEAR(abs(coeff1.t_r(0)), abs(coeff2.t_r(0)), 1e-14); EXPECT_NEAR(coeff1.t_r(0).real(), coeff2.t_r(0).real(), 1e-10); EXPECT_NEAR(coeff1.t_r(0).imag(), coeff2.t_r(0).imag(), 1e-10); - EXPECT_NEAR(abs(coeff1.t_r(1)), abs(coeff2.t_r(1)), 1e-14); + EXPECT_NEAR(abs(coeff1.t_r(1)), abs(coeff2.t_r(1)), 1e-14); EXPECT_NEAR(coeff1.t_r(1).real(), coeff2.t_r(1).real(), 1e-10); EXPECT_NEAR(coeff1.t_r(1).imag(), coeff2.t_r(1).imag(), 1e-10); } @@ -35,26 +34,27 @@ protected: const Material amat = HomogeneousMaterial("material A", 2e-6, 8e-7); const Material bmat = HomogeneousMaterial("material B (high absorption)", 3e-5, 2e-4); const Material stone = HomogeneousMaterial("substrate material", 1e-6, 1e-7); - const Layer topLayer {air, 0}; - const Layer substrate {stone, 0}; - const kvector_t k { 1, 0, 1e-3 }; + const Layer topLayer{air, 0}; + const Layer substrate{stone, 0}; + const kvector_t k{1, 0, 1e-3}; MultiLayer sample1, sample2; std::vector<ScalarRTCoefficients> coeffs1, coeffs2; }; +RTTest::~RTTest() = default; TEST_F(RTTest, SplitLayer) { const int n = 40; - sample1.addLayer( topLayer ); - sample1.addLayer( Layer(amat, n*10) ); - sample1.addLayer( substrate ); + sample1.addLayer(topLayer); + sample1.addLayer(Layer(amat, n * 10)); + sample1.addLayer(substrate); - sample2.addLayer( topLayer ); - for (size_t i=0; i<n; ++i) - sample2.addLayer( Layer(amat, 10) ); - sample2.addLayer( substrate ); + sample2.addLayer(topLayer); + for (size_t i = 0; i < n; ++i) + sample2.addLayer(Layer(amat, 10)); + sample2.addLayer(substrate); SpecularMatrix::execute(sample1, k, coeffs1); SpecularMatrix::execute(sample2, k, coeffs2); @@ -67,28 +67,27 @@ TEST_F(RTTest, SplitLayer) compareCoeffs(coeffs1.back(), coeffs2.back()); } - TEST_F(RTTest, SplitBilayers) { // With exaggerated values of #layers, layer thickness, and absorption // so that we also test correct handling of floating-point overflow. const int n = 200; - sample1.addLayer( topLayer ); - for (size_t i=0; i<n; ++i) { - sample1.addLayer( Layer(amat, 100) ); - sample1.addLayer( Layer(bmat, 200) ); + sample1.addLayer(topLayer); + for (size_t i = 0; i < n; ++i) { + sample1.addLayer(Layer(amat, 100)); + sample1.addLayer(Layer(bmat, 200)); } - sample1.addLayer( substrate ); - - sample2.addLayer( topLayer ); - for (size_t i=0; i<n; ++i) { - sample2.addLayer( Layer(amat, 100) ); - sample2.addLayer( Layer(bmat, 100) ); - sample2.addLayer( Layer(amat, 0) ); - sample2.addLayer( Layer(bmat, 100) ); + sample1.addLayer(substrate); + + sample2.addLayer(topLayer); + for (size_t i = 0; i < n; ++i) { + sample2.addLayer(Layer(amat, 100)); + sample2.addLayer(Layer(bmat, 100)); + sample2.addLayer(Layer(amat, 0)); + sample2.addLayer(Layer(bmat, 100)); } - sample2.addLayer( substrate ); + sample2.addLayer(substrate); SpecularMatrix::execute(sample1, k, coeffs1); SpecularMatrix::execute(sample2, k, coeffs2); @@ -100,8 +99,8 @@ TEST_F(RTTest, SplitBilayers) compareCoeffs(coeffs1[1], coeffs2[1]); // If floating-point overflow is handled correctly, amplitudes at bottom must be strictly zero. - EXPECT_EQ(complex_t(), coeffs1[coeffs1.size()-2].t_r(0)); - EXPECT_EQ(complex_t(), coeffs1[coeffs1.size()-2].t_r(1)); - EXPECT_EQ(complex_t(), coeffs2[coeffs2.size()-2].t_r(0)); - EXPECT_EQ(complex_t(), coeffs2[coeffs2.size()-2].t_r(1)); + EXPECT_EQ(complex_t(), coeffs1[coeffs1.size() - 2].t_r(0)); + EXPECT_EQ(complex_t(), coeffs1[coeffs1.size() - 2].t_r(1)); + EXPECT_EQ(complex_t(), coeffs2[coeffs2.size() - 2].t_r(0)); + EXPECT_EQ(complex_t(), coeffs2[coeffs2.size() - 2].t_r(1)); } diff --git a/Tests/UnitTests/Fit/FitKernel/AttLimitsTest.h b/Tests/UnitTests/Fit/FitKernel/AttLimitsTest.h index 175e60a5d98..2da2395d0ee 100644 --- a/Tests/UnitTests/Fit/FitKernel/AttLimitsTest.h +++ b/Tests/UnitTests/Fit/FitKernel/AttLimitsTest.h @@ -1,5 +1,5 @@ +#include "google_test.h" #include "AttLimits.h" -#include "gtest/gtest.h" class AttLimitsTest : public ::testing::Test { diff --git a/Tests/UnitTests/Fit/FitKernel/FitObjectTest.h b/Tests/UnitTests/Fit/FitKernel/FitObjectTest.h index 5cf03ed91da..6fecbd447b3 100644 --- a/Tests/UnitTests/Fit/FitKernel/FitObjectTest.h +++ b/Tests/UnitTests/Fit/FitKernel/FitObjectTest.h @@ -1,9 +1,9 @@ +#include "google_test.h" #include "FitObject.h" #include "GISASSimulation.h" #include "BornAgainNamespace.h" #include "Units.h" #include <iostream> -#include "gtest/gtest.h" class FitObjectTest : public ::testing::Test diff --git a/Tests/UnitTests/Fit/FitKernel/FitParameterSetTest.h b/Tests/UnitTests/Fit/FitKernel/FitParameterSetTest.h index 04101905cc5..5b4de970b71 100644 --- a/Tests/UnitTests/Fit/FitKernel/FitParameterSetTest.h +++ b/Tests/UnitTests/Fit/FitKernel/FitParameterSetTest.h @@ -1,6 +1,6 @@ +#include "google_test.h" #include "IFitParameter.h" #include "FitParameterSet.h" -#include "gtest/gtest.h" class FitParameterSetTest : public ::testing::Test { diff --git a/Tests/UnitTests/Fit/FitKernel/FitParameterTest.h b/Tests/UnitTests/Fit/FitKernel/FitParameterTest.h index f6fccefc031..f485ecd91cd 100644 --- a/Tests/UnitTests/Fit/FitKernel/FitParameterTest.h +++ b/Tests/UnitTests/Fit/FitKernel/FitParameterTest.h @@ -1,9 +1,9 @@ +#include "google_test.h" #include "IParameterized.h" #include "RealParameter.h" #include "ParameterPool.h" #include "FitParameter.h" #include <string> -#include "gtest/gtest.h" class FitParameterTest : public ::testing::Test { diff --git a/Tests/UnitTests/Fit/FitKernel/FitSuiteTest.h b/Tests/UnitTests/Fit/FitKernel/FitSuiteTest.h index b11dad2e71e..ff732a6f65b 100644 --- a/Tests/UnitTests/Fit/FitKernel/FitSuiteTest.h +++ b/Tests/UnitTests/Fit/FitKernel/FitSuiteTest.h @@ -1,15 +1,17 @@ +#include "google_test.h" #include "FitSuite.h" #include "IFitParameter.h" -#include "gtest/gtest.h" #include <memory> class FitSuiteTest : public ::testing::Test { protected: FitSuiteTest(){} - virtual ~FitSuiteTest(){} + ~FitSuiteTest(); }; +FitSuiteTest::~FitSuiteTest() = default; + TEST_F(FitSuiteTest, addFitParameter) { std::unique_ptr<FitSuite> fitSuite(new FitSuite); diff --git a/Tests/UnitTests/Fit/FitKernel/IFitParameterTest.h b/Tests/UnitTests/Fit/FitKernel/IFitParameterTest.h index be55114abc5..ce4305f1aba 100644 --- a/Tests/UnitTests/Fit/FitKernel/IFitParameterTest.h +++ b/Tests/UnitTests/Fit/FitKernel/IFitParameterTest.h @@ -1,5 +1,5 @@ +#include "google_test.h" #include "IFitParameter.h" -#include "gtest/gtest.h" #include <memory> class IFitParameterTest : public ::testing::Test diff --git a/Tests/UnitTests/Fit/FitKernel/MinimizerOptionsTest.h b/Tests/UnitTests/Fit/FitKernel/MinimizerOptionsTest.h index 21ae3ae8135..f76c7f120ca 100644 --- a/Tests/UnitTests/Fit/FitKernel/MinimizerOptionsTest.h +++ b/Tests/UnitTests/Fit/FitKernel/MinimizerOptionsTest.h @@ -1,5 +1,5 @@ +#include "google_test.h" #include "MinimizerOptions.h" -#include "gtest/gtest.h" #include <exception> class MinimizerOptionsTest : public ::testing::Test { diff --git a/Tests/UnitTests/Fit/FitKernel/MultiOptionTest.h b/Tests/UnitTests/Fit/FitKernel/MultiOptionTest.h index 3a344fdde7e..4eaf17c78b5 100644 --- a/Tests/UnitTests/Fit/FitKernel/MultiOptionTest.h +++ b/Tests/UnitTests/Fit/FitKernel/MultiOptionTest.h @@ -1,5 +1,5 @@ +#include "google_test.h" #include "MultiOption.h" -#include "gtest/gtest.h" #include <iostream> #include <string> diff --git a/Tests/UnitTests/Fit/FitKernel/OptionContainerTest.h b/Tests/UnitTests/Fit/FitKernel/OptionContainerTest.h index 3541b4d669c..83b0362af6e 100644 --- a/Tests/UnitTests/Fit/FitKernel/OptionContainerTest.h +++ b/Tests/UnitTests/Fit/FitKernel/OptionContainerTest.h @@ -1,5 +1,5 @@ +#include "google_test.h" #include "OptionContainer.h" -#include "gtest/gtest.h" #include <exception> class OptionContainerTest : public ::testing::Test { diff --git a/Tests/UnitTests/Fit/FitKernel/RealLimitsTest.h b/Tests/UnitTests/Fit/FitKernel/RealLimitsTest.h index 79dde2334e6..844130f3f5b 100644 --- a/Tests/UnitTests/Fit/FitKernel/RealLimitsTest.h +++ b/Tests/UnitTests/Fit/FitKernel/RealLimitsTest.h @@ -1,3 +1,4 @@ +#include "google_test.h" #include "RealLimits.h" #include <limits> diff --git a/Tests/UnitTests/Fit/FitKernel/StringUtilsTest.h b/Tests/UnitTests/Fit/FitKernel/StringUtilsTest.h index 1ead9751ac5..3560649fd08 100644 --- a/Tests/UnitTests/Fit/FitKernel/StringUtilsTest.h +++ b/Tests/UnitTests/Fit/FitKernel/StringUtilsTest.h @@ -1,3 +1,4 @@ +#include "google_test.h" #include "StringUtils.h" -- GitLab