~ubuntu-branches/ubuntu/trusty/presage/trusty-proposed

« back to all changes in this revision

Viewing changes to test/lib/core/meritocracyCombinerTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matteo Vescovi
  • Date: 2011-08-06 09:26:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110806092615-0wvhajaht9974ncx
Tags: upstream-0.8.6
ImportĀ upstreamĀ versionĀ 0.8.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************
 
3
 *  Presage, an extensible predictive text entry system
 
4
 *  ---------------------------------------------------
 
5
 *
 
6
 *  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
 
7
 
 
8
    This program is free software; you can redistribute it and/or modify
 
9
    it under the terms of the GNU General Public License as published by
 
10
    the Free Software Foundation; either version 2 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    This program is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU General Public License along
 
19
    with this program; if not, write to the Free Software Foundation, Inc.,
 
20
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
21
                                                                             *
 
22
                                                                **********(*)*/
 
23
 
 
24
 
 
25
#include "meritocracyCombinerTest.h"
 
26
 
 
27
CPPUNIT_TEST_SUITE_REGISTRATION( MeritocracyCombinerTest );
 
28
 
 
29
void MeritocracyCombinerTest::setUp()
 
30
{
 
31
    combiner = new MeritocracyCombiner();
 
32
 
 
33
    p1 = new Prediction();
 
34
    p1->addSuggestion(Suggestion("foo1", 1.0));
 
35
    p1->addSuggestion(Suggestion("foo2", 0.8));
 
36
    p1->addSuggestion(Suggestion("foo3", 0.6));
 
37
    p1->addSuggestion(Suggestion("foo4", 0.4));
 
38
    p1->addSuggestion(Suggestion("foo5", 0.2));
 
39
    p1->addSuggestion(Suggestion("foo6", 0.0));
 
40
                                           
 
41
    p2 = new Prediction();                 
 
42
    p2->addSuggestion(Suggestion("bar1", 0.9));
 
43
    p2->addSuggestion(Suggestion("bar2", 0.7));
 
44
    p2->addSuggestion(Suggestion("bar3", 0.5));
 
45
    p2->addSuggestion(Suggestion("bar4", 0.3));
 
46
    p2->addSuggestion(Suggestion("bar5", 0.1));
 
47
    p2->addSuggestion(Suggestion("bar6", 0.0));
 
48
    
 
49
    p3 = new Prediction();
 
50
    p3->addSuggestion(Suggestion("foobar1", 0.95));
 
51
    p3->addSuggestion(Suggestion("foobar2", 0.75));
 
52
    p3->addSuggestion(Suggestion("foobar3", 0.55));
 
53
    p3->addSuggestion(Suggestion("foobar4", 0.35));
 
54
    p3->addSuggestion(Suggestion("foobar5", 0.15));
 
55
    p3->addSuggestion(Suggestion("foobar6", 0.05));
 
56
 
 
57
    p12 = new Prediction();
 
58
    p12->addSuggestion(Suggestion("foo1", 1.0));
 
59
    p12->addSuggestion(Suggestion("foo2", 0.8));
 
60
    p12->addSuggestion(Suggestion("foo3", 0.6));
 
61
    p12->addSuggestion(Suggestion("foo4", 0.4));
 
62
    p12->addSuggestion(Suggestion("foo5", 0.2));
 
63
    p12->addSuggestion(Suggestion("foo6", 0.0));
 
64
    p12->addSuggestion(Suggestion("bar1", 0.9));
 
65
    p12->addSuggestion(Suggestion("bar2", 0.7));
 
66
    p12->addSuggestion(Suggestion("bar3", 0.5));
 
67
    p12->addSuggestion(Suggestion("bar4", 0.3));
 
68
    p12->addSuggestion(Suggestion("bar5", 0.1));
 
69
    p12->addSuggestion(Suggestion("bar6", 0.0));
 
70
    
 
71
    p13 = new Prediction();
 
72
    p13->addSuggestion(Suggestion("foo1", 1.0));
 
73
    p13->addSuggestion(Suggestion("foo2", 0.8));
 
74
    p13->addSuggestion(Suggestion("foo3", 0.6));
 
75
    p13->addSuggestion(Suggestion("foo4", 0.4));
 
76
    p13->addSuggestion(Suggestion("foo5", 0.2));
 
77
    p13->addSuggestion(Suggestion("foo6", 0.0));
 
78
    p13->addSuggestion(Suggestion("foobar1", 0.95));
 
79
    p13->addSuggestion(Suggestion("foobar2", 0.75));
 
80
    p13->addSuggestion(Suggestion("foobar3", 0.55));
 
81
    p13->addSuggestion(Suggestion("foobar4", 0.35));
 
82
    p13->addSuggestion(Suggestion("foobar5", 0.15));
 
83
    p13->addSuggestion(Suggestion("foobar6", 0.05));
 
84
 
 
85
    p23 = new Prediction();                
 
86
    p23->addSuggestion(Suggestion("bar1", 0.9));
 
87
    p23->addSuggestion(Suggestion("bar2", 0.7));
 
88
    p23->addSuggestion(Suggestion("bar3", 0.5));
 
89
    p23->addSuggestion(Suggestion("bar4", 0.3));
 
90
    p23->addSuggestion(Suggestion("bar5", 0.1));
 
91
    p23->addSuggestion(Suggestion("bar6", 0.0));
 
92
    p23->addSuggestion(Suggestion("foobar1", 0.95));
 
93
    p23->addSuggestion(Suggestion("foobar2", 0.75));
 
94
    p23->addSuggestion(Suggestion("foobar3", 0.55));
 
95
    p23->addSuggestion(Suggestion("foobar4", 0.35));
 
96
    p23->addSuggestion(Suggestion("foobar5", 0.15));
 
97
    p23->addSuggestion(Suggestion("foobar6", 0.05));
 
98
 
 
99
    p123 = new Prediction();
 
100
    p123->addSuggestion(Suggestion("foo1", 1.0));
 
101
    p123->addSuggestion(Suggestion("foo2", 0.8));
 
102
    p123->addSuggestion(Suggestion("foo3", 0.6));
 
103
    p123->addSuggestion(Suggestion("foo4", 0.4));
 
104
    p123->addSuggestion(Suggestion("foo5", 0.2));
 
105
    p123->addSuggestion(Suggestion("foo6", 0.0));
 
106
    p123->addSuggestion(Suggestion("bar1", 0.9));
 
107
    p123->addSuggestion(Suggestion("bar2", 0.7));
 
108
    p123->addSuggestion(Suggestion("bar3", 0.5));
 
109
    p123->addSuggestion(Suggestion("bar4", 0.3));
 
110
    p123->addSuggestion(Suggestion("bar5", 0.1));
 
111
    p123->addSuggestion(Suggestion("bar6", 0.0));
 
112
    p123->addSuggestion(Suggestion("foobar1", 0.95));
 
113
    p123->addSuggestion(Suggestion("foobar2", 0.75));
 
114
    p123->addSuggestion(Suggestion("foobar3", 0.55));
 
115
    p123->addSuggestion(Suggestion("foobar4", 0.35));
 
116
    p123->addSuggestion(Suggestion("foobar5", 0.15));
 
117
    p123->addSuggestion(Suggestion("foobar6", 0.05));
 
118
}
 
