IAP GITLAB

Skip to content
Snippets Groups Projects
Commit f72bd59f authored by ralfulrich's avatar ralfulrich
Browse files

better unit tests

parent 7de91386
No related branches found
No related tags found
1 merge request!269Resolve "Distinguish between alternative interaction processes and competing processes"
......@@ -65,7 +65,7 @@ public:
inline EProcessReturn DoContinuous(D& d, T&) const {
cout << "ContinuousProcess2::DoContinuous" << endl;
checkCont |= 2;
for (int i = 0; i < nData; ++i) d.data_[i] += 0.933;
for (int i = 0; i < nData; ++i) d.data_[i] += 0.111;
return EProcessReturn::eOk;
}
};
......@@ -84,7 +84,7 @@ public:
inline EProcessReturn DoContinuous(D& d, T&) const {
cout << "ContinuousProcess3::DoContinuous" << endl;
checkCont |= 4;
for (int i = 0; i < nData; ++i) d.data_[i] += 0.933;
for (int i = 0; i < nData; ++i) d.data_[i] += 0.333;
return EProcessReturn::eOk;
}
};
......@@ -124,8 +124,9 @@ public:
}
template <typename TView>
inline EProcessReturn DoInteraction(TView&) const {
inline EProcessReturn DoInteraction(TView& v) const {
checkInteract |= 2;
for (int i = 0; i < nData; ++i) v.parent().data_[i] /= 1.1;
cout << "Process2::DoInteraction" << endl;
return EProcessReturn::eOk;
}
......@@ -147,8 +148,9 @@ public:
}
template <typename TView>
inline EProcessReturn DoInteraction(TView&) const {
inline EProcessReturn DoInteraction(TView& v) const {
checkInteract |= 4;
for (int i = 0; i < nData; ++i) v.parent().data_[i] *= 1.01;
cout << "Process3::DoInteraction" << endl;
return EProcessReturn::eOk;
}
......@@ -284,6 +286,9 @@ TEST_CASE("Process Sequence", "[Process Sequence]") {
GrammageType const tot = sequence2.GetInteractionLength(particle);
InverseGrammageType const tot_inv = sequence2.GetInverseInteractionLength(particle);
cout << "lambda_tot=" << tot << "; lambda_tot_inv=" << tot_inv << endl;
CHECK(tot/1_g*square(1_cm) == 12);
CHECK(tot_inv*1_g/square(1_cm) == 1./12);
globalCount = 0;
}
......@@ -301,15 +306,17 @@ TEST_CASE("Process Sequence", "[Process Sequence]") {
InverseTimeType const tot_inv = sequence2.GetInverseLifetime(particle);
cout << "lambda_tot=" << tot << "; lambda_tot_inv=" << tot_inv << endl;
CHECK(tot/1_s == 1);
CHECK(tot_inv*1_s == 1.);
globalCount = 0;
}
SECTION("sectionTwo") {
globalCount = 0;
ContinuousProcess1 cp1(0);
ContinuousProcess2 cp2(1);
Process2 m2(2);
Process3 m3(3);
ContinuousProcess1 cp1(0); // += 0.933
ContinuousProcess2 cp2(1); // += 0.111
Process2 m2(2); // /= 1.1
Process3 m3(3); // *= 1.01
auto sequence2 = sequence(cp1, m2, m3, cp2);
......@@ -320,15 +327,20 @@ TEST_CASE("Process Sequence", "[Process Sequence]") {
globalCount = 0;
cout << "-->docont" << endl;
sequence2.DoContinuous(particle, track);
cout << "-->dodisc" << endl;
cout << "-->done" << endl;
// validation data
double test_data[nData] = {0};
const int nLoop = 5;
cout << "Running loop with n=" << nLoop << endl;
for (int i = 0; i < nLoop; ++i) { sequence2.DoContinuous(particle, track); }
for (int iLoop = 0; iLoop < nLoop; ++iLoop) {
for (int i=0; i<nData; ++i) {
test_data[i] += 0.933 + 0.111;
}
sequence2.DoContinuous(particle, track);
}
for (int i = 0; i < nData; i++) {
cout << "data_[" << i << "]=" << particle.data_[i] << endl;
CHECK(particle.data_[i] == Approx(test_data[i]).margin(1e-9));
}
cout << "done" << endl;
}
......
......@@ -134,8 +134,8 @@ TEST_CASE("SwitchProcess from InteractionProcess") {
// low energy process returns 1 kg/m²
SECTION("interaction length") {
REQUIRE(switchProcess.GetInteractionLength(p) / kgMSq == Approx(1));
REQUIRE(seq.GetInteractionLength(p) / kgMSq == Approx(3. / 4));
CHECK(switchProcess.GetInteractionLength(p) / kgMSq == Approx(1));
CHECK(seq.GetInteractionLength(p) / kgMSq == Approx(3. / 4));
}
}
......@@ -145,8 +145,8 @@ TEST_CASE("SwitchProcess from InteractionProcess") {
// high energy process returns 2 kg/m²
SECTION("interaction length") {
REQUIRE(switchProcess.GetInteractionLength(p) / kgMSq == Approx(2));
REQUIRE(seq.GetInteractionLength(p) / kgMSq == Approx(6. / 5));
CHECK(switchProcess.GetInteractionLength(p) / kgMSq == Approx(2));
CHECK(seq.GetInteractionLength(p) / kgMSq == Approx(6. / 5));
}
// high energy process creates 2 secondaries
......@@ -159,7 +159,7 @@ TEST_CASE("SwitchProcess from InteractionProcess") {
InverseGrammageType invLambda = 0 / kgMSq;
switchProcess.SelectInteraction(p, projectile, 0.01 / kgMSq, invLambda);
REQUIRE(view.getSize() == 2);
CHECK(view.getSize() == 2);
}
}
}
......@@ -182,8 +182,8 @@ TEST_CASE("SwitchProcess from ProcessSequence") {
auto p = stack.GetNextParticle();
SECTION("interaction length") {
REQUIRE(switchProcess.GetInteractionLength(p) / kgMSq == Approx(2. / 3));
REQUIRE(completeSeq.GetInteractionLength(p) / kgMSq == Approx(4. / 7));
CHECK(switchProcess.GetInteractionLength(p) / kgMSq == Approx(2. / 3));
CHECK(completeSeq.GetInteractionLength(p) / kgMSq == Approx(4. / 7));
}
SECTION("SelectInteraction") {
......@@ -207,7 +207,7 @@ TEST_CASE("SwitchProcess from ProcessSequence") {
auto const mean =
std::accumulate(numberOfSecondaries.cbegin(), numberOfSecondaries.cend(), 0.) /
numberOfSecondaries.size();
REQUIRE(mean == Approx(12. / 7.).margin(0.01));
CHECK(mean == Approx(12. / 7.).margin(0.01));
}
}
......@@ -216,8 +216,8 @@ TEST_CASE("SwitchProcess from ProcessSequence") {
auto p = stack.GetNextParticle();
SECTION("interaction length") {
REQUIRE(switchProcess.GetInteractionLength(p) / kgMSq == Approx(3));
REQUIRE(completeSeq.GetInteractionLength(p) / kgMSq == Approx(12. / 7.));
CHECK(switchProcess.GetInteractionLength(p) / kgMSq == Approx(3));
CHECK(completeSeq.GetInteractionLength(p) / kgMSq == Approx(12. / 7.));
}
SECTION("SelectInteraction") {
......@@ -241,7 +241,7 @@ TEST_CASE("SwitchProcess from ProcessSequence") {
auto const mean =
std::accumulate(numberOfSecondaries.cbegin(), numberOfSecondaries.cend(), 0.) /
numberOfSecondaries.size();
REQUIRE(mean == Approx(24. / 7.).margin(0.01));
CHECK(mean == Approx(24. / 7.).margin(0.01));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment