From af24950c943b3803d949cd589cb049f55b80bd9b Mon Sep 17 00:00:00 2001 From: Hans Dembinski <hans.dembinski@gmail.com> Date: Wed, 5 Dec 2018 14:19:20 +0100 Subject: [PATCH] demonstrating a tested example --- Documentation/Examples/CMakeLists.txt | 4 ++-- Documentation/Examples/stack_example.cc | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Documentation/Examples/CMakeLists.txt b/Documentation/Examples/CMakeLists.txt index 2a66a3470..bbf634d8f 100644 --- a/Documentation/Examples/CMakeLists.txt +++ b/Documentation/Examples/CMakeLists.txt @@ -11,8 +11,9 @@ target_link_libraries (logger_example CORSIKAunits CORSIKAlogging) install (TARGETS logger_example DESTINATION share/examples) add_executable (stack_example stack_example.cc) +target_compile_options(stack_example PRIVATE -g) # do not skip asserts target_link_libraries (stack_example SuperStupidStack CORSIKAunits CORSIKAlogging) -install (TARGETS stack_example DESTINATION share/examples) +add_test(stack_example stack_example) add_executable (cascade_example cascade_example.cc) target_link_libraries (cascade_example SuperStupidStack CORSIKAunits CORSIKAlogging @@ -34,4 +35,3 @@ target_link_libraries (staticsequence_example CORSIKAgeometry CORSIKAlogging) install (TARGETS staticsequence_example DESTINATION share/examples) - diff --git a/Documentation/Examples/stack_example.cc b/Documentation/Examples/stack_example.cc index f0a04f79b..ab9a7655e 100644 --- a/Documentation/Examples/stack_example.cc +++ b/Documentation/Examples/stack_example.cc @@ -13,6 +13,7 @@ #include <corsika/stack/super_stupid/SuperStupidStack.h> #include <iomanip> #include <iostream> +#include <cassert> using namespace std; // using namespace corsika::literals; @@ -30,14 +31,18 @@ void fill(corsika::stack::super_stupid::SuperStupidStack& s) { } void read(corsika::stack::super_stupid::SuperStupidStack& s) { - cout << "found Stack with " << s.GetSize() << " particles. " << endl; - EnergyType Etot; + assert(s.GetSize() == 11); // stack has 11 particles + + EnergyType total_energy; + int i = 0; for (auto& p : s) { - Etot += p.GetEnergy(); - cout << "particle: " << p.GetPID() << " with " << p.GetEnergy() / 1_GeV << " GeV" - << endl; + total_energy += p.GetEnergy(); + // particles are electrons with 1.5 GeV energy times i + assert(p.GetPID() == corsika::particles::Code::Electron); + assert(p.GetEnergy() == i++ * 1_GeV); } - cout << "Etot=" << Etot << " = " << Etot / 1_GeV << " GeV" << endl; + + assert(total_energy == 16.5_GeV); } int main() { -- GitLab