diff --git a/Stack/SuperStupidStack/CMakeLists.txt b/Stack/SuperStupidStack/CMakeLists.txt index 1e789386a3febf8c67d33578be0bb18cea938505..b9634f1d1bc523089dd4e90cb7caeaefe024480c 100644 --- a/Stack/SuperStupidStack/CMakeLists.txt +++ b/Stack/SuperStupidStack/CMakeLists.txt @@ -28,3 +28,24 @@ install ( DESTINATION include/${SuperStupidStack_NAMESPACE} ) + +# ---------------- +# code unit testing +add_executable ( + testSuperStupidStack + testSuperStupidStack.cc + ) + +target_link_libraries ( + testSuperStupidStack +# CORSIKAutls + ProcessStackInspector + CORSIKAgeometry + CORSIKAunits + CORSIKAthirdparty # for catch2 + ) + +add_test ( + NAME testSuperStupidStack + COMMAND testSuperStupidStack + ) diff --git a/Stack/SuperStupidStack/SuperStupidStack.h b/Stack/SuperStupidStack/SuperStupidStack.h index 8caa6cc77d25a14a48293ff53d793ef1f3ce2a86..816a8c5ba6dd662c99b464405cf4ce6178c7c58c 100644 --- a/Stack/SuperStupidStack/SuperStupidStack.h +++ b/Stack/SuperStupidStack/SuperStupidStack.h @@ -36,16 +36,17 @@ namespace corsika::stack { using corsika::units::si::energy_d; using corsika::geometry::Point; using corsika::geometry::Vector; - - typedef Vector<energy_d> MomentumVector; - + +#warning replace this with a proper momentum vector: + typedef Vector<energy_d> MomentumVector; // should be momentum_d !!! + /** * Example of a particle object on the stack. */ template <typename StackIteratorInterface> - class ParticleInterface : public ParticleBase<StackIteratorInterface> { - + class ParticleInterface : public ParticleBase<StackIteratorInterface> { + using ParticleBase<StackIteratorInterface>::GetStackData; using ParticleBase<StackIteratorInterface>::GetIndex; @@ -89,9 +90,9 @@ namespace corsika::stack { Code GetPID(const int i) const { return fDataPID[i]; } EnergyType GetEnergy(const int i) const { return fDataE[i]; } - MomentumVector GetMomentum(const int i) { return fMomentum[i]; } - Point GetPosition(const int i) { return fPosition[i]; } - TimeType GetTime(const int i) { return fTime[i]; } + MomentumVector GetMomentum(const int i) const { return fMomentum[i]; } + Point GetPosition(const int i) const { return fPosition[i]; } + TimeType GetTime(const int i) const { return fTime[i]; } /** * Function to copy particle at location i2 in stack to i1 diff --git a/Stack/SuperStupidStack/testSuperStupidStack.cc b/Stack/SuperStupidStack/testSuperStupidStack.cc new file mode 100644 index 0000000000000000000000000000000000000000..93f0a095a5a258653a73ca5e6de46a5526720f8a --- /dev/null +++ b/Stack/SuperStupidStack/testSuperStupidStack.cc @@ -0,0 +1,68 @@ + +/** + * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu + * + * See file AUTHORS for a list of contributors. + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#include <corsika/stack/super_stupid/SuperStupidStack.h> +#include <corsika/units/PhysicalUnits.h> + +using namespace corsika::geometry; +using namespace corsika::units::si; + +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one + // cpp file +#include <catch2/catch.hpp> + +using namespace corsika; +using namespace corsika::stack::super_stupid; + + +#include <iostream> +using namespace std; + + +TEST_CASE("SuperStupidStack", "[stack]") { + + SECTION("read+write") { + + SuperStupidStack s; + auto p = s.NewParticle(); + p.SetPID(corsika::particles::Code::Electron); + p.SetEnergy(1.5_GeV); + auto const dummyCS = corsika::geometry::CoordinateSystem::CreateRootCS(); + p.SetMomentum(MomentumVector(dummyCS, {1 * joule, 1 * joule, 1 * joule})); + p.SetPosition(Point(dummyCS, {1 * meter, 1 * meter, 1 * meter})); + p.SetTime(100_s); + + // read + REQUIRE(s.GetSize() == 1); + auto pout = s.GetNextParticle(); + REQUIRE(pout.GetPID() == corsika::particles::Code::Electron); + REQUIRE(pout.GetEnergy() == 1.5_GeV); +#warning Fix the next two lines: + //REQUIRE(pout.GetMomentum() == MomentumVector(dummyCS, {1 * joule, 1 * joule, 1 * joule})); + //REQUIRE(pout.GetPosition() == Point(dummyCS, {1 * meter, 1 * meter, 1 * meter})); + REQUIRE(pout.GetTime() == 100_s); + } + + SECTION("write+delete") { + + SuperStupidStack s; + for (int i=0; i<99; ++i) + s.NewParticle(); + + REQUIRE(s.GetSize() == 99); + + for (int i=0; i<99; ++i) + s.GetNextParticle().Delete(); + + + REQUIRE(s.GetSize() == 0); + } +}