Skip to content

Commit 729c97b

Browse files
author
Raghuveer Devulapalli
committed
Add tests for objsort
1 parent 38f89b0 commit 729c97b

File tree

2 files changed

+80
-8
lines changed

2 files changed

+80
-8
lines changed

tests/meson.build

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ libtests += static_library('tests_kvsort',
1212
include_directories : [lib, utils],
1313
)
1414

15-
#if cancompilefp16
16-
# libtests += static_library('tests_qsortfp16',
17-
# files('test-qsortfp16.cpp', ),
18-
# dependencies: gtest_dep,
19-
# include_directories : [src, utils],
20-
# cpp_args : ['-O3', '-march=sapphirerapids'],
21-
# )
22-
#endif
15+
libtests += static_library('tests_objsort',
16+
files('test-objqsort.cpp', ),
17+
dependencies: gtest_dep,
18+
include_directories : [lib, utils],
19+
)

tests/test-objqsort.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*******************************************
2+
* * Copyright (C) 2022-2023 Intel Corporation
3+
* * SPDX-License-Identifier: BSD-3-Clause
4+
* *******************************************/
5+
6+
#include "rand_array.h"
7+
#include "x86simdsort.h"
8+
#include <gtest/gtest.h>
9+
10+
template <typename T>
11+
struct P {
12+
T x, y;
13+
T metric() const
14+
{
15+
return x;
16+
}
17+
bool operator==(const P<T> &a) const
18+
{
19+
return a.x == x; // && a.y == y;
20+
}
21+
};
22+
23+
template <typename T>
24+
class simdobjsort : public ::testing::Test {
25+
public:
26+
simdobjsort()
27+
{
28+
std::iota(arrsize.begin(), arrsize.end(), 1);
29+
arrtype = {"random",
30+
"constant",
31+
"sorted",
32+
"reverse",
33+
"smallrange",
34+
"max_at_the_end",
35+
"rand_max"};
36+
}
37+
std::vector<std::string> arrtype;
38+
std::vector<size_t> arrsize = std::vector<size_t>(1024);
39+
};
40+
41+
TYPED_TEST_SUITE_P(simdobjsort);
42+
43+
TYPED_TEST_P(simdobjsort, test_objsort)
44+
{
45+
for (auto type : this->arrtype) {
46+
for (auto size : this->arrsize) {
47+
std::vector<TypeParam> x = get_array<TypeParam>(type, size);
48+
std::vector<TypeParam> y = get_array<TypeParam>("random", size);
49+
std::vector<P<TypeParam>> arr(size);
50+
for (size_t ii = 0; ii < size; ++ii) {
51+
arr[ii].x = x[ii];
52+
arr[ii].y = y[ii];
53+
}
54+
std::vector<P<TypeParam>> arr_bckp = arr;
55+
x86simdsort::object_qsort(arr.data(), size, [](P<TypeParam> p) {
56+
return p.metric();
57+
});
58+
std::sort(arr_bckp.begin(),
59+
arr_bckp.end(),
60+
[](const P<TypeParam> &a, const P<TypeParam> &b) {
61+
return a.metric() < b.metric();
62+
});
63+
ASSERT_EQ(arr, arr_bckp);
64+
arr.clear();
65+
arr_bckp.clear();
66+
}
67+
}
68+
}
69+
70+
REGISTER_TYPED_TEST_SUITE_P(simdobjsort, test_objsort);
71+
72+
using QObjSortTestTypes
73+
= testing::Types<double, uint64_t, int64_t, uint32_t, int32_t, float>;
74+
75+
INSTANTIATE_TYPED_TEST_SUITE_P(xss, simdobjsort, QObjSortTestTypes);

0 commit comments

Comments
 (0)