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