LCOV - code coverage report
Current view: top level - test - testModuleList.cpp (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 94.5 % 55 52
Test Date: 2026-06-18 09:49:19 Functions: 85.7 % 7 6

            Line data    Source code
       1              : #include "crpropa/ModuleList.h"
       2              : #include "crpropa/Source.h"
       3              : #include "crpropa/ParticleID.h"
       4              : #include "crpropa/module/SimplePropagation.h"
       5              : #include "crpropa/module/BreakCondition.h"
       6              : 
       7              : #include "gtest/gtest.h"
       8              : 
       9              : namespace crpropa {
      10              : 
      11            1 : TEST(ModuleList, process) {
      12            1 :         ModuleList modules;
      13            1 :         modules.add(new SimplePropagation());
      14            1 :         ParticleState initial;
      15            1 :         ref_ptr<Candidate> candidate = new Candidate(initial);
      16            2 :         modules.process(candidate);
      17            1 : }
      18              : 
      19            1 : TEST(ModuleList, getModule) {
      20            1 :         ModuleList modules;
      21            1 :         ref_ptr<SimplePropagation> prop = new SimplePropagation();
      22            1 :         modules.add(prop);
      23            2 :         EXPECT_TRUE(modules[0] == prop);
      24            1 : }
      25              : 
      26            1 : TEST(ModuleList, removeModule) {
      27            1 :         ModuleList modules;
      28            1 :         ref_ptr<SimplePropagation> prop = new SimplePropagation();
      29            1 :         modules.add(prop);
      30            1 :         modules.remove(0);
      31            1 :         EXPECT_EQ(modules.size(), 0);
      32            1 : }
      33              : 
      34            1 : TEST(ModuleList, runCandidateList) {
      35            1 :         ModuleList modules;
      36            1 :         modules.add(new SimplePropagation());
      37            1 :         modules.add(new MaximumTrajectoryLength(1 * Mpc));
      38            1 :         ParticleState initial;
      39            1 :         ref_ptr<Candidate> candidate = new Candidate(initial);
      40            1 :         modules.run(candidate);
      41            1 :         EXPECT_DOUBLE_EQ(1 * Mpc, candidate->getTrajectoryLength());
      42            1 :         EXPECT_TRUE(candidate->isActive() == false);
      43            1 : }
      44              : 
      45            1 : TEST(ModuleList, runSource) {
      46            1 :         ModuleList modules;
      47            1 :         modules.add(new SimplePropagation());
      48            1 :         modules.add(new MaximumTrajectoryLength(1 * Mpc));
      49              :         Source source;
      50            1 :         source.add(new SourcePosition(Vector3d(10, 0, 0) * Mpc));
      51            1 :         source.add(new SourceIsotropicEmission());
      52            1 :         source.add(new SourcePowerLawSpectrum(5 * EeV, 100 * EeV, -2));
      53            1 :         source.add(new SourceParticleType(nucleusId(1, 1)));
      54            1 :         modules.setShowProgress(true);
      55            1 :         modules.run(&source, 100, false);
      56            1 : }
      57              : 
      58              : #if _OPENMP
      59              : #include <omp.h>
      60            1 : TEST(ModuleList, runOpenMP) {
      61            1 :         ModuleList modules;
      62            1 :         modules.add(new SimplePropagation());
      63            1 :         modules.add(new MaximumTrajectoryLength(1 * Mpc));
      64              :         Source source;
      65            1 :         source.add(new SourcePosition(Vector3d(10, 0, 0) * Mpc));
      66            1 :         source.add(new SourceIsotropicEmission());
      67            1 :         source.add(new SourcePowerLawSpectrum(5 * EeV, 100 * EeV, -2));
      68            1 :         source.add(new SourceParticleType(nucleusId(1, 1)));
      69            1 :         omp_set_num_threads(2);
      70            1 :         modules.run(&source, 1000, false);
      71            1 : }
      72              : #endif
      73              : 
      74            0 : int main(int argc, char **argv) {
      75            0 :         ::testing::InitGoogleTest(&argc, argv);
      76            0 :         return RUN_ALL_TESTS();
      77              : }
      78              : 
      79              : } // namespace crpropa
        

Generated by: LCOV version 2.0-1