Skip to content

Commit 98fdfe3

Browse files
author
Raghuveer Devulapalli
committed
Add tests for keyvalue
1 parent 22d2636 commit 98fdfe3

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/test-keyvalue.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 "x86simdsort-scalar.h"
9+
#include <gtest/gtest.h>
10+
11+
template <typename T>
12+
class simdkvsort : public ::testing::Test {
13+
public:
14+
simdkvsort()
15+
{
16+
std::iota(arrsize.begin(), arrsize.end(), 1);
17+
arrtype = {"random",
18+
"constant",
19+
"sorted",
20+
"reverse",
21+
"smallrange",
22+
"max_at_the_end",
23+
"rand_max"};
24+
}
25+
std::vector<std::string> arrtype;
26+
std::vector<size_t> arrsize = std::vector<size_t>(1024);
27+
};
28+
29+
TYPED_TEST_SUITE_P(simdkvsort);
30+
31+
TYPED_TEST_P(simdkvsort, test_kvsort)
32+
{
33+
using T1 = typename std::tuple_element<0, decltype(TypeParam())>::type;
34+
using T2 = typename std::tuple_element<1, decltype(TypeParam())>::type;
35+
for (auto type : this->arrtype) {
36+
bool hasnan = (type == "rand_with_nan") ? true : false;
37+
for (auto size : this->arrsize) {
38+
std::vector<T1> v1 = get_array<T1>(type, size);
39+
std::vector<T2> v2 = get_array<T2>(type, size);
40+
std::vector<T1> v1_bckp = v1;
41+
std::vector<T2> v2_bckp = v2;
42+
xss::scalar::keyvalue_qsort(v1_bckp.data(), v2_bckp.data(), size, hasnan);
43+
x86simdsort::keyvalue_qsort(v1.data(), v2.data(), size, hasnan);
44+
ASSERT_EQ(v1, v1_bckp);
45+
ASSERT_EQ(v2, v2_bckp);
46+
v1.clear(); v2.clear();
47+
v1_bckp.clear(); v2_bckp.clear();
48+
}
49+
}
50+
}
51+
52+
REGISTER_TYPED_TEST_SUITE_P(simdkvsort, test_kvsort);
53+
54+
using QKVSortTestTypes = testing::Types<std::tuple<double, double>,
55+
std::tuple<double, uint64_t>,
56+
std::tuple<double, int64_t>,
57+
std::tuple<uint64_t, double>,
58+
std::tuple<uint64_t, uint64_t>,
59+
std::tuple<uint64_t, int64_t>,
60+
std::tuple<int64_t, double>,
61+
std::tuple<int64_t, uint64_t>,
62+
std::tuple<int64_t, int64_t>>;
63+
64+
INSTANTIATE_TYPED_TEST_SUITE_P(xss, simdkvsort, QKVSortTestTypes);

0 commit comments

Comments
 (0)