diff --git a/GeoModelCore/GeoModelKernel/CMakeLists.txt b/GeoModelCore/GeoModelKernel/CMakeLists.txt index 94e322406819431dd468e9c514907d4d1832f92d..025a6a4a02506e4b199c42421d74b3c8992414bb 100644 --- a/GeoModelCore/GeoModelKernel/CMakeLists.txt +++ b/GeoModelCore/GeoModelKernel/CMakeLists.txt @@ -66,4 +66,5 @@ endforeach() include(GoogleTest) gtest_discover_tests(testRCBase) gtest_discover_tests(testGeoGraphNode) - +gtest_discover_tests(testGeoMaterial) +gtest_discover_tests(testGeoElement) diff --git a/GeoModelCore/GeoModelKernel/tests/testGeoElement.cxx b/GeoModelCore/GeoModelKernel/tests/testGeoElement.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0769a9cb928ec7a3aa2f35b96c4c1c8a4de8dc7b --- /dev/null +++ b/GeoModelCore/GeoModelKernel/tests/testGeoElement.cxx @@ -0,0 +1,94 @@ +/* + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration +*/ + + +#include "GeoModelKernel/GeoElement.h" +#include <gtest/gtest.h> + +class SampleElement{ + private: + const std::string m_name{"Rhodium"}; + const std::string m_symbol{"Rh"}; + const double m_Z{45.}; + const double m_A{102.90549*GeoModelKernelUnits::gram/GeoModelKernelUnits::mole}; + GeoElement * m_ptr{}; + public: + GeoElement * ptr() const {return m_ptr;} + SampleElement():m_ptr(new GeoElement(m_name, m_symbol, m_Z, m_A)){ + m_ptr->ref(); + } + ~SampleElement(){m_ptr->unref();} +}; + + +TEST(GeoElement, CanBeConstructedOnHeap) { + GeoElement * pG{}; + const std::string name{"Rhodium"}; + const std::string symbol{"Rh"}; + const double Z{45.}; + const double A{102.90549}; + EXPECT_NO_THROW(pG = new GeoElement(name, symbol, Z, A)); + pG->ref(); + pG->unref(); //should be destroyed here +} + +TEST(GeoElement,CalculatesNCorrectly){ + SampleElement rhodium; + const auto p = rhodium.ptr(); + EXPECT_EQ(p->getN(), 102.90549); +} + +TEST(GeoElement,GivesCorrectName){ + SampleElement rhodium; + const auto p = rhodium.ptr(); + EXPECT_EQ(p->getName(),"Rhodium"); +} + +TEST(GeoElement,GivesCorrectSymbol){ + SampleElement rhodium; + const auto p = rhodium.ptr(); + EXPECT_EQ(p->getSymbol(),"Rh"); +} + +TEST(GeoElement,GivesCorrectZValue){ + SampleElement rhodium; + const auto p = rhodium.ptr(); + EXPECT_EQ(p->getZ(),45); +} +TEST(GeoElement,GivesCorrectAverageAtomicMass){ + SampleElement rhodium; + const auto p = rhodium.ptr(); + EXPECT_EQ(p->getA(),102.90549*GeoModelKernelUnits::gram/GeoModelKernelUnits::mole); +} + +TEST(GeoElement,GivesCorrectRadiationLength){ + SampleElement rhodium; + const auto p = rhodium.ptr(); + EXPECT_EQ(p->getRadTsai(),1.8442455962801794e-21); +} + +TEST(GeoElement,EqualityOperator){ + const std::string name{"Rhodium"}; + const std::string symbol{"Rh"}; + const double Z{45.}; + const double A{102.90549*GeoModelKernelUnits::gram/GeoModelKernelUnits::mole}; + auto pG = new GeoElement(name, symbol, Z, A); + SampleElement rhodium; + ASSERT_TRUE(*pG == *(rhodium.ptr())); +} + +TEST(GeoElement,InequalityOperator){ + const std::string name{"Rhodium"}; + const std::string symbol{"Rh"}; + const double Z{45.}; + //alter A value _slightly_ + const double A{102.91*GeoModelKernelUnits::gram/GeoModelKernelUnits::mole}; + auto pG = new GeoElement(name, symbol, Z, A); + SampleElement rhodium; + ASSERT_TRUE(*pG != *(rhodium.ptr())); + pG->ref(); + pG->unref(); //should be destroyed here + +} + diff --git a/GeoModelCore/GeoModelKernel/tests/testGeoMaterial.cxx b/GeoModelCore/GeoModelKernel/tests/testGeoMaterial.cxx new file mode 100644 index 0000000000000000000000000000000000000000..48465566482bd483f55c597944c52504e51d4d29 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/tests/testGeoMaterial.cxx @@ -0,0 +1,17 @@ +/* + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration +*/ + + +#include "GeoModelKernel/GeoMaterial.h" +#include <gtest/gtest.h> + + +TEST(GeoMaterial, CanBeConstructedOnHeap) { + GeoMaterial * pG{}; + const std::string name{"Shaun"}; + const double dense{13.0}; + EXPECT_NO_THROW(pG = new GeoMaterial(name, dense));//Shaun is dense + pG->ref(); + pG->unref(); //should be destroyed here +}