~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/TEST/InterpolationModel_test.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Clemens Groepl $
 
25
// $Authors: $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/CONCEPT/ClassTest.h>
 
29
 
 
30
///////////////////////////
 
31
 
 
32
#include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/InterpolationModel.h>
 
33
#include <OpenMS/CONCEPT/Exception.h>
 
34
 
 
35
 
 
36
///////////////////////////
 
37
 
 
38
using namespace OpenMS;
 
39
 
 
40
class TestModel : public InterpolationModel
 
41
{
 
42
  public:
 
43
  TestModel()
 
44
    : InterpolationModel()
 
45
  {
 
46
    setName(getProductName());
 
47
 
 
48
    check_defaults_ = false;
 
49
 
 
50
    defaultsToParam_();
 
51
  }
 
52
 
 
53
 
 
54
  TestModel(const TestModel& source)
 
55
    : InterpolationModel(source)
 
56
  {
 
57
    updateMembers_();
 
58
  }
 
59
 
 
60
  virtual ~TestModel()
 
61
  {
 
62
  }
 
63
 
 
64
  virtual TestModel& operator = (const TestModel& source)
 
65
  {
 
66
    if (&source == this) return *this;
 
67
 
 
68
    InterpolationModel::operator = (source);
 
69
    updateMembers_();
 
70
 
 
71
    return *this;
 
72
  }
 
73
 
 
74
  void updateMembers_()
 
75
  {
 
76
     InterpolationModel::updateMembers_();
 
77
  }
 
78
 
 
79
  IntensityType getIntensity(const PositionType& pos) const
 
80
  {
 
81
    return pos[0]*3.0;
 
82
  }
 
83
 
 
84
  IntensityType getIntensity(CoordinateType coord) const
 
85
  {
 
86
    return coord*3.0;
 
87
  }
 
88
 
 
89
  bool isContained(const PositionType& pos) const
 
90
  {
 
91
    return getIntensity(pos)>cut_off_;
 
92
  }
 
93
 
 
94
  void  fillIntensity(PeakType& peak) const
 
95
  {
 
96
    peak.setIntensity(getIntensity(peak.getPosition()));
 
97
  }
 
98
 
 
99
  void getSamples(SamplesType& /*cont*/) const
 
100
  {
 
101
  }
 
102
 
 
103
  void setSamples()
 
104
  {
 
105
  }
 
106
 
 
107
  CoordinateType getCenter() const
 
108
  {
 
109
    return 10.0;
 
110
  }
 
111
 
 
112
  static const String getProductName()
 
113
  {
 
114
    return "TestModel";
 
115
  }
 
116
 
 
117
};
 
118
 
 
119
 
 
120
START_TEST(InterpolationModel , "$Id: InterpolationModel_test.C 8210 2011-03-28 13:19:52Z aiche $")
 
121
 
 
122
/////////////////////////////////////////////////////////////
 
123
/////////////////////////////////////////////////////////////
 
124
 
 
125
using std::stringstream;
 
126
 
 
127
//////////////////////////////////////
 
128
 
 
129
// default ctor
 
130
TestModel* ptr = 0;
 
131
TestModel* nullPointer = 0;
 
132
START_SECTION((InterpolationModel()))
 
133
        ptr = new TestModel();
 
134
        TEST_NOT_EQUAL(ptr, nullPointer)
 
135
END_SECTION
 
136
 
 
137
// destructor
 
138
START_SECTION((virtual ~InterpolationModel()))
 
139
        delete ptr;
 
140
END_SECTION
 
141
 
 
142
// assignment operator
 
143
START_SECTION((virtual InterpolationModel& operator=(const InterpolationModel &source)))
 
144
        TestModel tm1;
 
145
  TestModel tm2;
 
146
 
 
147
  tm1.setCutOff(3.3);
 
148
  tm2 = tm1;
 
149
        TEST_REAL_SIMILAR(tm1.getCutOff(),tm2.getCutOff())
 
150
        TEST_REAL_SIMILAR(tm1.getScalingFactor(),tm2.getScalingFactor())
 
151
END_SECTION
 
152
 
 
153
// copy constructor
 
154
START_SECTION((InterpolationModel(const InterpolationModel &source)))
 
155
        TestModel fp1;
 
156
  fp1.setCutOff(0.1);
 
157
 
 
158
  TestModel fp2(fp1);
 
159
 
 
160
  TestModel fp3;
 
161
  fp3.setCutOff(0.1);
 
162
 
 
163
  fp1 = TestModel();
 
164
        TEST_EQUAL(fp2==fp3, true)
 
165
END_SECTION
 
166
 
 
167
START_SECTION(([EXTRA]IntensityType getCutOff() const))
 
168
  const TestModel s;
 
169
  TEST_REAL_SIMILAR(s.getCutOff(), TestModel::IntensityType(0))
 
170
END_SECTION
 
171
 
 
172
START_SECTION(([EXTRA]void setCutOff(IntensityType cut_off)))
 
173
        TestModel s;
 
174
        s.setCutOff(4.4);
 
175
  TEST_REAL_SIMILAR(s.getCutOff(), 4.4)
 
176
END_SECTION
 
177
 
 
178
START_SECTION(([EXTRA]const String& getName() const))
 
