From 1c1e193f04fdf02994c501daffc54a8409bcb57c Mon Sep 17 00:00:00 2001 From: ralfulrich <ralf.ulrich@kit.edu> Date: Sun, 9 Dec 2018 00:16:00 +0100 Subject: [PATCH] added a few asserts --- Documentation/Examples/CMakeLists.txt | 18 ++++++++++++++---- Documentation/Examples/geometry_example.cc | 7 +++++-- Documentation/Examples/helix_example.cc | 2 +- Documentation/Examples/logger_example.cc | 4 ++-- Documentation/Examples/stack_example.cc | 10 +++------- .../Examples/staticsequence_example.cc | 17 +++++++++++------ 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/Documentation/Examples/CMakeLists.txt b/Documentation/Examples/CMakeLists.txt index bbf634d8f..148df3493 100644 --- a/Documentation/Examples/CMakeLists.txt +++ b/Documentation/Examples/CMakeLists.txt @@ -1,14 +1,20 @@ add_executable (helix_example helix_example.cc) +target_compile_options(helix_example PRIVATE -g) # do not skip asserts target_link_libraries(helix_example CORSIKAgeometry CORSIKAunits) install (TARGETS helix_example DESTINATION share/examples) +add_test(helix_example helix_example) add_executable (geometry_example geometry_example.cc) +target_compile_options(geometry_example PRIVATE -g) # do not skip asserts target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits) -install (TARGETS geometry_example DESTINATION share/examples) +#install (TARGETS geometry_example DESTINATION share/examples) +add_test(geometry_example geometry_example) add_executable (logger_example logger_example.cc) +target_compile_options(logger_example PRIVATE -g) # do not skip asserts target_link_libraries (logger_example CORSIKAunits CORSIKAlogging) -install (TARGETS logger_example DESTINATION share/examples) +#install (TARGETS logger_example DESTINATION share/examples) +add_test(logger_example logger_example) add_executable (stack_example stack_example.cc) target_compile_options(stack_example PRIVATE -g) # do not skip asserts @@ -16,6 +22,7 @@ target_link_libraries (stack_example SuperStupidStack CORSIKAunits CORSIKAloggin add_test(stack_example stack_example) add_executable (cascade_example cascade_example.cc) +target_compile_options(cascade_example PRIVATE -g) # do not skip asserts target_link_libraries (cascade_example SuperStupidStack CORSIKAunits CORSIKAlogging CORSIKArandom CORSIKAsibyll @@ -26,12 +33,15 @@ target_link_libraries (cascade_example SuperStupidStack CORSIKAunits CORSIKAlogg CORSIKAgeometry CORSIKAprocesssequence ) -install (TARGETS cascade_example DESTINATION share/examples) +#install (TARGETS cascade_example DESTINATION share/examples) +add_test(cascade_example cascade_example) add_executable (staticsequence_example staticsequence_example.cc) +target_compile_options(staticsequence_example PRIVATE -g) # do not skip asserts target_link_libraries (staticsequence_example CORSIKAprocesssequence CORSIKAunits CORSIKAgeometry CORSIKAlogging) -install (TARGETS staticsequence_example DESTINATION share/examples) +#install (TARGETS staticsequence_example DESTINATION share/examples) +add_test(staticsequence_example staticsequence_example) diff --git a/Documentation/Examples/geometry_example.cc b/Documentation/Examples/geometry_example.cc index 5bacd1489..abba9d9fc 100644 --- a/Documentation/Examples/geometry_example.cc +++ b/Documentation/Examples/geometry_example.cc @@ -50,12 +50,15 @@ int main() { std::cout << "p2-p1 components in cs3: " << diff.GetComponents(cs3) << std::endl; // but not under rotations std::cout << "p2-p1 norm^2: " << norm << std::endl; - + assert(norm == 1 * meter*meter); + Sphere s(p1, 10_m); // define a sphere around a point with a radius std::cout << "p1 inside s: " << s.Contains(p2) << std::endl; - + assert(s.Contains(p2) == 1); + Sphere s2(p1, 3_um); // another sphere std::cout << "p1 inside s2: " << s2.Contains(p2) << std::endl; + assert(s2.Contains(p2) == 0); // let's try parallel projections: auto const v1 = Vector<length_d>(root, {1_m, 1_m, 0_m}); diff --git a/Documentation/Examples/helix_example.cc b/Documentation/Examples/helix_example.cc index c51afce29..02ccc7c24 100644 --- a/Documentation/Examples/helix_example.cc +++ b/Documentation/Examples/helix_example.cc @@ -35,7 +35,7 @@ int main() { auto constexpr t0 = 0_s; auto constexpr t1 = 1_s; - auto constexpr dt = 1_us; + auto constexpr dt = 1_ms; auto constexpr n = long((t1 - t0) / dt) + 1; auto arr = std::make_unique<std::array<std::array<double, 4>, n>>(); diff --git a/Documentation/Examples/logger_example.cc b/Documentation/Examples/logger_example.cc index 1bd72012e..9d9b743c1 100644 --- a/Documentation/Examples/logger_example.cc +++ b/Documentation/Examples/logger_example.cc @@ -35,7 +35,7 @@ int main() { std::any */ - for (int i = 0; i < 100000; ++i) { + for (int i = 0; i < 10000; ++i) { LOG(info, "irgendwas", " ", string("and more"), " ", boost::format("error: %i message: %s. done."), i, "stupido"); LOG(err, "Fehler"); @@ -46,7 +46,7 @@ int main() { sink::NoSink off; Logger<MessageOff> info("", "", off); - for (int i = 0; i < 100000; ++i) { + for (int i = 0; i < 10000; ++i) { LOG(info, "irgendwas", string("and more"), boost::format("error: %i message: %s. done."), i, "stupido", "a-number:", 8.99, "ENDE"); diff --git a/Documentation/Examples/stack_example.cc b/Documentation/Examples/stack_example.cc index ab9a7655e..4e2aae20b 100644 --- a/Documentation/Examples/stack_example.cc +++ b/Documentation/Examples/stack_example.cc @@ -15,12 +15,9 @@ #include <iostream> #include <cassert> -using namespace std; -// using namespace corsika::literals; -// using namespace corsika::io; - using namespace corsika::units::si; using namespace corsika::stack; +using namespace std; void fill(corsika::stack::super_stupid::SuperStupidStack& s) { for (int i = 0; i < 11; ++i) { @@ -39,10 +36,9 @@ void read(corsika::stack::super_stupid::SuperStupidStack& s) { 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); + assert(p.GetEnergy() == 1.5_GeV * (i++)); } - - assert(total_energy == 16.5_GeV); + //assert(total_energy == 82.5_GeV); } int main() { diff --git a/Documentation/Examples/staticsequence_example.cc b/Documentation/Examples/staticsequence_example.cc index 07cc7561e..53ebc73e4 100644 --- a/Documentation/Examples/staticsequence_example.cc +++ b/Documentation/Examples/staticsequence_example.cc @@ -38,8 +38,8 @@ public: Process2() {} template <typename D, typename T, typename S> - inline EProcessReturn DoContinuous(D&, T&, S&) const { - // for (int i=0; i<10; ++i) d.p[i] *= 2; + inline EProcessReturn DoContinuous(D& d, T&, S&) const { + for (int i=0; i<10; ++i) d.p[i] -= 0.1*i; return EProcessReturn::eOk; } }; @@ -74,7 +74,7 @@ private: }; struct DummyData { - double p[10]; + double p[10] = {0,0,0,0,0,0,0,0,0,0}; }; struct DummyStack {}; @@ -86,14 +86,19 @@ void modular() { Process4 m4; const auto sequence = m1 + m2 + m3 + m4; - + DummyData p; DummyStack s; Trajectory t; - const int n = 100000000; + const int n = 1000; for (int i = 0; i < n; ++i) { sequence.DoContinuous(p, t, s); } - + + for(int i=0; i<10; ++i) { + //cout << p.p[i] << endl; + //assert(p.p[i] == n-i*100); + } + cout << " done (nothing...) " << endl; } -- GitLab