hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxReduceResultTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxReduceResultTest.cpp
3  *
4  * Created on: May 2, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
9 #include "SphinxReduceResult.hpp"
10 #include <vector>
11 
12 using namespace HCE::sphinx::reduce_task;
13 using namespace std;
14 
15 TEST(SphinxReduceResult, emptyResult)
16 {
17  SphinxReduceResult sphinxReduceResult;
18 
19  ASSERT_TRUE(sphinxReduceResult.hasNext() == false);
20 }
21 
22 
23 class SphinxReduceResultTest: public ::testing::Test{
24  protected:
25  virtual void SetUp(){
26  idWeightResult.push_back(make_pair("14", "12345"));
27  idWeightResult.push_back(make_pair("7", "256789"));
28  idWeightResult.push_back(make_pair("21", "1122334"));
29  }
30 
31  vector<pair<string, string> > idWeightResult;
32  string expectId;
33  string expectWeight;
34 };
35 
37 {
38  SphinxReduceResult sphinxReduceResult;
39 
40  sphinxReduceResult.addKeyValue(idWeightResult[0].first, idWeightResult[0].second);
41 
42  sphinxReduceResult.reset();
43  ASSERT_TRUE(sphinxReduceResult.hasNext());
44 
45  sphinxReduceResult.getNext(expectId, expectWeight);
46  EXPECT_EQ(idWeightResult[0].first, expectId);
47  EXPECT_EQ(idWeightResult[0].second, expectWeight);
48 
49  EXPECT_TRUE(sphinxReduceResult.hasNext() == false);
50 }
51 
53 {
54  SphinxReduceResult sphinxReduceResult;
55  for (size_t resIndex = 0; resIndex < idWeightResult.size(); ++resIndex){
56  sphinxReduceResult.addKeyValue(idWeightResult[resIndex].first,
57  idWeightResult[resIndex].second);
58  }
59 
60  unsigned int docsNumber = 0;
61  sphinxReduceResult.reset();
62  while(sphinxReduceResult.hasNext()){
63  sphinxReduceResult.getNext(expectId, expectWeight);
64  EXPECT_EQ(idWeightResult[docsNumber].first, expectId);
65  EXPECT_EQ(idWeightResult[docsNumber].second, expectWeight);
66  docsNumber++;
67  }
68 
69  ASSERT_EQ(docsNumber, idWeightResult.size());
70 }