From c9b72fb68a6813c78229bafc8b2ead1fe112995b Mon Sep 17 00:00:00 2001 From: ralfulrich <ralf.ulrich@kit.edu> Date: Fri, 7 May 2021 08:31:13 +0200 Subject: [PATCH] coverage --- .../framework/utility/QuarticSolver.inl | 3 +- tests/framework/testProcessSequence.cpp | 61 +++++++++++++++---- tests/framework/testSolver.cpp | 7 ++- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/corsika/detail/framework/utility/QuarticSolver.inl b/corsika/detail/framework/utility/QuarticSolver.inl index 988bbe80b..4562b39c0 100644 --- a/corsika/detail/framework/utility/QuarticSolver.inl +++ b/corsika/detail/framework/utility/QuarticSolver.inl @@ -32,7 +32,7 @@ namespace corsika { long double c3 = -b * b * e - d * d + 4. * c * e; // cubic resolvent - // y^3 − b*y^2 + (ac−4d)*y − a^2*d−c^2+4*b*d = 0 + // y^3 − c*y^2 + (bd−4e)*y − b^2*e−d^2+4*c*e = 0 std::vector<double> x3 = solve_cubic_real(1, a3, b3, c3, epsilon); long double y = x3[0]; // there is always at least one solution @@ -52,6 +52,7 @@ namespace corsika { q1 = q2 = y * 0.5; // g1+g2 = b && g1+g2 = c-y <=> g^2 - b*g + c-y = 0 (p === g) Det = b * b - 4 * (c - y); + CORSIKA_LOG_TRACE("Det={}", Det); if (fabs(Det) < epsilon) { // in other words - D==0 p1 = p2 = b * 0.5; } else { diff --git a/tests/framework/testProcessSequence.cpp b/tests/framework/testProcessSequence.cpp index 02105eb9e..1335974cd 100644 --- a/tests/framework/testProcessSequence.cpp +++ b/tests/framework/testProcessSequence.cpp @@ -62,10 +62,11 @@ struct DummyView { int globalCount = 0; // simple counter -int checkDecay = 0; // use this as a bit field -int checkInteract = 0; // use this as a bit field -int checkSec = 0; // use this as a bit field -int checkCont = 0; // use this as a bit field +int checkDecay = 0; // use this as a bit field +int checkInteract = 0; // use this as a bit field +int checkSec = 0; // use this as a bit field +int checkCont = 0; // use this as a bit field +int checkSecondaries = 0; // use this as a bit field class ContinuousProcess1 : public ContinuousProcess<ContinuousProcess1> { public: @@ -332,6 +333,22 @@ private: int count_ = 0; }; +class Secondaries1 : public SecondariesProcess<Secondaries1> { +public: + template <typename TView> + void doSecondaries(TView const&) { + checkSecondaries |= 1; + } +}; + +class Secondaries2 : public SecondariesProcess<Secondaries2> { +public: + template <typename TView> + void doSecondaries(TView const&) { + checkSecondaries |= 2; + } +}; + class Boundary1 : public BoundaryCrossingProcess<Boundary1> { public: Boundary1(double const v = 1.0) @@ -580,7 +597,6 @@ TEST_CASE("ProcessSequence General", "ProcessSequence") { TEST_CASE("SwitchProcessSequence", "ProcessSequence") { logging::set_level(logging::level::info); - corsika_logger->set_pattern("[%n:%^%-8l%$]: %v"); /** * In this example switching is done only by "data_[0]>0", where @@ -596,8 +612,11 @@ TEST_CASE("SwitchProcessSequence", "ProcessSequence") { auto cp2 = ContinuousProcess2(0, 2_m); auto cp3 = ContinuousProcess3(0, 3_m); - auto sequence1 = make_sequence(Process1(0), cp2, Decay1(0), Boundary1(1.0)); - auto sequence2 = make_sequence(cp3, Process2(0), Boundary1(-1.0), Decay2(0)); + auto sec1 = Secondaries1(); + auto sec2 = Secondaries2(); + + auto sequence1 = make_sequence(Process1(0), cp2, Decay1(0), sec1, Boundary1(1.0)); + auto sequence2 = make_sequence(cp3, Process2(0), Boundary1(-1.0), Decay2(0), sec2); auto sequence3 = make_sequence(cp1, Process3(0), SwitchProcessSequence(select1, sequence1, sequence2)); @@ -650,7 +669,7 @@ TEST_CASE("SwitchProcessSequence", "ProcessSequence") { checkInteract = 0; checkSec = 0; checkCont = 0; - particle.data_[0] = 100; // data positive + particle.data_[0] = 100; // data positive --> sequence1 sequence3.doContinuous(particle, track, ContinuousProcessIndex(1)); CHECK(checkInteract == 0); CHECK(checkDecay == 0); @@ -661,7 +680,7 @@ TEST_CASE("SwitchProcessSequence", "ProcessSequence") { checkInteract = 0; checkSec = 0; checkCont = 0; - particle.data_[0] = -100; // data negative + particle.data_[0] = -100; // data negative --> sequence2 sequence3.doContinuous(particle, track, ContinuousProcessIndex(1)); CHECK(checkInteract == 0); CHECK(checkDecay == 0); @@ -676,7 +695,7 @@ TEST_CASE("SwitchProcessSequence", "ProcessSequence") { checkInteract = 0; checkSec = 0; checkCont = 0; - particle.data_[0] = 100; // data positive + particle.data_[0] = 100; // data positive --> sequence1 sequence3.selectInteraction(view, lambda_select); sequence3.selectDecay(view, time_select); CHECK(checkInteract == 0b100); // this is Process3 @@ -692,7 +711,7 @@ TEST_CASE("SwitchProcessSequence", "ProcessSequence") { checkInteract = 0; checkSec = 0; checkCont = 0; - particle.data_[0] = -100; // data negative + particle.data_[0] = -100; // data negative --> sequence2 sequence3.selectInteraction(view, lambda_select); sequence3.selectDecay(view, time_select); CHECK(checkInteract == 0b010); // this is Process2 @@ -704,7 +723,7 @@ TEST_CASE("SwitchProcessSequence", "ProcessSequence") { checkInteract = 0; checkSec = 0; checkCont = 0; - particle.data_[0] = -100; // data negative + particle.data_[0] = -100; // data negative --> sequence2 sequence3.doSecondaries(view); Stack1 stack(0); sequence3.doStack(stack); @@ -720,7 +739,7 @@ TEST_CASE("SwitchProcessSequence", "ProcessSequence") { checkInteract = 0; checkSec = 0; checkCont = 0; - particle.data_[0] = -100; // data positive + particle.data_[0] = -100; // data negative --> sequence1 sequence4.selectInteraction(view, lambda_select); sequence4.doSecondaries(view); sequence4.selectDecay(view, time_select); @@ -741,6 +760,22 @@ TEST_CASE("SwitchProcessSequence", "ProcessSequence") { CHECK(checkDecay == 0); } + SECTION("Check SecondariesProcesses in SwitchProcessSequence") { + + DummyData particle; + DummyView view(particle); + + checkSecondaries = 0; + particle.data_[0] = 100; // data positive --> sequence1 + sequence3.doSecondaries(view); + CHECK(checkSecondaries == 1); + + checkSecondaries = 0; + particle.data_[0] = -100; // data positive --> sequence1 + sequence3.doSecondaries(view); + CHECK(checkSecondaries == 2); + } + SECTION("Check ContinuousProcesses in SwitchProcessSequence") { DummyData particle; diff --git a/tests/framework/testSolver.cpp b/tests/framework/testSolver.cpp index 52f1fa13f..423b73b8b 100644 --- a/tests/framework/testSolver.cpp +++ b/tests/framework/testSolver.cpp @@ -53,7 +53,6 @@ TEST_CASE("Solver") { {7e8, -1e-7}}; for (auto v : vals) { - { double a = v.first; double b = v.second; @@ -74,7 +73,9 @@ TEST_CASE("Solver") { } CHECK(solve_linear_real(0, 55.).size() == 0); - } + CHECK(solve_linear(0, 55.).size() == 0); + + } // linear SECTION("quadratic") { @@ -129,7 +130,7 @@ TEST_CASE("Solver") { } } } - } + } // quadratic SECTION("cubic") { -- GitLab