8 #include <gtest/gtest.h>
15 using namespace HCE::sphinx;
16 using namespace HCE::sphinx::reduce_task;
26 ASSERT_TRUE(sphinxReduceResult->hasNext() ==
false);
33 idWeightResult.push_back(make_pair(
"13",
"12345"));
34 idWeightResult.push_back(make_pair(
"13",
"2567891"));
35 idWeightResult.push_back(make_pair(
"21",
"1122334"));
36 idWeightResult.push_back(make_pair(
"221",
"99123453"));
37 idWeightResult.push_back(make_pair(
"221",
"5525"));
41 bool isFindExpectData(
string &expectDocId,
string &expectWeight, vector<int>& bestResIndex){
43 if (expectDocId == idWeightResult[bestResIndex[
index]].first &&
44 expectWeight == idWeightResult[bestResIndex[
index]].second){
62 sphinxReduceTask.
addKeyValue(idWeightResult[0].first, idWeightResult[0].second);
65 sphinxReduceResult->reset();
66 ASSERT_TRUE(sphinxReduceResult->hasNext());
67 sphinxReduceResult->getNext(expectId, expectWeight);
69 EXPECT_EQ(expectId, idWeightResult[0].first);
70 EXPECT_EQ(expectWeight, idWeightResult[0].second);
72 ASSERT_TRUE(sphinxReduceResult->hasNext() ==
false);
81 sphinxReduceTask.
addKeyValue(idWeightResult[0].first, idWeightResult[0].second);
82 sphinxReduceTask.
addKeyValue(idWeightResult[1].first, idWeightResult[1].second);
85 sphinxReduceResult->reset();
86 ASSERT_TRUE(sphinxReduceResult->hasNext());
87 sphinxReduceResult->getNext(expectId, expectWeight);
89 EXPECT_EQ(expectId, idWeightResult[1].first);
90 EXPECT_EQ(expectWeight, idWeightResult[1].second);
92 ASSERT_TRUE(sphinxReduceResult->hasNext() ==
false);
101 sphinxReduceTask.
addKeyValue(idWeightResult[3].first, idWeightResult[3].second);
102 sphinxReduceTask.
addKeyValue(idWeightResult[4].first, idWeightResult[4].second);
105 sphinxReduceResult->reset();
106 ASSERT_TRUE(sphinxReduceResult->hasNext());
107 sphinxReduceResult->getNext(expectId, expectWeight);
109 EXPECT_EQ(expectId, idWeightResult[3].first);
110 EXPECT_EQ(expectWeight, idWeightResult[3].second);
112 ASSERT_TRUE(sphinxReduceResult->hasNext() ==
false);
121 for (
size_t resIndex = 0; resIndex < idWeightResult.size(); ++resIndex){
122 sphinxReduceTask.
addKeyValue(idWeightResult[resIndex].first,
123 idWeightResult[resIndex].second);
125 vector<int>bestResIndex = {1, 2, 3};
129 sphinxReduceResult->reset();
132 while (sphinxReduceResult->hasNext()){
133 sphinxReduceResult->getNext(expectId, expectWeight);
134 EXPECT_TRUE(isFindExpectData(expectId, expectWeight, bestResIndex));
138 ASSERT_EQ(docNumber, 3);