From e239950eafc68504c2f3af45ae5ff0090cecdfcd Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Thu, 27 May 2021 09:30:43 +0200
Subject: [PATCH] coverage

---
 .gitlab-ci.yml                                   |  4 ++--
 corsika/detail/framework/utility/CorsikaData.inl |  4 ++--
 corsika/detail/modules/ParticleCut.inl           |  5 +----
 modules/qgsjetII/qgsjet-II-04.cpp                |  4 ++--
 tests/modules/testObservationPlane.cpp           |  8 +++++---
 tests/modules/testStackInspector.cpp             |  4 ++++
 tests/stack/testGeometryNodeStackExtension.cpp   |  3 +--
 tests/stack/testHistoryStack.cpp                 | 13 +++++++++++--
 tests/stack/testNuclearStackExtension.cpp        |  9 +++++++++
 9 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fe2865b43..746c78c9a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -304,7 +304,7 @@ build_test-clang-8:
     - cd build_examples
     - cmake ../install/share/corsika/examples
     - make -j4
-    - make -j4 run_examples | gzip -v -9 > examples.log.gz
+    - make run_examples | gzip -v -9 > examples.log.gz
   rules:
     - if: '$CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_TITLE =~ /^Draft:/'
       when: manual
@@ -421,7 +421,7 @@ install-clang-8:
     - cd build_examples
     - cmake ../install/share/corsika/examples
     - make -j4
-    - make -j4 run_examples | gzip -v -9 > examples.log.gz
+    - make run_examples | gzip -v -9 > examples.log.gz
   rules:
     - if: '$CI_MERGE_REQUEST_LABELS =~ /Ready for code review/' # run on merge requests, if label 'Ready for code review' is set
     - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
diff --git a/corsika/detail/framework/utility/CorsikaData.inl b/corsika/detail/framework/utility/CorsikaData.inl
index fc638b81a..c3a82ad11 100644
--- a/corsika/detail/framework/utility/CorsikaData.inl
+++ b/corsika/detail/framework/utility/CorsikaData.inl
@@ -16,7 +16,7 @@
 inline boost::filesystem::path corsika::corsika_data(boost::filesystem::path const& key) {
   if (auto const* p = std::getenv("CORSIKA_DATA"); p != nullptr) {
     return boost::filesystem::path(p) / key;
-  } else {
+  } else { // LCOV_EXCL_START, this cannot be easily tested system-independently
     throw std::runtime_error("CORSIKA_DATA not set");
-  }
+  } // LCOV_EXCL_STOP
 }
