-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathranker_test.h
90 lines (75 loc) · 2.01 KB
/
ranker_test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
This file is part of the MiLi Minimalistic Library.
Copyright (C) Hugo Arregui, Emmanuel Teisaire, FuDePAN 2011
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt in the root directory or
copy at http://www.boost.org/LICENSE_1_0.txt)
MiLi IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
This is a test file.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "mili/mili.h"
using std::string;
using namespace mili;
struct Player
{
string name;
float score;
Player(string name, float score)
: name(name),
score(score)
{}
bool operator==(const Player& aPlayer) const
{
return name == aPlayer.name;
}
};
/* Compare two Players' names */
struct PlayerUnique
{
bool operator()(const Player& p1, const Player& p2)
{
return p1.name > p2.name;
}
};
/* Compare two Players' scores */
struct PlayerRanking
{
bool operator()(const Player& p1, const Player& p2)
{
return p1.score > p2.score;
}
};
template <class T>
struct PlayerPointerAdapter
{
bool operator()(const Player* const p1, const Player* const p2)
{
T c;
return p1 != NULL && p2 != NULL && c.operator()(*p1, *p2);
}
};
template <class ScoreT, class T>
struct GetScore
{};
template<class T, class Iterator>
bool isSorted(Iterator it)
{
GetScore<T, Iterator> f;
bool sorted = true;
T score = f(it);
while (!it.end() && sorted)
{
sorted = (score >= f(it));
score = f(it);
++it;
}
return sorted;
}