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

« back to all changes in this revision

Viewing changes to source/TEST/EmgModel_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
 
 
29
#include <OpenMS/CONCEPT/ClassTest.h>
 
30
 
 
31
///////////////////////////
 
32
 
 
33
#include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/EmgModel.h>
 
34
#include <OpenMS/MATH/MISC/MathFunctions.h>
 
35
#include <boost/math/special_functions/fpclassify.hpp>
 
36
 
 
37
 
 
38
///////////////////////////
 
39
 
 
40
START_TEST(EmgModel, "$Id: EmgModel_test.C 8210 2011-03-28 13:19:52Z aiche $")
 
41
 
 
42
/////////////////////////////////////////////////////////////
 
43
/////////////////////////////////////////////////////////////
 
44
 
 
45
using namespace OpenMS;
 
46
using std::stringstream;
 
47
 
 
48
// default ctor
 
49
EmgModel* ptr = 0;
 
50
EmgModel* nullPointer = 0;
 
51
START_SECTION((EmgModel()))
 
52
        ptr = new EmgModel();
 
53
        TEST_EQUAL(ptr->getName(), "EmgModel")
 
54
        TEST_NOT_EQUAL(ptr, nullPointer)
 
55
END_SECTION
 
56
 
 
57
// destructor
 
58
START_SECTION((virtual ~EmgModel()))
 
59
        delete ptr;
 
60
END_SECTION
 
61
 
 
62
START_SECTION((static const String getProductName()))
 
63
        TEST_EQUAL(EmgModel::getProductName(),"EmgModel")
 
64
        TEST_EQUAL(EmgModel().getName(),"EmgModel")
 
65
END_SECTION
 
66
 
 
67
START_SECTION((static BaseModel<1>* create()))
 
68
        BaseModel<1>* ptr = EmgModel::create();
 
69
        TEST_EQUAL(ptr->getName(), "EmgModel")
 
70
        TEST_NOT_EQUAL(ptr, nullPointer)
 
71
END_SECTION
 
72
 
 
73
// assignment operator
 
74
START_SECTION((virtual EmgModel& operator=(const EmgModel &source)))
 
75
        EmgModel em1;
 
76
        em1.setInterpolationStep(0.2);
 
77
 
 
78
        Param tmp;
 
79
        tmp.setValue("bounding_box:min", 678.9);
 
80
        tmp.setValue("bounding_box:max", 789.0);
 
81
        tmp.setValue("statistics:mean", 680.1 );
 
82
        tmp.setValue("statistics:variance",  2.0);
 
83
        tmp.setValue("emg:height",100000.0);
 
84
        tmp.setValue("emg:width",5.0);
 
85
        tmp.setValue("emg:symmetry",5.0);
 
86
        tmp.setValue("emg:retention",725.0);
 
87
        em1.setParameters(tmp);
 
88
 
 
89
        EmgModel em2;
 
90
        em2 = em1;
 
91
        
 
92
        EmgModel em3;
 
93
        em3.setInterpolationStep(0.2);
 
94
        em3.setParameters(tmp);
 
95
  TEST_EQUAL(em3.getParameters(), em2.getParameters())
 
96
END_SECTION
 
97
 
 
98
// copy ctor
 
99
START_SECTION((EmgModel(const EmgModel& source)))
 
100
        EmgModel em1;
 
101
        em1.setInterpolationStep(0.2);
 
102
 
 
103
        Param tmp;
 
104
        tmp.setValue("bounding_box:min", 678.9);
 
105
        tmp.setValue("bounding_box:max", 789.0);
 
106
        tmp.setValue("statistics:mean", 680.1 );
 
107
        tmp.setValue("statistics:variance",  2.0);
 
108
        tmp.setValue("emg:height",100000.0);
 
109
        tmp.setValue("emg:width",5.0);
 
110
        tmp.setValue("emg:symmetry",5.0);
 
111
        tmp.setValue("emg:retention",725.0);
 
112
        em1.setParameters(tmp);
 
113
 
 
114
        EmgModel em2(em1);
 
115
        EmgModel em3;
 
116
        em3.setInterpolationStep(0.2);
 
117
        em3.setParameters(tmp);
 
118
 
 
119
        em1 = EmgModel();
 
120
        TEST_EQUAL(em3.getParameters(), em2.getParameters())
 
121
END_SECTION
 
