diff --git a/Framework/StackInterface/testSecondaryView.cc b/Framework/StackInterface/testSecondaryView.cc index 2d2064b64e2e09c96ec5f77ebbf25d50f5d60e9e..a306de379eab62687b48530df09109534e462353 100644 --- a/Framework/StackInterface/testSecondaryView.cc +++ b/Framework/StackInterface/testSecondaryView.cc @@ -134,4 +134,77 @@ TEST_CASE("SecondaryStack", "[stack]") { REQUIRE(view.GetSize() == 1); } + + SECTION("deletion") { + StackTest stack; + stack.AddParticle(std::tuple{0.}); + + { + auto particle = stack.GetNextParticle(); + StackTestView view(particle); + + auto proj = view.GetProjectile(); + proj.AddSecondary(std::tuple{-2.}); + proj.AddSecondary(std::tuple{-1.}); + proj.AddSecondary(std::tuple{1.}); + proj.AddSecondary(std::tuple{2.}); + + CHECK(stack.GetSize() == 5); + + // now delete all negative entries, i.e. -1 and -2 + auto p = view.begin(); + while (p != view.end()) { + auto data = p.GetData(); + if (data < 0) { + std::cout << "deleting " << data << ", "; + p.Delete(); + } else { + ++p; + } + } + + // stack should contain 0, 1, 2 now + + CHECK(stack.GetSize() == 3); + + std::cout << std::endl; + for (auto& p : stack) { std::cout << p.GetData() << " | "; } + std::cout << std::endl; + } + + // repeat + + { + auto particle = stack.GetNextParticle(); + StackTestView view(particle); + + // put -2,...,+2 on stack + auto proj = view.GetProjectile(); + proj.AddSecondary(std::tuple{-2.}); + proj.AddSecondary(std::tuple{-1.}); + proj.AddSecondary(std::tuple{1.}); + proj.AddSecondary(std::tuple{2.}); + // stack should contain 0, 1, 2, [ -2, -1, 1, 2] + + auto p = view.begin(); + while (p != view.end()) { + auto data = p.GetData(); + if (data < 0) { + std::cout << "deleting " << data << ", "; + p.Delete(); + } else { + ++p; + } + } + + // stack should contain 0, 1, 2, 0, [1, 2] + // view should contain 1, 2 + + CHECK(stack.GetSize() == 6); + + std::cout << std::endl; + for (auto& p : stack) { std::cout << p.GetData() << " | "; } + std::cout << std::endl; + } + } }