119
 
 
120
void MeritocracyCombinerTest::tearDown()
 
121
{
 
122
    delete combiner;
 
123
 
 
124
    delete p1;
 
125
    delete p2;
 
126
    delete p3;
 
127
 
 
128
    delete p12;
 
129
    delete p23;
 
130
    delete p13;
 
131
 
 
132
    delete p123;
 
133
}
 
134
 
 
135
void MeritocracyCombinerTest::testCombineSinglePrediction()
 
136
{
 
137
    std::vector< Prediction > predictions;
 
138
 
 
139
    predictions.push_back(*p1);
 
140
    CPPUNIT_ASSERT_EQUAL(*p1, combiner->combine(predictions));
 
141
    predictions.clear();
 
142
 
 
143
    predictions.push_back(*p2);
 
144
    CPPUNIT_ASSERT_EQUAL(*p2, combiner->combine(predictions));
 
145
    predictions.clear();
 
146
 
 
147
    predictions.push_back(*p3);
 
148
    CPPUNIT_ASSERT_EQUAL(*p3, combiner->combine(predictions));
 
149
    predictions.clear();
 
150
}
 
151
 
 
152
void MeritocracyCombinerTest::testCombineTwoPredictions()
 
153
{
 
154
    std::vector< Prediction > predictions;
 
155
 
 
156
    predictions.push_back(*p1);
 
157
    predictions.push_back(*p2);
 
158
    CPPUNIT_ASSERT_EQUAL(*p12, combiner->combine(predictions));
 
159
    predictions.clear();
 
160
 
 
161
    predictions.push_back(*p2);
 
162
    predictions.push_back(*p3);
 
163
    CPPUNIT_ASSERT_EQUAL(*p23, combiner->combine(predictions));
 
164
    predictions.clear();
 
165
 
 
166
    predictions.push_back(*p1);
 
167
    predictions.push_back(*p3);
 
168
    CPPUNIT_ASSERT_EQUAL(*p13, combiner->combine(predictions));
 
169
    predictions.clear();
 
170
}
 
171
 
 
172
void MeritocracyCombinerTest::testCombineThreePredictions()
 
173
{
 
174
    std::vector< Prediction > predictions;
 
175
    predictions.push_back(*p1);
 
176
    predictions.push_back(*p2);
 
177
    predictions.push_back(*p3);
 
178
    CPPUNIT_ASSERT_EQUAL(*p123, combiner->combine(predictions));
 
179
}