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: Clemens Groepl $
26
// --------------------------------------------------------------------------
28
#include <OpenMS/CONCEPT/ClassTest.h>
30
///////////////////////////
32
#include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/InterpolationModel.h>
33
#include <OpenMS/CONCEPT/Exception.h>
36
///////////////////////////
38
using namespace OpenMS;
40
class TestModel : public InterpolationModel
44
: InterpolationModel()
46
setName(getProductName());
48
check_defaults_ = false;
54
TestModel(const TestModel& source)
55
: InterpolationModel(source)
64
virtual TestModel& operator = (const TestModel& source)
66
if (&source == this) return *this;
68
InterpolationModel::operator = (source);
76
InterpolationModel::updateMembers_();
79
IntensityType getIntensity(const PositionType& pos) const
84
IntensityType getIntensity(CoordinateType coord) const
89
bool isContained(const PositionType& pos) const
91
return getIntensity(pos)>cut_off_;
94
void fillIntensity(PeakType& peak) const
96
peak.setIntensity(getIntensity(peak.getPosition()));
99
void getSamples(SamplesType& /*cont*/) const
107
CoordinateType getCenter() const
112
static const String getProductName()
120
START_TEST(InterpolationModel , "$Id: InterpolationModel_test.C 8210 2011-03-28 13:19:52Z aiche $")
122
/////////////////////////////////////////////////////////////
123
/////////////////////////////////////////////////////////////
125
using std::stringstream;
127
//////////////////////////////////////
131
TestModel* nullPointer = 0;
132
START_SECTION((InterpolationModel()))
133
ptr = new TestModel();
134
TEST_NOT_EQUAL(ptr, nullPointer)
138
START_SECTION((virtual ~InterpolationModel()))
142
// assignment operator
143
START_SECTION((virtual InterpolationModel& operator=(const InterpolationModel &source)))
149
TEST_REAL_SIMILAR(tm1.getCutOff(),tm2.getCutOff())
150
TEST_REAL_SIMILAR(tm1.getScalingFactor(),tm2.getScalingFactor())
154
START_SECTION((InterpolationModel(const InterpolationModel &source)))
164
TEST_EQUAL(fp2==fp3, true)
167
START_SECTION(([EXTRA]IntensityType getCutOff() const))
169
TEST_REAL_SIMILAR(s.getCutOff(), TestModel::IntensityType(0))
172
START_SECTION(([EXTRA]void setCutOff(IntensityType cut_off)))
175
TEST_REAL_SIMILAR(s.getCutOff(), 4.4)
178
START_SECTION(([EXTRA]const String& getName() const))
180
TEST_EQUAL(s.getName(), "TestModel")
183
START_SECTION((IntensityType getIntensity(const PositionType& pos) const))
185
TestModel::PositionType pos;
187
TEST_REAL_SIMILAR(s.getIntensity(pos), 0.3)
190
START_SECTION(([EXTRA]bool isContained(const PositionType& pos) const))
193
TestModel::PositionType pos;
195
const TestModel& t = s;
196
TEST_EQUAL(t.isContained(pos), false)
199
START_SECTION(([EXTRA]void fillIntensity(PeakType& peak) const))
201
TestModel::PeakType p;
202
p.getPosition()[0]=0.1;
203
p.setIntensity(0.1f);
205
TEST_REAL_SIMILAR(p.getIntensity(), 0.3)
208
START_SECTION(([EXTRA]void fillIntensities(PeakIterator beg, PeakIterator end) const))
210
std::vector< TestModel::PeakType > vec(4);
211
for (Size i=0; i<4; ++i)
213
vec[i].setIntensity(-0.5);
214
vec[i].getPosition()[0] = i;
216
t.fillIntensities(vec.begin()+1, vec.end()-1);
217
TEST_EQUAL(vec[0].getIntensity(), -0.5)
218
TEST_EQUAL(vec[1].getIntensity(), 3.0)
219
TEST_EQUAL(vec[2].getIntensity(), 6.0)
220
TEST_EQUAL(vec[3].getIntensity(), -0.5)
223
START_SECTION( virtual CoordinateType getCenter() const)
225
TEST_REAL_SIMILAR(t.getCenter(),10.0);
228
START_SECTION([EXTRA] DefaultParmHandler::setParameters(...))
230
p.setValue("cutoff",17.0);
233
TEST_REAL_SIMILAR(m.getParameters().getValue("cutoff"), 17.0)
236
START_SECTION( void setScalingFactor(CoordinateType scaling) )
238
tm.setScalingFactor(2.0);
240
TEST_REAL_SIMILAR(tm.getParameters().getValue("intensity_scaling"),2.0)
241
TEST_REAL_SIMILAR(tm.getScalingFactor(),2.0)
244
START_SECTION( void setInterpolationStep(CoordinateType interpolation_step) )
246
tm.setInterpolationStep( 10.5 );
248
TEST_REAL_SIMILAR(tm.getParameters().getValue("interpolation_step"), 10.5 )
251
START_SECTION( virtual void setSamples() )
252
// not much to be tested here
255
START_SECTION( void getSamples(SamplesType &cont) const )
256
// not much to be tested here
259
START_SECTION( virtual void setOffset(CoordinateType offset) )
263
START_SECTION( CoordinateType getScalingFactor() const )
265
tm.setScalingFactor(666.0);
267
TEST_REAL_SIMILAR(tm.getParameters().getValue("intensity_scaling"),666.0)
268
TEST_REAL_SIMILAR(tm.getScalingFactor(),666.0)
271
START_SECTION( const LinearInterpolation& getInterpolation() const )
273
InterpolationModel::LinearInterpolation interpol1;
274
InterpolationModel::LinearInterpolation interpol2 = tm.getInterpolation();
277
TEST_REAL_SIMILAR(interpol1.getScale(), interpol2.getScale());
278
TEST_REAL_SIMILAR(interpol1.getInsideReferencePoint(), interpol2.getInsideReferencePoint());
279
TEST_REAL_SIMILAR(interpol1.getOutsideReferencePoint(), interpol2.getOutsideReferencePoint() );
283
START_SECTION( IntensityType getIntensity(CoordinateType coord) const )
285
TestModel::PositionType pos;
287
TEST_REAL_SIMILAR(s.getIntensity(pos), 0.3)
290
/////////////////////////////////////////////////////////////
291
/////////////////////////////////////////////////////////////