179
        TestModel s;
 
180
  TEST_EQUAL(s.getName(), "TestModel")
 
181
END_SECTION
 
182
 
 
183
START_SECTION((IntensityType getIntensity(const PositionType& pos) const))
 
184
        const TestModel s;
 
185
  TestModel::PositionType pos;
 
186
  pos[0]=0.1;
 
187
  TEST_REAL_SIMILAR(s.getIntensity(pos), 0.3)
 
188
END_SECTION
 
189
 
 
190
START_SECTION(([EXTRA]bool isContained(const PositionType& pos) const))
 
191
        TestModel s;
 
192
  s.setCutOff(0.9);
 
193
  TestModel::PositionType pos;
 
194
  pos[0]=0.1;
 
195
  const TestModel& t = s;
 
196
  TEST_EQUAL(t.isContained(pos), false)
 
197
END_SECTION
 
198
 
 
199
START_SECTION(([EXTRA]void fillIntensity(PeakType& peak) const))
 
200
        const TestModel t;
 
201
  TestModel::PeakType p;
 
202
  p.getPosition()[0]=0.1;
 
203
  p.setIntensity(0.1f);
 
204
  t.fillIntensity(p);
 
205
  TEST_REAL_SIMILAR(p.getIntensity(), 0.3)
 
206
END_SECTION
 
207
 
 
208
START_SECTION(([EXTRA]void  fillIntensities(PeakIterator beg, PeakIterator end) const))
 
209
        const TestModel t;
 
210
  std::vector< TestModel::PeakType > vec(4);
 
211
  for (Size i=0; i<4; ++i)
 
212
  {
 
213
                vec[i].setIntensity(-0.5);
 
214
                vec[i].getPosition()[0] = i;
 
215
        }
 
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)
 
221
END_SECTION
 
222
 
 
223
START_SECTION( virtual CoordinateType getCenter() const)
 
224
        const TestModel t;
 
225
 TEST_REAL_SIMILAR(t.getCenter(),10.0);
 
226
END_SECTION
 
227
 
 
228
START_SECTION([EXTRA] DefaultParmHandler::setParameters(...))
 
229
        Param p;
 
230
        p.setValue("cutoff",17.0);
 
231
        TestModel m;
 
232
        m.setParameters(p);
 
233
        TEST_REAL_SIMILAR(m.getParameters().getValue("cutoff"), 17.0)
 
234
END_SECTION
 
235
 
 
236
START_SECTION( void setScalingFactor(CoordinateType scaling) )
 
237
        TestModel tm;
 
238
        tm.setScalingFactor(2.0);
 
239
 
 
240
        TEST_REAL_SIMILAR(tm.getParameters().getValue("intensity_scaling"),2.0)
 
241
        TEST_REAL_SIMILAR(tm.getScalingFactor(),2.0)
 
242
END_SECTION
 
243
 
 
244
START_SECTION( void setInterpolationStep(CoordinateType interpolation_step) )
 
245
        TestModel tm;
 
246
        tm.setInterpolationStep( 10.5 );
 
247
 
 
248
        TEST_REAL_SIMILAR(tm.getParameters().getValue("interpolation_step"), 10.5 )
 
249
END_SECTION
 
250
 
 
251
START_SECTION( virtual void setSamples() )
 
252
        // not much to be tested here
 
253
END_SECTION
 
254
 
 
255
START_SECTION( void getSamples(SamplesType &cont) const )
 
256
        // not much to be tested here
 
257
END_SECTION
 
258
 
 
259
START_SECTION( virtual void setOffset(CoordinateType offset) )
 
260
 
 
261
END_SECTION
 
262
 
 
263
START_SECTION( CoordinateType getScalingFactor() const )
 
264
        TestModel tm;
 
265
        tm.setScalingFactor(666.0);
 
266
 
 
267
        TEST_REAL_SIMILAR(tm.getParameters().getValue("intensity_scaling"),666.0)
 
268
        TEST_REAL_SIMILAR(tm.getScalingFactor(),666.0)
 
269
END_SECTION
 
270
 
 
271
START_SECTION( const LinearInterpolation& getInterpolation() const )
 
272
        TestModel tm;
 
273
        InterpolationModel::LinearInterpolation interpol1;
 
274
        InterpolationModel::LinearInterpolation interpol2 = tm.getInterpolation();
 
275
 
 
276
        // compare models
 
277
        TEST_REAL_SIMILAR(interpol1.getScale(), interpol2.getScale());
 
278
        TEST_REAL_SIMILAR(interpol1.getInsideReferencePoint(), interpol2.getInsideReferencePoint());
 
279
        TEST_REAL_SIMILAR(interpol1.getOutsideReferencePoint(), interpol2.getOutsideReferencePoint() );
 
280
 
 
281
END_SECTION
 
282
 
 
283
START_SECTION( IntensityType getIntensity(CoordinateType coord) const )
 
284
        const TestModel s;
 
285
  TestModel::PositionType pos;
 
286
  pos[0]=0.1;
 
287
  TEST_REAL_SIMILAR(s.getIntensity(pos), 0.3)
 
288
END_SECTION
 
289
 
 
290
/////////////////////////////////////////////////////////////
 
291
/////////////////////////////////////////////////////////////
 
292
END_TEST