122
 
 
123
 
 
124
START_SECTION([EXTRA] DefaultParamHandler::setParameters(...))
 
125
 
 
126
        TOLERANCE_ABSOLUTE(0.001)
 
127
        EmgModel em1;
 
128
 
 
129
        Param tmp;
 
130
        tmp.setValue("bounding_box:min", 678.9);
 
131
        tmp.setValue("bounding_box:max", 680.9);
 
132
        tmp.setValue("statistics:mean", 679.1 );
 
133
        tmp.setValue("statistics:variance",  2.0);
 
134
        tmp.setValue("emg:height", 100000.0);
 
135
        tmp.setValue("emg:width", 5.0);
 
136
        tmp.setValue("emg:symmetry", 5.0);
 
137
        tmp.setValue("emg:retention", 1200.0);
 
138
        em1.setParameters(tmp);
 
139
        em1.setOffset(680.0);
 
140
 
 
141
        TEST_REAL_SIMILAR(em1.getCenter(), 680.2)
 
142
 
 
143
        EmgModel em3;
 
144
        em3.setParameters(em1.getParameters());
 
145
 
 
146
        std::vector<Peak1D> dpa1;
 
147
        std::vector<Peak1D> dpa2;
 
148
        em1.getSamples(dpa1);
 
149
        em3.getSamples(dpa2);
 
150
 
 
151
        TOLERANCE_ABSOLUTE(0.0001)
 
152
        TEST_EQUAL(dpa1.size(),dpa2.size())
 
153
        ABORT_IF(dpa1.size()!=dpa2.size());
 
154
        for (Size i=0; i<dpa1.size(); ++i)
 
155
        {
 
156
                TEST_REAL_SIMILAR(dpa1[i].getPosition()[0],dpa2[i].getPosition()[0])
 
157
                TEST_REAL_SIMILAR(dpa1[i].getIntensity(),dpa2[i].getIntensity())
 
158
        }
 
159
 
 
160
        EmgModel em2;
 
161
        em2.setInterpolationStep(0.1);
 
162
 
 
163
        tmp.setValue("bounding_box:min", -1.0);
 
164
        tmp.setValue("bounding_box:max", 4.0);
 
165
        tmp.setValue("statistics:mean", 0.0 );
 
166
        tmp.setValue("statistics:variance",  0.1);
 
167
        tmp.setValue("emg:height", 10.0);
 
168
        tmp.setValue("emg:width", 1.0);
 
169
        tmp.setValue("emg:symmetry", 2.0);
 
170
        tmp.setValue("emg:retention", 3.0);
 
171
        em2.setParameters(tmp);
 
172
 
 
173
        TEST_REAL_SIMILAR(em2.getCenter(), 0.0)
 
174
 
 
175
        TOLERANCE_ABSOLUTE(0.01)
 
176
        TEST_REAL_SIMILAR(em2.getIntensity(-1.0), 0.0497198);
 
177
        TEST_REAL_SIMILAR(em2.getIntensity(0.0), 0.164882);
 
178
        TEST_REAL_SIMILAR(em2.getIntensity(1.0), 0.54166);
 
179
        TEST_REAL_SIMILAR(em2.getIntensity(2.0), 1.69364);
 
180
 
 
181
        em2.setInterpolationStep(0.2);
 
182
        em2.setSamples();
 
183
 
 
184
        TEST_REAL_SIMILAR(em2.getIntensity(-1.0), 0.0497198);
 
185
        TEST_REAL_SIMILAR(em2.getIntensity(0.0), 0.164882);
 
186
        TEST_REAL_SIMILAR(em2.getIntensity(1.0), 0.54166);
 
187
        TEST_REAL_SIMILAR(em2.getIntensity(2.0), 1.69364);
 
188
 
 
189
 
 
190
        // checked small values of parameter symmetry
 
191
        tmp.setValue("bounding_box:min", 0.0);
 
192
        tmp.setValue("bounding_box:max", 10.0);
 
193
        tmp.setValue("statistics:mean", 0.0 );
 
194
        tmp.setValue("statistics:variance",  0.1);
 
195
        tmp.setValue("emg:height", 10.0);
 
196
        tmp.setValue("emg:width", 6.0);
 
197
        tmp.setValue("emg:symmetry", 1.0);
 
198
        tmp.setValue("emg:retention", 3.0);
 
199
        em2.setParameters(tmp);
 
