@@ -666,6 +666,33 @@ TEST_CASE("Collection size and empty", "[basics][collections]") {
666666 REQUIRE (coll.size () == 2u );
667667}
668668
669+ TEST_CASE (" Collection construction from range" , " [basics][collections]" ) {
670+ std::vector<MutableExampleCluster> clusters (10 );
671+ auto clusterColl = ExampleClusterCollection::from (clusters);
672+ REQUIRE_FALSE (clusterColl.isSubsetCollection ());
673+ REQUIRE (clusterColl.size () == clusters.size ());
674+ for (size_t i = 0 ; i < clusters.size (); ++i) {
675+ REQUIRE (clusterColl[i] == clusters[i]);
676+ }
677+
678+ const auto otherClusterColl = ExampleClusterCollection::from (std::as_const (clusterColl));
679+ REQUIRE (otherClusterColl.isSubsetCollection ());
680+ REQUIRE (otherClusterColl.size () == clusterColl.size ());
681+ for (size_t i = 0 ; i < clusters.size (); ++i) {
682+ REQUIRE (otherClusterColl[i] == clusterColl[i]);
683+ }
684+
685+ // Cannot construct a collection from a range of unowned immutable handles
686+ REQUIRE_THROWS_AS (ExampleClusterCollection::from (std::vector<ExampleCluster>(10 )), std::invalid_argument);
687+
688+ for (const auto & cluster : clusterColl) {
689+ REQUIRE (cluster.id ().index != podio::ObjectID::untracked);
690+ }
691+ // Cannot construct a collection from a range of mutable handles that are
692+ // already owned
693+ REQUIRE_THROWS_AS (ExampleClusterCollection::from (clusters), std::invalid_argument);
694+ }
695+
669696TEST_CASE (" const correct indexed access to const collections" , " [const-correctness]" ) {
670697 STATIC_REQUIRE (std::is_same_v<decltype (std::declval<const ExampleClusterCollection>()[0 ]),
671698 ExampleCluster>); // const collections should only have indexed access to mutable
0 commit comments