1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Timo Sachsenberg $
25
// $Authors: Marc Sturm $
26
// --------------------------------------------------------------------------
28
#include <OpenMS/CONCEPT/ClassTest.h>
30
///////////////////////////
32
#include <OpenMS/VISUAL/MultiGradient.h>
33
#include <QtGui/QColor>
34
#include <OpenMS/CONCEPT/Types.h>
35
///////////////////////////
37
using namespace OpenMS;
40
START_TEST(MultiGradient, "$Id: MultiGradient_test.C 8544 2011-08-03 07:50:10Z aiche $")
42
/////////////////////////////////////////////////////////////
43
/////////////////////////////////////////////////////////////
45
MultiGradient* d10_ptr = 0;
46
MultiGradient* d10_nullPointer = 0;
47
START_SECTION((MultiGradient()))
48
d10_ptr = new MultiGradient();
49
TEST_NOT_EQUAL(d10_ptr, d10_nullPointer)
52
START_SECTION((~MultiGradient()))
56
START_SECTION((InterpolationMode getInterpolationMode() const))
57
TEST_EQUAL(MultiGradient().getInterpolationMode(),MultiGradient::IM_LINEAR)
60
START_SECTION((void setInterpolationMode(InterpolationMode mode)))
62
mg.setInterpolationMode(MultiGradient::IM_STAIRS);
63
TEST_EQUAL(mg.getInterpolationMode(),MultiGradient::IM_STAIRS)
66
START_SECTION((Size size() const))
68
TEST_EQUAL(mg.size(),2);
71
START_SECTION((UInt position(UInt index)))
73
TEST_EQUAL(mg.position(0),0);
74
TEST_EQUAL(mg.position(1),100);
77
START_SECTION((QColor color(UInt index)))
79
TEST_EQUAL(mg.color(0)==Qt::white,true);
80
TEST_EQUAL(mg.color(1)==Qt::black,true);
83
START_SECTION((void insert(DoubleReal position, QColor color)))
85
mg.insert(50,Qt::red);
86
TEST_EQUAL(mg.size(),3);
87
TEST_EQUAL(mg.position(0),0);
88
TEST_EQUAL(mg.position(1),50);
89
TEST_EQUAL(mg.position(2),100);
90
TEST_EQUAL(mg.color(0)==Qt::white,true);
91
TEST_EQUAL(mg.color(1)==Qt::red,true);
92
TEST_EQUAL(mg.color(2)==Qt::black,true);
93
mg.insert(50,Qt::red);
94
TEST_EQUAL(mg.size(),3);
95
TEST_EQUAL(mg.position(0),0);
96
TEST_EQUAL(mg.position(1),50);
97
TEST_EQUAL(mg.position(2),100);
98
TEST_EQUAL(mg.color(0)==Qt::white,true);
99
TEST_EQUAL(mg.color(1)==Qt::red,true);
100
TEST_EQUAL(mg.color(2)==Qt::black,true);
101
mg.insert(25,Qt::green);
102
mg.insert(75,Qt::blue);
103
TEST_EQUAL(mg.size(),5);
104
TEST_EQUAL(mg.position(0),0);
105
TEST_EQUAL(mg.position(1),25);
106
TEST_EQUAL(mg.position(2),50);
107
TEST_EQUAL(mg.position(3),75);
108
TEST_EQUAL(mg.position(4),100);
109
TEST_EQUAL(mg.color(0)==Qt::white,true);
110
TEST_EQUAL(mg.color(1)==Qt::green,true);
111
TEST_EQUAL(mg.color(2)==Qt::red,true);
112
TEST_EQUAL(mg.color(3)==Qt::blue,true);
113
TEST_EQUAL(mg.color(4)==Qt::black,true);
114
mg.insert(76,Qt::magenta);
115
TEST_EQUAL(mg.size(),6);
116
TEST_EQUAL(mg.position(0),0);
117
TEST_EQUAL(mg.position(1),25);
118
TEST_EQUAL(mg.position(2),50);
119
TEST_EQUAL(mg.position(3),75);
120
TEST_EQUAL(mg.position(4),76);
121
TEST_EQUAL(mg.position(5),100);
122
TEST_EQUAL(mg.color(0)==Qt::white,true);
123
TEST_EQUAL(mg.color(1)==Qt::green,true);
124
TEST_EQUAL(mg.color(2)==Qt::red,true);
125
TEST_EQUAL(mg.color(3)==Qt::blue,true);
126
TEST_EQUAL(mg.color(4)==Qt::magenta,true);
127
TEST_EQUAL(mg.color(5)==Qt::black,true);
130
START_SECTION((bool remove(DoubleReal position)))
132
mg.insert(25,Qt::green);
133
mg.insert(50,Qt::red);
134
mg.insert(75,Qt::blue);
136
TEST_EQUAL(mg.size(),4);
137
TEST_EQUAL(mg.position(0),0);
138
TEST_EQUAL(mg.position(1),25);
139
TEST_EQUAL(mg.position(2),75);
140
TEST_EQUAL(mg.position(3),100);
141
TEST_EQUAL(mg.color(0)==Qt::white,true);
142
TEST_EQUAL(mg.color(1)==Qt::green,true);
143
TEST_EQUAL(mg.color(2)==Qt::blue,true);
144
TEST_EQUAL(mg.color(3)==Qt::black,true);
146
TEST_EQUAL(mg.size(),3);
147
TEST_EQUAL(mg.position(0),0);
148
TEST_EQUAL(mg.position(1),75);
149
TEST_EQUAL(mg.position(2),100);
150
TEST_EQUAL(mg.color(0)==Qt::white,true);
151
TEST_EQUAL(mg.color(1)==Qt::blue,true);
152
TEST_EQUAL(mg.color(2)==Qt::black,true);
154
TEST_EQUAL(mg.size(),2);
155
TEST_EQUAL(mg.position(0),0);
156
TEST_EQUAL(mg.position(1),100);
157
TEST_EQUAL(mg.color(0)==Qt::white,true);
158
TEST_EQUAL(mg.color(1)==Qt::black,true);
161
START_SECTION((bool exists(DoubleReal position)))
163
mg.insert(25,Qt::green);
164
mg.insert(50,Qt::red);
165
mg.insert(75,Qt::blue);
166
TEST_EQUAL(mg.exists(0),true);
167
TEST_EQUAL(mg.exists(1),false);
168
TEST_EQUAL(mg.exists(25),true);
169
TEST_EQUAL(mg.exists(49),false);
170
TEST_EQUAL(mg.exists(50),true);
171
TEST_EQUAL(mg.exists(51),false);
172
TEST_EQUAL(mg.exists(75),true);
173
TEST_EQUAL(mg.exists(99),false);
174
TEST_EQUAL(mg.exists(100),true);
177
START_SECTION((QColor interpolatedColorAt(DoubleReal position) const))
179
TEST_EQUAL(mg.interpolatedColorAt(0)==Qt::white,true);
180
TEST_EQUAL(mg.interpolatedColorAt(25)==QColor(191,191,191),true);
181
TEST_EQUAL(mg.interpolatedColorAt(50)==QColor(127,127,127),true);
182
TEST_EQUAL(mg.interpolatedColorAt(75)==QColor(63,63,63),true);
183
TEST_EQUAL(mg.interpolatedColorAt(100)==Qt::black,true);
184
mg.insert(50,Qt::red);
185
TEST_EQUAL(mg.interpolatedColorAt(0)==Qt::white,true);
186
TEST_EQUAL(mg.interpolatedColorAt(25)==QColor(255,127,127),true);
187
TEST_EQUAL(mg.interpolatedColorAt(50)==Qt::red,true);
188
TEST_EQUAL(mg.interpolatedColorAt(75)==QColor(127,0,0),true);
189
TEST_EQUAL(mg.interpolatedColorAt(100)==Qt::black,true);
190
mg.insert(50,Qt::green);
191
TEST_EQUAL(mg.interpolatedColorAt(0)==Qt::white,true);
192
TEST_EQUAL(mg.interpolatedColorAt(25)==QColor(127,255,127),true);
193
TEST_EQUAL(mg.interpolatedColorAt(50)==Qt::green,true);
194
TEST_EQUAL(mg.interpolatedColorAt(75)==QColor(0,127,0),true);
195
TEST_EQUAL(mg.interpolatedColorAt(100)==Qt::black,true);
196
mg.insert(50,Qt::blue);
197
TEST_EQUAL(mg.interpolatedColorAt(0)==Qt::white,true);
198
TEST_EQUAL(mg.interpolatedColorAt(25)==QColor(127,127,255),true);
199
TEST_EQUAL(mg.interpolatedColorAt(50)==Qt::blue,true);
200
TEST_EQUAL(mg.interpolatedColorAt(75)==QColor(0,0,127),true);
201
TEST_EQUAL(mg.interpolatedColorAt(100)==Qt::black,true);
204
mg2.setInterpolationMode(MultiGradient::IM_STAIRS);
205
TEST_EQUAL(mg2.interpolatedColorAt(0)==Qt::white,true);
206
TEST_EQUAL(mg2.interpolatedColorAt(25)==Qt::white,true);
207
TEST_EQUAL(mg2.interpolatedColorAt(100)==Qt::black,true);
208
mg2.insert(50,Qt::red);
209
TEST_EQUAL(mg2.interpolatedColorAt(0)==Qt::white,true);
210
TEST_EQUAL(mg2.interpolatedColorAt(49)==Qt::white,true);
211
TEST_EQUAL(mg2.interpolatedColorAt(50)==Qt::red,true);
212
TEST_EQUAL(mg2.interpolatedColorAt(51)==Qt::red,true);
213
TEST_EQUAL(mg2.interpolatedColorAt(99)==Qt::red,true);
214
TEST_EQUAL(mg2.interpolatedColorAt(100)==Qt::black,true);
217
START_SECTION((QColor interpolatedColorAt(DoubleReal position, DoubleReal min, DoubleReal max) const))
219
mg.insert(50,Qt::red);
220
TEST_EQUAL(mg.interpolatedColorAt(0,0,100)==Qt::white,true);
221
TEST_EQUAL(mg.interpolatedColorAt(25,0,100)==QColor(255,127,127),true);
222
TEST_EQUAL(mg.interpolatedColorAt(50,0,100)==Qt::red,true);
223
TEST_EQUAL(mg.interpolatedColorAt(75,0,100)==QColor(127,0,0),true);
224
TEST_EQUAL(mg.interpolatedColorAt(100,0,100)==Qt::black,true);
227
mg2.setInterpolationMode(MultiGradient::IM_STAIRS);
228
mg2.insert(50,Qt::red);
229
TEST_EQUAL(mg2.interpolatedColorAt(0)==Qt::white,true);
230
TEST_EQUAL(mg2.interpolatedColorAt(49)==Qt::white,true);
231
TEST_EQUAL(mg2.interpolatedColorAt(50)==Qt::red,true);
232
TEST_EQUAL(mg2.interpolatedColorAt(51)==Qt::red,true);
233
TEST_EQUAL(mg2.interpolatedColorAt(99)==Qt::red,true);
234
TEST_EQUAL(mg2.interpolatedColorAt(100)==Qt::black,true);
237
START_SECTION((void activatePrecalculationMode(DoubleReal min, DoubleReal max, UInt steps)))
241
START_SECTION((QColor precalculatedColorAt(DoubleReal position) const ))
243
mg.insert(0,Qt::white);
244
mg.insert(100,Qt::blue);
245
mg.activatePrecalculationMode(-50.0,50.0,100);
247
//Test precalclulated Values
248
TEST_EQUAL(mg.precalculatedColorAt(-50.0).red(),255);
249
TEST_EQUAL(mg.precalculatedColorAt(-50.0).green(),255);
250
TEST_EQUAL(mg.precalculatedColorAt(-50.0).blue(),255);
252
TEST_EQUAL(mg.precalculatedColorAt(-25.0).red(),193);
253
TEST_EQUAL(mg.precalculatedColorAt(-25.0).green(),193);
254
TEST_EQUAL(mg.precalculatedColorAt(-25.0).blue(),255);
256
TEST_EQUAL(mg.precalculatedColorAt(0.0).red(),128);
257
TEST_EQUAL(mg.precalculatedColorAt(0.0).green(),128);
258
TEST_EQUAL(mg.precalculatedColorAt(0.0).blue(),255);
260
TEST_EQUAL(mg.precalculatedColorAt(25.0).red(),64);
261
TEST_EQUAL(mg.precalculatedColorAt(25.0).green(),64);
262
TEST_EQUAL(mg.precalculatedColorAt(25.0).blue(),255);
264
TEST_EQUAL(mg.precalculatedColorAt(50.0).red(),2);
265
TEST_EQUAL(mg.precalculatedColorAt(50.0).green(),2);
266
TEST_EQUAL(mg.precalculatedColorAt(50.0).blue(),255);
269
START_SECTION((void deactivatePrecalculationMode()))
271
mg.activatePrecalculationMode(-50,50,100);
272
mg.deactivatePrecalculationMode();
276
START_SECTION((std::string toString() const))
278
TEST_EQUAL(mg.toString(),"Linear|0,#ffffff;100,#000000")
279
mg.setInterpolationMode(MultiGradient::IM_STAIRS);
280
mg.insert(50,Qt::red);
281
TEST_EQUAL(mg.toString(),"Stairs|0,#ffffff;50,#ff0000;100,#000000")
284
START_SECTION((void fromString(const std::string& gradient)))
286
mg.fromString("Linear|0,#ff0000;100,#000000");
287
TEST_EQUAL(mg.getInterpolationMode(),MultiGradient::IM_LINEAR)
288
TEST_EQUAL(mg.size(),2)
289
TEST_EQUAL(mg.color(0)==Qt::red, true);
290
TEST_EQUAL(mg.color(1)==Qt::black, true);
291
TEST_EQUAL(mg.position(0), 0);
292
TEST_EQUAL(mg.position(1), 100);
293
mg.fromString("Stairs|0,#ffffff;50,#ff0000;100,#000000");
294
TEST_EQUAL(mg.getInterpolationMode(),MultiGradient::IM_STAIRS)
295
TEST_EQUAL(mg.size(),3)
296
TEST_EQUAL(mg.color(0)==Qt::white, true);
297
TEST_EQUAL(mg.color(1)==Qt::red, true);
298
TEST_EQUAL(mg.color(2)==Qt::black, true);
299
TEST_EQUAL(mg.position(0), 0);
300
TEST_EQUAL(mg.position(1), 50);
301
TEST_EQUAL(mg.position(2), 100);
306
/////////////////////////////////////////////////////////////
307
/////////////////////////////////////////////////////////////