hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxResultTransformerTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxResultTransformerTest.cpp
3  *
4  * Created on: May 9, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
9 #include <gmock/gmock.h>
11 #include "SphinxResultData.hpp"
13 
14 using namespace HCE::sphinx;
15 using namespace HCE::sphinx::reduce_task;
16 using namespace Poco;
17 
18 using ::testing::ContainerEq;
19 
20 class SphinxResultTransformerTest: public ::testing::Test{
21  protected:
22  virtual void SetUp(){
23  nodeName = "node1";
24  query = "My query";
25  totalRes = 10;
26  totalFound = 2;
27  time = 1020;
28 
29  WordInfo word1 = WordInfo("word1", 10, 3);
30  WordInfo word2 = WordInfo("word2", 1, 1);
31 
32  SphinxMatchInfo matchInfo1 = buildSimpleMatchInfo(7LLU, 111LLU);
33  SphinxMatchInfo matchInfo2 = buildSimpleMatchInfo(9LLU, 222LLU);
34  SphinxMatchInfo matchInfo3 = buildSimpleMatchInfo(17LLU, 99LLU);
35  SphinxMatchInfo matchInfo4 = buildSimpleMatchInfo(9LLU, 444LLU);
36 
37  expectedWeightKeys.push_back(make_pair(toHexString(111LLU), 7LLU));
38  expectedWeightKeys.push_back(make_pair(toHexString(222LLU), 9LLU));
39  expectedWeightKeys.push_back(make_pair(toHexString(99LLU), 17LLU));
40  expectedWeightKeys.push_back(make_pair(toHexString(444LLU), 9LLU));
41 
42  AttrInfo attrInfo("first", "value");
43 
44  matchInfo1.addAttrInfo(attrInfo);
45  matchInfo2.addAttrInfo(attrInfo);
46  matchInfo3.addAttrInfo(attrInfo);
47  matchInfo4.addAttrInfo(attrInfo);
48 
49  SphinxRequestInfo sphinxRequestInfo;
50  sphinxRequestInfo.setQuery(query);
51  sphinxRequestInfo.setTotal(totalRes);
52  sphinxRequestInfo.setTotalFound(totalFound);
53  sphinxRequestInfo.setTimeMsec(time);
54  sphinxRequestInfo.addWordInfo(word1);
55  sphinxRequestInfo.addWordInfo(word2);
56 
57  sphinxResultData.assign(new SphinxResultData);
58  sphinxResultData->addMatchInfo(matchInfo1);
59  sphinxResultData->addMatchInfo(matchInfo2);
60  sphinxResultData->addMatchInfo(matchInfo3);
61  sphinxResultData->addMatchInfo(matchInfo4);
62  sphinxResultData->addRequestInfo(sphinxRequestInfo);
63  }
64 
65  SharedPtr<SphinxResultData> sphinxResultData;
66  vector<pair<string, unsigned long long> > expectedWeightKeys;
67  static string query;
68  static string nodeName;
69  static int totalRes;
70  static int totalFound;
71  static int time;
72 };
78 
79 
80 TEST_F(SphinxResultTransformerTest, emptyDataShouldExtractEmptyData)
81 {
82  SphinxResultTransformer sphinxResultTransformer;
83 
84  sphinxResultData.assign(new SphinxResultData);
85  vector<pair<string, unsigned long long> > weightKeys;
86 
87  sphinxResultTransformer.extractWeightKeys(sphinxResultData, weightKeys);
88 
89  ASSERT_EQ(weightKeys.size(), 0U);
90 }
91 
92 
93 TEST_F(SphinxResultTransformerTest, extractCorrectWeightKeysPairs)
94 {
95  SphinxResultTransformer sphinxResultTransformer;
96 
97  vector<pair<string, unsigned long long> > weightKeys;
98 
99  sphinxResultTransformer.extractWeightKeys(sphinxResultData, weightKeys);
100 
101  ASSERT_EQ(expectedWeightKeys, weightKeys);
102 }