File indexing completed on 2026-07-26 08:22:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <vecmem/containers/device_vector.hpp>
0011 #include <vecmem/containers/vector.hpp>
0012
0013
0014 #include <traccc/definitions/qualifiers.hpp>
0015 #include <traccc/sanity/contiguous_on.hpp>
0016
0017
0018 #include <gtest/gtest.h>
0019
0020 struct int_identity_projection {
0021 TRACCC_HOST_DEVICE
0022 int operator()(const int& v) const { return v; }
0023 };
0024
0025 class CPUSanityContiguousOn : public testing::Test {
0026 protected:
0027 CPUSanityContiguousOn() {}
0028 };
0029
0030 TEST_F(CPUSanityContiguousOn, TrueOrdered) {
0031 std::vector<int> host_vector;
0032
0033 for (int i = 0; i < 5000; ++i) {
0034 for (int j = 0; j < i; ++j) {
0035 host_vector.push_back(i);
0036 }
0037 }
0038
0039 ASSERT_TRUE(
0040 traccc::host::is_contiguous_on(int_identity_projection(), host_vector));
0041
0042 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0043
0044 ASSERT_TRUE(
0045 traccc::host::is_contiguous_on(int_identity_projection(), device_vector));
0046 }
0047
0048 TEST_F(CPUSanityContiguousOn, TrueRandom) {
0049 std::vector<int> host_vector;
0050
0051 for (int i : {603, 6432, 1, 3, 67, 2, 1111}) {
0052 for (int j = 0; j < i; ++j) {
0053 host_vector.push_back(i);
0054 }
0055 }
0056
0057 ASSERT_TRUE(
0058 traccc::host::is_contiguous_on(int_identity_projection(), host_vector));
0059
0060 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0061
0062 ASSERT_TRUE(
0063 traccc::host::is_contiguous_on(int_identity_projection(), device_vector));
0064 }
0065
0066 TEST_F(CPUSanityContiguousOn, FalseOrdered) {
0067 std::vector<int> host_vector;
0068
0069 for (int i = 0; i < 5000; ++i) {
0070 if (i == 105) {
0071 host_vector.push_back(5);
0072 } else {
0073 for (int j = 0; j < i; ++j) {
0074 host_vector.push_back(i);
0075 }
0076 }
0077 }
0078
0079 ASSERT_FALSE(
0080 traccc::host::is_contiguous_on(int_identity_projection(), host_vector));
0081
0082 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0083
0084 ASSERT_FALSE(
0085 traccc::host::is_contiguous_on(int_identity_projection(), device_vector));
0086 }
0087
0088 TEST_F(CPUSanityContiguousOn, FalseOrderedPathologicalFirst) {
0089 std::vector<int> host_vector;
0090
0091 host_vector.push_back(4000);
0092
0093 for (int i = 0; i < 5000; ++i) {
0094 for (int j = 0; j < i; ++j) {
0095 host_vector.push_back(i);
0096 }
0097 }
0098
0099 ASSERT_FALSE(
0100 traccc::host::is_contiguous_on(int_identity_projection(), host_vector));
0101
0102 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0103
0104 ASSERT_FALSE(
0105 traccc::host::is_contiguous_on(int_identity_projection(), device_vector));
0106 }
0107
0108 TEST_F(CPUSanityContiguousOn, TrueOrderedPathologicalFirst) {
0109 std::vector<int> host_vector;
0110
0111 host_vector.push_back(6000);
0112
0113 for (int i = 0; i < 5000; ++i) {
0114 for (int j = 0; j < i; ++j) {
0115 host_vector.push_back(i);
0116 }
0117 }
0118
0119 ASSERT_TRUE(
0120 traccc::host::is_contiguous_on(int_identity_projection(), host_vector));
0121
0122 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0123
0124 ASSERT_TRUE(
0125 traccc::host::is_contiguous_on(int_identity_projection(), device_vector));
0126 }
0127
0128 TEST_F(CPUSanityContiguousOn, FalseOrderedPathologicalLast) {
0129 std::vector<int> host_vector;
0130
0131 for (int i = 0; i < 5000; ++i) {
0132 for (int j = 0; j < i; ++j) {
0133 host_vector.push_back(i);
0134 }
0135 }
0136
0137 host_vector.push_back(2);
0138
0139 ASSERT_FALSE(
0140 traccc::host::is_contiguous_on(int_identity_projection(), host_vector));
0141
0142 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0143
0144 ASSERT_FALSE(
0145 traccc::host::is_contiguous_on(int_identity_projection(), device_vector));
0146 }
0147
0148 TEST_F(CPUSanityContiguousOn, FalseRandom) {
0149 std::vector<int> host_vector;
0150
0151 for (int i : {603, 6432, 1, 3, 67, 1, 1111}) {
0152 for (int j = 0; j < i; ++j) {
0153 host_vector.push_back(i);
0154 }
0155 }
0156
0157 ASSERT_FALSE(
0158 traccc::host::is_contiguous_on(int_identity_projection(), host_vector));
0159
0160 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0161
0162 ASSERT_FALSE(
0163 traccc::host::is_contiguous_on(int_identity_projection(), device_vector));
0164 }