Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:57

0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003 
0004 #include "DataFormats/Common/interface/StdArray.h"
0005 
0006 TEST_CASE("StdArray", "[StdArray]") {
0007   SECTION("Empty array") {
0008     edm::StdArray<int, 0> array;
0009     REQUIRE(array.empty());
0010     REQUIRE(array.begin() == array.end());
0011     REQUIRE(array.rbegin() == array.rend());
0012     for ([[maybe_unused]] auto element : array) {
0013       REQUIRE(false);
0014     }
0015     REQUIRE(std::data(array) == nullptr);
0016     REQUIRE(std::size(array) == 0);
0017   }
0018 
0019   SECTION("Default constructor") {
0020     edm::StdArray<int, 4> array;
0021     REQUIRE(not array.empty());
0022     REQUIRE(array.size() == 4);
0023     REQUIRE(std::data(array) != nullptr);
0024     REQUIRE(std::size(array) != 0);
0025   }
0026 
0027   SECTION("Aggregate constructor") {
0028     edm::StdArray<int, 4> array{{0, 1, 2, 3}};
0029     REQUIRE(not array.empty());
0030     REQUIRE(array.size() == 4);
0031     REQUIRE(array.front() == 0);
0032     REQUIRE(array.back() == 3);
0033     for (int i = 0; i < 4; ++i) {
0034       REQUIRE(array.at(i) == i);
0035       REQUIRE(array[i] == i);
0036     }
0037     REQUIRE(std::data(array) != nullptr);
0038     REQUIRE(std::size(array) != 0);
0039   }
0040 
0041   SECTION("Copy constructor") {
0042     edm::StdArray<int, 4> array{{0, 1, 2, 3}};
0043     edm::StdArray<int, 4> other = array;
0044     for (int i = 0; i < 4; ++i) {
0045       REQUIRE(other[i] == i);
0046     }
0047   }
0048 
0049   SECTION("Move constructor") {
0050     edm::StdArray<int, 4> array{{0, 1, 2, 3}};
0051     edm::StdArray<int, 4> other = std::move(array);
0052     for (int i = 0; i < 4; ++i) {
0053       REQUIRE(other[i] == i);
0054     }
0055   }
0056 
0057   SECTION("Copy assignment") {
0058     edm::StdArray<int, 4> array{{0, 1, 2, 3}};
0059     edm::StdArray<int, 4> other;
0060     other = array;
0061     for (int i = 0; i < 4; ++i) {
0062       REQUIRE(other[i] == i);
0063     }
0064   }
0065 
0066   SECTION("Move assignment") {
0067     edm::StdArray<int, 4> array{{0, 1, 2, 3}};
0068     edm::StdArray<int, 4> other;
0069     other = std::move(array);
0070     for (int i = 0; i < 4; ++i) {
0071       REQUIRE(other[i] == i);
0072     }
0073   }
0074 
0075   SECTION("Assignment from std::array") {
0076     edm::StdArray<int, 4> array;
0077     std::array<int, 4> other{{0, 1, 2, 3}};
0078     array = other;
0079     for (int i = 0; i < 4; ++i) {
0080       REQUIRE(array[i] == i);
0081     }
0082   }
0083 
0084   SECTION("Assignment to std::array") {
0085     edm::StdArray<int, 4> array{{0, 1, 2, 3}};
0086     std::array<int, 4> other = array;
0087     for (int i = 0; i < 4; ++i) {
0088       REQUIRE(other[i] == i);
0089     }
0090   }
0091 }