hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxResultSortersTest.cpp
Go to the documentation of this file.
1 /*
2  * SphinxResultSortersTest.cpp
3  *
4  * Created on: Jun 11, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
12 
13 using namespace HCE::sphinx::reduce_task;
14 using namespace HCE::sphinx;
15 using namespace Poco;
16 using namespace std;
17 
18 class SphinxResultSortersTest: public ::testing::Test{
19  protected:
20  virtual void SetUp(){
21  expectedNullResult.push_back(make_pair( toHexString(111) + toHexString( 222 ), 7));
22  expectedNullResult.push_back(make_pair( toHexString(222) + toHexString( 111 ), 9));
23  expectedNullResult.push_back(make_pair( toHexString(222) + toHexString( 111 ), 11));
24  expectedNullResult.push_back(make_pair( toHexString(99) + toHexString( 444 ), 12));
25  expectedNullResult.push_back(make_pair( toHexString(444) + toHexString( 99 ), 13));
26 
27  expectedDescResult.push_back(make_pair( toHexString(444) + toHexString( 99 ), 13));
28  expectedDescResult.push_back(make_pair( toHexString(222) + toHexString( 111 ), 9));
29  expectedDescResult.push_back(make_pair( toHexString(222) + toHexString( 111 ), 11));
30  expectedDescResult.push_back(make_pair( toHexString(111) + toHexString( 222 ), 7));
31  expectedDescResult.push_back(make_pair( toHexString(99) + toHexString( 444 ), 12));
32 
33  expectedAscResult.push_back(make_pair(toHexString(99) + toHexString( 444 ), 12));
34  expectedAscResult.push_back(make_pair(toHexString(111) + toHexString( 222 ), 7));
35  expectedAscResult.push_back(make_pair(toHexString(222) + toHexString( 111 ), 9));
36  expectedAscResult.push_back(make_pair(toHexString(222) + toHexString( 111 ), 11));
37  expectedAscResult.push_back(make_pair(toHexString(444) + toHexString( 99 ), 13));
38 
39  initResult.insert(initResult.begin(), expectedNullResult.begin(),
40  expectedNullResult.end());
41  }
42 
43  virtual void TearDown(){
44  expectedAscResult.clear();
45  expectedDescResult.clear();
46  expectedNullResult.clear();
47  }
48 
49  vector<pair<string, unsigned long long> > initResult;
50  static vector<pair<string, unsigned long long> >expectedDescResult;
51  static vector<pair<string, unsigned long long> >expectedAscResult;
52  static vector<pair<string, unsigned long long> >expectedNullResult;
53 };
54 vector<pair<string, unsigned long long> >SphinxResultSortersTest::expectedDescResult;
55 vector<pair<string, unsigned long long> >SphinxResultSortersTest::expectedAscResult;
56 vector<pair<string, unsigned long long> >SphinxResultSortersTest::expectedNullResult;
57 
58 
59 TEST_F(SphinxResultSortersTest, dontSortResourcesByWeight)
60 {
61  SphinxResultNullSorter sphinxResultNullSorter;
62 
63  sphinxResultNullSorter.sortByWeight(initResult);
64 
65  ASSERT_EQ(initResult, expectedNullResult);
66 }
67 
68 
69 TEST_F(SphinxResultSortersTest, sortResourcesByWeightDesc)
70 {
71  SphinxResultDescSorter sphinxResultDescSorter;
72 
73  sphinxResultDescSorter.sortByWeight(initResult);
74 
75  ASSERT_EQ(initResult, expectedDescResult);
76 }
77 
78 
79 TEST_F(SphinxResultSortersTest, sortResourcesByWeightAsc)
80 {
81  SphinxResultAscSorter sphinxResultAscSorter;
82 
83  sphinxResultAscSorter.sortByWeight(initResult);
84 
85  ASSERT_EQ(initResult, expectedAscResult);
86 }
87