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/ordered_on.hpp>
0016
0017
0018 #include <gtest/gtest.h>
0019
0020 struct int_lt_relation {
0021 TRACCC_HOST_DEVICE
0022 bool operator()(const int& a, const int& b) const { return a < b; }
0023 };
0024
0025 struct int_leq_relation {
0026 TRACCC_HOST_DEVICE
0027 bool operator()(const int& a, const int& b) const { return a <= b; }
0028 };
0029
0030 class CPUSanityOrderedOn : public testing::Test {
0031 protected:
0032 CPUSanityOrderedOn() {}
0033 };
0034
0035 TEST_F(CPUSanityOrderedOn, TrueConsecutiveNoRepeatsLeq) {
0036 std::vector<int> host_vector;
0037
0038 for (int i = 0; i < 500000; ++i) {
0039 host_vector.push_back(i);
0040 }
0041
0042 ASSERT_TRUE(traccc::host::is_ordered_on(int_leq_relation(), host_vector));
0043
0044 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0045
0046 ASSERT_TRUE(traccc::host::is_ordered_on(int_leq_relation(), device_vector));
0047 }
0048
0049 TEST_F(CPUSanityOrderedOn, TrueConsecutiveNoRepeatsLt) {
0050 std::vector<int> host_vector;
0051
0052 for (int i = 0; i < 500000; ++i) {
0053 host_vector.push_back(i);
0054 }
0055
0056 ASSERT_TRUE(traccc::host::is_ordered_on(int_lt_relation(), host_vector));
0057
0058 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0059
0060 ASSERT_TRUE(traccc::host::is_ordered_on(int_lt_relation(), device_vector));
0061 }
0062
0063 TEST_F(CPUSanityOrderedOn, TrueConsecutiveRepeatsLeq) {
0064 std::vector<int> host_vector;
0065
0066 for (int i = 0; i < 5000; ++i) {
0067 for (int j = 0; j < i; ++j) {
0068 host_vector.push_back(i);
0069 }
0070 }
0071
0072 ASSERT_TRUE(traccc::host::is_ordered_on(int_leq_relation(), host_vector));
0073
0074 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0075
0076 ASSERT_TRUE(traccc::host::is_ordered_on(int_leq_relation(), device_vector));
0077 }
0078
0079 TEST_F(CPUSanityOrderedOn, FalseConsecutiveRepeatLt) {
0080 std::vector<int> host_vector;
0081
0082 for (int i = 0; i < 5000; ++i) {
0083 for (int j = 0; j < i; ++j) {
0084 host_vector.push_back(i);
0085 }
0086 }
0087
0088 ASSERT_FALSE(traccc::host::is_ordered_on(int_lt_relation(), host_vector));
0089
0090 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0091
0092 ASSERT_FALSE(traccc::host::is_ordered_on(int_lt_relation(), device_vector));
0093 }
0094
0095 TEST_F(CPUSanityOrderedOn, TrueConsecutivePathologicalFirstLeq) {
0096 std::vector<int> host_vector;
0097
0098 host_vector.push_back(4000);
0099
0100 for (int i = 0; i < 5000; ++i) {
0101 for (int j = 0; j < i; ++j) {
0102 host_vector.push_back(i);
0103 }
0104 }
0105
0106 ASSERT_FALSE(traccc::host::is_ordered_on(int_leq_relation(), host_vector));
0107
0108 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0109
0110 ASSERT_FALSE(traccc::host::is_ordered_on(int_leq_relation(), device_vector));
0111 }
0112
0113 TEST_F(CPUSanityOrderedOn, TrueConsecutivePathologicalLastLeq) {
0114 std::vector<int> host_vector;
0115
0116 host_vector.push_back(2000);
0117
0118 for (int i = 0; i < 5000; ++i) {
0119 for (int j = 0; j < i; ++j) {
0120 host_vector.push_back(i);
0121 }
0122 }
0123
0124 ASSERT_FALSE(traccc::host::is_ordered_on(int_leq_relation(), host_vector));
0125
0126 vecmem::device_vector<int> device_vector(vecmem::get_data(host_vector));
0127
0128 ASSERT_FALSE(traccc::host::is_ordered_on(int_leq_relation(), device_vector));
0129 }