17 #include "my_config.h"
18 #include <gtest/gtest.h>
20 #include "test_utils.h"
27 namespace join_tab_sort_unittest {
35 virtual void SetUp() { initializer.SetUp(); }
36 virtual void TearDown() { initializer.TearDown(); }
48 m_table.map= 1ULL << table_no;
49 this->table= &m_table;
55 std::ostream &operator<<(std::ostream &s,
const MOCK_JOIN_TAB &jt)
58 << jt.found_records <<
", "
64 TEST_F(JTSortTest, SimpleSortTest)
66 MOCK_JOIN_TAB jt1(UINT_MAX, 0);
67 MOCK_JOIN_TAB jt2(2, 0);
68 MOCK_JOIN_TAB jt3(1, 0);
69 MOCK_JOIN_TAB jt4(10, 0);
70 MOCK_JOIN_TAB jt5(5, 0);
72 MOCK_JOIN_TAB *arr[5];
81 EXPECT_EQ(1
U, arr[0]->found_records);
82 EXPECT_EQ(2
U, arr[1]->found_records);
83 EXPECT_EQ(5
U, arr[2]->found_records);
84 EXPECT_EQ(10
U, arr[3]->found_records);
85 EXPECT_EQ(UINT_MAX, arr[4]->found_records);
90 TEST_F(JTSortTest, SortFoundRecordsTest)
92 const int num_tables= 50;
93 MOCK_JOIN_TAB *arr[num_tables];
95 for (
int i= 0;
i < num_tables;
i++)
96 arr[
i]=
new MOCK_JOIN_TAB(
i, 0);
99 std::random_shuffle(arr, arr + 50);
101 for (
int i= 1;
i < num_tables;
i++)
102 EXPECT_TRUE(arr[
i]->found_records > arr[
i-1]->found_records);
105 std::random_shuffle(arr, arr + 50);
107 for (
int i= 1;
i < num_tables;
i++)
108 EXPECT_TRUE(arr[
i]->found_records > arr[
i-1]->found_records);
110 for (
int i= 0;
i < num_tables;
i++)
117 TEST_F(JTSortTest, SortDependsTest)
119 const int num_tables= 50;
120 MOCK_JOIN_TAB *arr[num_tables];
126 for (
int i= 0;
i < num_tables;
i++)
128 arr[
i]=
new MOCK_JOIN_TAB(
i,
i);
129 for (
int j=
i+1; j < num_tables; j++)
130 arr[
i]->dependent|= 1ULL << j;
134 std::random_shuffle(arr, arr + num_tables);
136 for (
int i= 1;
i < num_tables;
i++)
137 EXPECT_TRUE(arr[
i]->found_records < arr[
i-1]->found_records)
138 <<
"i: " << *(arr[
i]) <<
" "
139 <<
"i-1: " << *(arr[
i-1]);
142 std::random_shuffle(arr, arr + num_tables);
144 for (
int i= 1;
i < num_tables;
i++)
145 EXPECT_TRUE(arr[
i]->found_records < arr[
i-1]->found_records);
147 for (
int i= 0;
i < num_tables;
i++)
154 TEST_F(JTSortTest, SortKeyDependsTest)
156 const int num_tables= 50;
157 MOCK_JOIN_TAB *arr[num_tables];
164 for (
int i= 0;
i < num_tables;
i++)
166 arr[
i]=
new MOCK_JOIN_TAB(
i,
i);
167 for (
int j=
i+1; j < num_tables; j++)
168 arr[
i]->key_dependent|= 1ULL << j;
172 std::random_shuffle(arr, arr + num_tables);
174 for (
int i= 1;
i < num_tables;
i++)
175 EXPECT_TRUE(arr[
i]->found_records < arr[
i-1]->found_records);
178 std::random_shuffle(arr, arr + num_tables);
180 for (
int i= 1;
i < num_tables;
i++)
181 EXPECT_TRUE(arr[
i]->found_records < arr[
i-1]->found_records);
183 for (
int i= 0;
i < num_tables;
i++)
193 public std::binary_function<const int*, const int*, bool>
196 bool operator()(
const int *i1,
const int *i2)
const
205 const uint ints_to_sort= 1000;
207 std::vector<int> arr;
208 std::vector<int*> arr_ptr;
210 arr.reserve(ints_to_sort);
211 arr_ptr.reserve(ints_to_sort);
213 for (uint
i= 0;
i < ints_to_sort;
i++)
216 arr_ptr.push_back(&arr[
i]);
219 EXPECT_TRUE(arr.size() == ints_to_sort);
220 EXPECT_TRUE(arr_ptr.size() == ints_to_sort);
223 std::random_shuffle(&arr_ptr.front(), &arr_ptr.back() + 1);
224 merge_sort(&arr_ptr.front(), &arr_ptr.back() + 1, Int_compare_ptr());
225 for (uint
i= 0;
i < arr_ptr.size();
i++)
226 EXPECT_TRUE(*arr_ptr[
i] == (
int)
i);
229 std::random_shuffle(&arr_ptr.front(), &arr_ptr.back() + 1);
230 insert_sort(&arr_ptr.front(), &arr_ptr.back() + 1, Int_compare_ptr());
231 for (uint
i= 0;
i < arr_ptr.size();
i++)
232 EXPECT_TRUE(*arr_ptr[
i] == (
int)
i);
236 TEST_F(JTSortTest, SortInt2Test)
238 const uint ints_to_sort= 1000;
240 std::vector<int> arr;
241 std::vector<int*> arr_ptr;
243 arr.reserve(ints_to_sort);
244 arr_ptr.reserve(ints_to_sort);
246 for (uint
i= 0;
i < (ints_to_sort - 2);
i++)
248 arr.push_back((
i % 2) ?
i : (
i * -1));
249 arr_ptr.push_back(&arr[
i]);
252 arr.push_back(INT_MAX32);
253 arr_ptr.push_back(&arr.back());
255 arr.push_back(INT_MIN32);
256 arr_ptr.push_back(&arr.back());
258 EXPECT_TRUE(arr.size() == ints_to_sort);
259 EXPECT_TRUE(arr_ptr.size() == ints_to_sort);
262 std::random_shuffle(&arr_ptr.front(), &arr_ptr.back() + 1);
263 merge_sort(&arr_ptr.front(), &arr_ptr.back() + 1, Int_compare_ptr());
264 for (uint
i= 1;
i < arr_ptr.size();
i++)
265 EXPECT_TRUE(*arr_ptr[
i-1] < *arr_ptr[
i]);
268 std::random_shuffle(&arr_ptr.front(), &arr_ptr.back() + 1);
269 insert_sort(&arr_ptr.front(), &arr_ptr.back() + 1, Int_compare_ptr());
270 for (uint i= 1; i < arr_ptr.size(); i++)
271 EXPECT_TRUE(*arr_ptr[i-1] < *arr_ptr[i]);