200
 
 
201
        TEST_REAL_SIMILAR(em2.getIntensity(2.0), 747203);
 
202
 
 
203
        tmp.setValue("emg:symmetry", 0.1);
 
204
        em2.setParameters(tmp);
 
205
        ABORT_IF(boost::math::isinf(em2.getIntensity(2.0)))
 
206
 
 
207
        tmp.setValue("emg:symmetry", 0.16);
 
208
        em2.setParameters(tmp);
 
209
        ABORT_IF(boost::math::isinf(em2.getIntensity(2.0)))
 
210
 
 
211
        tmp.setValue("emg:symmetry", 0.17);
 
212
        em2.setParameters(tmp);
 
213
        ABORT_IF(boost::math::isinf(float(!em2.getIntensity(2.0))))
 
214
 
 
215
        tmp.setValue("emg:symmetry", 0.2);
 
216
        em2.setParameters(tmp);
 
217
        ABORT_IF(!boost::math::isinf(em2.getIntensity(2.0)))
 
218
 
 
219
END_SECTION
 
220
 
 
221
START_SECTION((void setOffset(CoordinateType offset)))
 
222
        EmgModel em1;
 
223
        
 
224
        Param tmp;
 
225
        tmp.setValue("bounding_box:min", 678.9);
 
226
        tmp.setValue("bounding_box:max", 789.0);
 
227
        tmp.setValue("statistics:mean", 680.1 );
 
228
        tmp.setValue("statistics:variance",  2.0);
 
229
        tmp.setValue("emg:height", 100000.0);
 
230
        tmp.setValue("emg:width", 5.0);
 
231
        tmp.setValue("emg:symmetry", 5.0);
 
232
        tmp.setValue("emg:retention", 725.0);
 
233
        em1.setParameters(tmp);
 
234
        em1.setOffset(680.9);
 
235
 
 
236
        EmgModel em2;
 
237
        em2.setParameters(tmp);
 
238
        em2.setOffset(680.9);
 
239
 
 
240
        TEST_EQUAL(em1.getParameters(), em2.getParameters())
 
241
        TEST_REAL_SIMILAR(em1.getCenter(), em2.getCenter())
 
242
        TEST_REAL_SIMILAR(em1.getCenter(), 682.1)
 
243
 
 
244
        std::vector<Peak1D> dpa1;
 
245
        std::vector<Peak1D> dpa2;
 
246
        em1.getSamples(dpa1);
 
247
        em2.getSamples(dpa2);
 
248
 
 
249
        TOLERANCE_ABSOLUTE(0.01)
 
250
        TEST_EQUAL(dpa1.size(),dpa2.size())
 
251
        ABORT_IF(dpa1.size()!=dpa2.size());
 
252
        for (Size i=0; i<dpa1.size(); ++i)
 
253
        {
 
254
                TEST_REAL_SIMILAR(dpa1[i].getPosition()[0],dpa2[i].getPosition()[0])
 
255
                TEST_REAL_SIMILAR(dpa1[i].getIntensity(),dpa2[i].getIntensity())
 
256
        }
 
257
END_SECTION
 
258
 
 
259
START_SECTION((CoordinateType getCenter() const))
 
260
        TOLERANCE_ABSOLUTE(0.001)
 
261
        EmgModel em1;
 
262
        
 
263
        Param tmp;
 
264
        tmp.setValue("bounding_box:min",        678.9);
 
265
        tmp.setValue("bounding_box:max", 789.0);
 
266
        tmp.setValue("statistics:mean", 680.1 );
 
267
        tmp.setValue("statistics:variance",  2.0);
 
268
        tmp.setValue("emg:height",  100000.0);
 
269
        tmp.setValue("emg:width",  5.0);
 
270
        tmp.setValue("emg:symmetry",  5.0);
 
271
        tmp.setValue("emg:retention",  725.0);
 
272
        em1.setParameters(tmp);
 
273
        em1.setOffset(680.0);
 
274
        TEST_REAL_SIMILAR(em1.getCenter(), 681.2)
 
275
 
 
276
END_SECTION
 
277
 
 
278
START_SECTION((void setSamples()))
 
279
{
 
280
  // dummy subtest
 
281
        TEST_EQUAL(1,1)
 
282
}
 
283
END_SECTION
 
284
 
 
285
/////////////////////////////////////////////////////////////
 
286
/////////////////////////////////////////////////////////////
 
287
END_TEST