diff --git a/corsika/detail/modules/ParticleCut.inl b/corsika/detail/modules/ParticleCut.inl
index 9fc69b4a9..a5c6dceda 100644
--- a/corsika/detail/modules/ParticleCut.inl
+++ b/corsika/detail/modules/ParticleCut.inl
@@ -25,7 +25,7 @@ namespace corsika {
       , em_count_(0)
       , inv_count_(0) {
     for (auto p : get_all_particles())
-      if (is_hadron(p))
+      if (is_hadron(p)) // nuclei are also hadrons
         set_kinetic_energy_threshold(p, eHadCut);
       else if (is_muon(p))
         set_kinetic_energy_threshold(p, eMuCut);
@@ -33,9 +33,6 @@ namespace corsika {
         set_kinetic_energy_threshold(p, eEleCut);
       else if (p == Code::Photon)
         set_kinetic_energy_threshold(p, ePhoCut);
-      else if (p == Code::Nucleus)
-        // nuclei have same threshold as hadrons on the nucleon level.
-        set_kinetic_energy_threshold(p, eHadCut);
     CORSIKA_LOG_DEBUG(
         "setting kinetic energy thresholds: electrons = {} GeV, photons = {} GeV, "
         "hadrons = {} GeV, "
diff --git a/modules/qgsjetII/qgsjet-II-04.cpp b/modules/qgsjetII/qgsjet-II-04.cpp
index 8ffd24df4..550091632 100644
--- a/modules/qgsjetII/qgsjet-II-04.cpp
+++ b/modules/qgsjetII/qgsjet-II-04.cpp
@@ -3,10 +3,10 @@
 #include <iostream>
 
 datadir::datadir(std::string const& dir) {
-  if (dir.length() > 130) {
+  if (dir.length() > 130) { // LCOV_EXCL_START since we can't test this error message
     std::cerr << "QGSJetII error, will cut datadir \"" << dir
               << "\" to 130 characters: " << std::endl;
-  }
+  } // LCOV_EXCL_STOP
   int i = 0;
   for (i = 0; i < std::min(130, int(dir.length())); ++i) data[i] = dir[i];
   data[i + 0] = ' ';
diff --git a/tests/modules/testObservationPlane.cpp b/tests/modules/testObservationPlane.cpp
index e6fd80ee5..1ed62d524 100644
--- a/tests/modules/testObservationPlane.cpp
+++ b/tests/modules/testObservationPlane.cpp
@@ -28,7 +28,7 @@ using namespace corsika;
 
 TEST_CASE("ObservationPlane", "interface") {
 
-  logging::set_level(logging::level::trace);
+  logging::set_level(logging::level::info);
 
   auto [env, csPtr, nodePtr] = setup::testing::setup_environment(Code::Oxygen);
   auto const& cs = *csPtr;
@@ -48,7 +48,7 @@ TEST_CASE("ObservationPlane", "interface") {
 
   // dummy track. Not used for calculation!
   Point const start(cs, {0_m, 1_m, 10_m});
-  VelocityVector vec(cs, 0_m / second, 0_m / second, -constants::c);
+  VelocityVector vec(cs, constants::c, 0_m / second, 0_m / second);
   Line line(start, vec);
   setup::Trajectory no_used_track =
       setup::testing::make_track<setup::Trajectory>(line, 12_m / constants::c);
@@ -75,7 +75,7 @@ TEST_CASE("ObservationPlane", "interface") {
 
     // particle past plane:
     {
-      particle.setPosition({cs, {0_m, 0_m, -1_m}});
+      particle.setPosition({cs, {11_m, 0_m, -1_m}});
       setup::Trajectory no_hit_track =
           setup::testing::make_track<setup::Trajectory>(line, 1_nm / constants::c);
       LengthType const no_hit = obs.getMaxStepLength(particle, no_hit_track);
@@ -90,9 +90,11 @@ TEST_CASE("ObservationPlane", "interface") {
 
     LengthType const length = obs.getMaxStepLength(particle, no_used_track);
     ProcessReturn const ret = obs.doContinuous(particle, no_used_track, false);
+    ProcessReturn const ret2 = obs.doContinuous(particle, no_used_track, true);
 
     CHECK(length / 1_m == Approx(1).margin(1e-4));
     CHECK(ret == ProcessReturn::Ok);
+    CHECK(ret2 == ProcessReturn::Ok);
   }
 
   SECTION("inclined plane, inclined particle") {
diff --git a/tests/modules/testStackInspector.cpp b/tests/modules/testStackInspector.cpp
index f4675a09c..9464e54a5 100644
--- a/tests/modules/testStackInspector.cpp
+++ b/tests/modules/testStackInspector.cpp
@@ -38,10 +38,14 @@ TEST_CASE("StackInspector", "modules") {
   stack.addParticle(std::make_tuple(Code::Electron,
                                     MomentumVector(rootCS, {0_GeV, 0_GeV, -1_GeV}),
                                     Point(rootCS, {0_m, 0_m, 10_km}), 0_ns));
+  stack.addParticle(std::make_tuple(Code::Nucleus,
+                                    MomentumVector(rootCS, {0_GeV, 0_GeV, -1_GeV}),
+                                    Point(rootCS, {0_m, 0_m, 10_km}), 0_ns, 16, 8));
 
   SECTION("interface") {
 
     StackInspector<TestCascadeStack> model(1, true, E0);
     model.doStack(stack);
+    // there are no actions, nothing to check...
   }
 }
diff --git a/tests/stack/testGeometryNodeStackExtension.cpp b/tests/stack/testGeometryNodeStackExtension.cpp
index e0673f3c3..9cc29edcc 100644
--- a/tests/stack/testGeometryNodeStackExtension.cpp
+++ b/tests/stack/testGeometryNodeStackExtension.cpp
@@ -37,10 +37,9 @@ using StackWithGeometryInterface =
 using TestStack = CombinedStack<typename dummy_stack::DummyStack::stack_data_type,
                                 node::GeometryData<DummyEnv>, StackWithGeometryInterface>;
 
-TEST_CASE("GeometryNodeStackExtension", "[stack]") {
+TEST_CASE("GeometryNodeStackExtension", "stack") {
 
   logging::set_level(logging::level::info);
-  corsika_logger->set_pattern("[%n:%^%-8l%$] custom pattern: %v");
 
   dummy_stack::NoData noData;
 
diff --git a/tests/stack/testHistoryStack.cpp b/tests/stack/testHistoryStack.cpp
index 485b794a5..4542db2eb 100644
--- a/tests/stack/testHistoryStack.cpp
+++ b/tests/stack/testHistoryStack.cpp
@@ -46,10 +46,9 @@ using TestStack =
 
 using EvtPtr = std::shared_ptr<DummyEvent>;
 
-TEST_CASE("HistoryStackExtension", "[stack]") {
+TEST_CASE("HistoryStackExtension", "stack") {
 
   logging::set_level(logging::level::info);
-  corsika_logger->set_pattern("[%n:%^%-8l%$] custom pattern: %v");
 
   [[maybe_unused]] CoordinateSystemPtr const& dummyCS = get_root_CoordinateSystem();
 
@@ -64,4 +63,14 @@ TEST_CASE("HistoryStackExtension", "[stack]") {
     EvtPtr evt = p.getEvent();
     CHECK(evt == nullptr);
   }
+
+  SECTION("add and remove particles") {
+
+    auto p = s.addParticle(std::tuple<dummy_stack::NoData>{noData});
+    CHECK(s.getEntries() == 2);
+    p.erase();
+    CHECK(s.getEntries() == 1);
+    s.purge();
+    CHECK(s.getEntries() == 1);
+  }
 }
diff --git a/tests/stack/testNuclearStackExtension.cpp b/tests/stack/testNuclearStackExtension.cpp
index fa9201023..198fe7da9 100644
--- a/tests/stack/testNuclearStackExtension.cpp
+++ b/tests/stack/testNuclearStackExtension.cpp
@@ -227,6 +227,15 @@ TEST_CASE("NuclearStackExtension", "stack") {
                                          nuclear_stack::ExtendedParticleInterfaceType>
         s;
 
+    // not valid, no A,Z:
+    // not valid, no A,Z:
+    CHECK_THROWS(s.addParticle(
+        std::make_tuple(Code::Nucleus, 100_GeV, DirectionVector(dummyCS, {1, 0, 0}),
+                        Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s)));
+    CHECK_THROWS(s.addParticle(
+        std::make_tuple(Code::Nucleus, MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}),
+                        Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s)));
+
     // not valid:
     CHECK_THROWS(s.addParticle(std::make_tuple(
         Code::Oxygen, MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}),
-- 
GitLab