hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxResultTrancaterTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxResultTrancaterTest.cpp
3  *
4  * Created on: Jun 11, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
11 
12 using namespace HCE::sphinx;
13 using namespace HCE::sphinx::reduce_task;
14 using namespace Poco;
15 
16 class SphinxResultTrancaterTest: public ::testing::Test{
17  protected:
18  virtual void SetUp(){
19 
20  matchInfo1 = buildSimpleMatchInfo(7LLU, 111LLU);
21  matchInfo2 = buildSimpleMatchInfo(9LLU, 222LLU);
22  matchInfo3 = buildSimpleMatchInfo(11LLU, 222LLU);
23  matchInfo4 = buildSimpleMatchInfo(12LLU, 99LLU);
24  matchInfo5 = buildSimpleMatchInfo(13LLU, 444LLU);
25 
26  AttrInfo pAttrInfo("first", "value");
27  matchInfo1.addAttrInfo(pAttrInfo);
28  matchInfo2.addAttrInfo(pAttrInfo);
29  matchInfo3.addAttrInfo(pAttrInfo);
30  matchInfo4.addAttrInfo(pAttrInfo);
31  matchInfo5.addAttrInfo(pAttrInfo);
32 
33  sphinxRequestInfo.setMaxResultsNumber(3);
34  sphinxRequestInfo.setOrderBy(NULL_SORT);
35 
36  sphinxResultData.assign(new SphinxResultData());
37  sphinxResultData->addMatchInfo(matchInfo1);
38  sphinxResultData->addMatchInfo(matchInfo2);
39  sphinxResultData->addMatchInfo(matchInfo5);
40  sphinxResultData->addMatchInfo(matchInfo3);
41  sphinxResultData->addMatchInfo(matchInfo4);
42 
43  expectSphinxResultData.addMatchInfo(matchInfo5);
44  expectSphinxResultData.addMatchInfo(matchInfo2);
45  expectSphinxResultData.addMatchInfo(matchInfo3);
46  }
47 
54  SharedPtr<SphinxResultData> sphinxResultData;
56 };
57 
58 TEST_F(SphinxResultTrancaterTest, correctTrancareResult)
59 {
60  SphinxResultTruncater sphinxResultTrancater;
61 
62  sphinxRequestInfo.setOrderBy(DESC_SORT);
63  sphinxResultData->addRequestInfo(sphinxRequestInfo);
64  expectSphinxResultData.addRequestInfo(sphinxRequestInfo);
65 
66  SharedPtr<SphinxResultData> trancatedResult = sphinxResultTrancater.trancate(sphinxResultData);
67 
68  ASSERT_TRUE(isEqualSphinxResultData(*trancatedResult.get(), expectSphinxResultData));
69 }
70 
71 
72 TEST_F(SphinxResultTrancaterTest, correctTruncateLessResultThanNeedToBeStored)
73 {
74  SphinxResultTruncater sphinxResultTrancater;
75 
76  sphinxRequestInfo.setMaxResultsNumber(10);
77  sphinxResultData->addRequestInfo(sphinxRequestInfo);
78 
79  SharedPtr<SphinxResultData> trancatedResult = sphinxResultTrancater.trancate(sphinxResultData);
80 
81  ASSERT_TRUE(isEqualSphinxResultData(*trancatedResult.get(),
82  *sphinxResultData.get()));
83 }
84 
85 
86 TEST_F(SphinxResultTrancaterTest, correctTruncateEqualResultThanNeedToBeStored)
87 {
88  SphinxResultTruncater sphinxResultTrancater;
89 
90  sphinxRequestInfo.setMaxResultsNumber(5);
91  sphinxResultData->addRequestInfo(sphinxRequestInfo);
92 
93  SharedPtr<SphinxResultData> trancatedResult = sphinxResultTrancater.trancate(sphinxResultData);
94 
95  ASSERT_TRUE(isEqualSphinxResultData(*trancatedResult.get(),
96  *sphinxResultData.get()));
97 }