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

« back to all changes in this revision

Viewing changes to source/TEST/LmaGaussModel_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/LmaGaussModel.h>
 
33
 
 
34
///////////////////////////
 
35
 
 
36
START_TEST(LmaGaussModel, "$Id: LmaGaussModel_test.C 8210 2011-03-28 13:19:52Z aiche $")
 
37
 
 
38
/////////////////////////////////////////////////////////////
 
39
/////////////////////////////////////////////////////////////
 
40
 
 
41
using namespace OpenMS;
 
42
using std::stringstream;
 
43
 
 
44
// default ctor
 
45
LmaGaussModel* ptr = 0;
 
46
LmaGaussModel* nullPointer = 0;
 
47
START_SECTION((LmaGaussModel()))
 
48
        ptr = new LmaGaussModel();
 
49
  TEST_EQUAL(ptr->getName(), "LmaGaussModel")
 
50
        TEST_NOT_EQUAL(ptr, nullPointer)
 
51
END_SECTION
 
52
 
 
53
// destructor
 
54
START_SECTION((virtual ~LmaGaussModel()))
 
55
        delete ptr;
 
56
END_SECTION
 
57
 
 
58
START_SECTION((static const String getProductName()))
 
59
        TEST_EQUAL(LmaGaussModel::getProductName(),"LmaGaussModel")
 
60
        TEST_EQUAL(LmaGaussModel().getName(),"LmaGaussModel")
 
61
END_SECTION
 
62
 
 
63
START_SECTION((static BaseModel<1>* create()))
 
64
        BaseModel<1>* ptr = LmaGaussModel::create();
 
65
        TEST_EQUAL(ptr->getName(), "LmaGaussModel")
 
66
        TEST_NOT_EQUAL(ptr, nullPointer)
 
67
END_SECTION
 
68
 
 
69
// assignment operator
 
70
START_SECTION((virtual LmaGaussModel& operator=(const LmaGaussModel &source)))
 
71
        LmaGaussModel lm1;
 
72
        lm1.setInterpolationStep(0.3);
 
73
 
 
74
        Param tmp;
 
75
        tmp.setValue("bounding_box:min", 678.9);
 
76
        tmp.setValue("bounding_box:max", 789.0);
 
77
        tmp.setValue("statistics:mean", 680.1 );
 
78
        tmp.setValue("statistics:variance",  2.0);
 
79
        tmp.setValue("lma:scale_factor", 1000000.0);
 
80
        tmp.setValue("lma:standard_deviation", 2.0);
 
81
        tmp.setValue("lma:expected_value", 680.0);
 
82
        lm1.setParameters(tmp);
 
83
 
 
84
        LmaGaussModel lm2;
 
85
        lm2 = lm1;
 
86
 
 
87
        LmaGaussModel lm3;
 
88
        lm3.setInterpolationStep(0.3);
 
89
        lm3.setParameters(tmp);
 
90
        
 
91
        TEST_EQUAL(lm3.getParameters(), lm2.getParameters())
 
92
END_SECTION
 
93
 
 
94
// copy ctor
 
95
START_SECTION((LmaGaussModel(const LmaGaussModel& source)))
 
96
        LmaGaussModel lm1;
 
97
        lm1.setInterpolationStep(0.3);
 
98
 
 
99
        Param tmp;
 
100
        tmp.setValue("bounding_box:min", 678.9);
 
101
        tmp.setValue("bounding_box:max", 789.0);
 
102
        tmp.setValue("statistics:mean", 680.1 );
 
103
        tmp.setValue("statistics:variance",  2.0);
 
104
        tmp.setValue("lma:scale_factor", 10.0);
 
105
        tmp.setValue("lma:standard_deviation", 2.0);
 
106
        tmp.setValue("lma:expected_value", 680.0);
 
107
        lm1.setParameters(tmp);
 
108
 
 
109
        LmaGaussModel lm2(lm1);
 
110
        LmaGaussModel lm3;
 
111
        lm3.setInterpolationStep(0.3);
 
112
        lm3.setParameters(tmp);
 
113
 
 
114
        TEST_EQUAL(lm3.getParameters(), lm2.getParameters())
 
115
END_SECTION
 
116
 
 
117
START_SECTION([EXTRA] DefaultParamHandler::setParameters(...))
 
118
        TOLERANCE_ABSOLUTE(0.001)
 
119
        LmaGaussModel lm1;
 
120
        
 
121
        Param tmp;
 
122
        tmp.setValue("bounding_box:min", 678.9);
 
123
        tmp.setValue("bounding_box:max", 680.9);
 
124
        tmp.setValue("statistics:mean", 679.1 );
 
125
        tmp.setValue("statistics:variance",  2.0);
 
126
        tmp.setValue("lma:scale_factor", 10.0);
 
127
        tmp.setValue("lma:standard_deviation", 2.0);
 
128
        tmp.setValue("lma:expected_value", 700.0);
 
129
        lm1.setParameters(tmp);
 
130
        lm1.setOffset(680.0);
 
131
 
 
132
        TEST_REAL_SIMILAR(lm1.getCenter(), 680.2)
 
133
 
 
134
        LmaGaussModel lm2;
 
135
        lm2.setParameters(lm1.getParameters());
 
136
 
 
137
        std::vector<Peak1D> dpa1;
 
138
        std::vector<Peak1D> dpa2;
 
139
        lm1.getSamples(dpa1);
 
140
        lm2.getSamples(dpa2);
 
141
 
 
142
        TOLERANCE_ABSOLUTE(0.0001)
 
143
        TEST_EQUAL(dpa1.size(),dpa2.size())
 
144
        ABORT_IF(dpa1.size()!=dpa2.size());
 
145
        for (Size i=0; i<dpa1.size(); ++i)
 
146
        {
 
147
                TEST_REAL_SIMILAR(dpa1[i].getPosition()[0],dpa2[i].getPosition()[0])
 
148
                TEST_REAL_SIMILAR(dpa1[i].getIntensity(),dpa2[i].getIntensity())
 
149
        }
 
150
END_SECTION
 
151
 
 
152
START_SECTION([EXTRA] DefaultParamHandler::setParameters(...))
 
153
        LmaGaussModel lm1;
 
154
        
 
155
        Param tmp;
 
156
        tmp.setValue("bounding_box:min", -1.0);
 
157
        tmp.setValue("bounding_box:max", 4.0);
 
158
        tmp.setValue("statistics:mean", 0.0 );
 
159
        tmp.setValue("statistics:variance",  0.1);
 
160
        tmp.setValue("lma:scale_factor", 1.0);
 
161
        tmp.setValue("lma:standard_deviation", 2.0);
 
162
        tmp.setValue("lma:expected_value", 3.0);
 
163
        lm1.setParameters(tmp);
 
164
 
 
165
        TEST_REAL_SIMILAR(lm1.getCenter(), 0.0)
 
166
 
 
167
        TOLERANCE_ABSOLUTE(0.001)
 
168
        TEST_REAL_SIMILAR(lm1.getIntensity(-1.0), 0.0269955);
 
169
        TEST_REAL_SIMILAR(lm1.getIntensity(0.0), 0.0647588);
 
170
        TEST_REAL_SIMILAR(lm1.getIntensity(1.0), 0.120985);
 
171
        TEST_REAL_SIMILAR(lm1.getIntensity(2.0), 0.176033);
 
172
 
 
173
        lm1.setInterpolationStep(0.2);
 
174
        lm1.setSamples();
 
175
 
 
176
        TEST_REAL_SIMILAR(lm1.getIntensity(-1.0), 0.0269955);
 
177
        TEST_REAL_SIMILAR(lm1.getIntensity(0.0), 0.0647588);
 
178
        TEST_REAL_SIMILAR(lm1.getIntensity(1.0), 0.120985);
 
179
        TEST_REAL_SIMILAR(lm1.getIntensity(2.0), 0.176033);
 
180
 
 
181
        TOLERANCE_ABSOLUTE(0.1)
 
182
        tmp.setValue("lma:scale_factor", 10.0);
 
183
        lm1.setParameters(tmp);
 
184
        lm1.setSamples();
 
185
        
 
186
        TEST_REAL_SIMILAR(lm1.getIntensity(-1.0), 0.269955);
 
187
        TEST_REAL_SIMILAR(lm1.getIntensity(0.0), 0.647588);
 
188
        TEST_REAL_SIMILAR(lm1.getIntensity(1.0), 1.20985);
 
189
        TEST_REAL_SIMILAR(lm1.getIntensity(2.0), 1.76033);
 
190
END_SECTION
 
191
 
 
192
START_SECTION((void setOffset(CoordinateType offset)))
 
193
 
 
194
        LmaGaussModel lm1;
 
195
 
 
196
        Param tmp;
 
197
        tmp.setValue("bounding_box:min", 678.9);
 
198
        tmp.setValue("bounding_box:max", 789.0);
 
199
        tmp.setValue("statistics:mean", 680.1 );
 
200
        tmp.setValue("statistics:variance",  2.0);
 
201
        tmp.setValue("lma:scale_factor", 10.0);
 
202
        tmp.setValue("lma:standard_deviation", 2.0);
 
203
        tmp.setValue("lma:expected_value", 700.0);
 
204
        lm1.setParameters(tmp);
 
205
        lm1.setOffset(680.9);
 
206
 
 
207
        LmaGaussModel lm2;
 
208
        lm2.setParameters(tmp);
 
209
        lm2.setOffset(680.9);
 
210
 
 
211
        TEST_EQUAL(lm1.getParameters(), lm2.getParameters())
 
212
        TEST_REAL_SIMILAR(lm1.getCenter(), lm2.getCenter())
 
213
        TEST_REAL_SIMILAR(lm1.getCenter(), 682.1)
 
214
 
 
215
        std::vector<Peak1D> dpa1;
 
216
        std::vector<Peak1D> dpa2;
 
217
        lm1.getSamples(dpa1);
 
218
        lm2.getSamples(dpa2);
 
219
 
 
220
        TOLERANCE_ABSOLUTE(0.01)
 
221
        TEST_EQUAL(dpa1.size(),dpa2.size())
 
222
        ABORT_IF(dpa1.size()!=dpa2.size());
 
223
        for (Size i=0; i<dpa1.size(); ++i)
 
224
        {
 
225
                TEST_REAL_SIMILAR(dpa1[i].getPosition()[0],dpa2[i].getPosition()[0])
 
226
                TEST_REAL_SIMILAR(dpa1[i].getIntensity(),dpa2[i].getIntensity())
 
227
        }
 
228
 
 
229
END_SECTION
 
230
 
 
231
START_SECTION((CoordinateType getCenter() const))
 
232
        // already test above, but just for the sake of it
 
233
        TOLERANCE_ABSOLUTE(0.001)
 
234
        LmaGaussModel lm1;
 
235
        
 
236
        Param tmp;
 
237
        tmp.setValue("bounding_box:min", 678.9);
 
238
        tmp.setValue("bounding_box:max", 789.0);
 
239
        tmp.setValue("statistics:mean", 680.1 );
 
240
        tmp.setValue("statistics:variance",  2.0);
 
241
        tmp.setValue("lma:scale_factor", 10.0);
 
242
        tmp.setValue("lma:standard_deviation", 2.0);
 
243
        tmp.setValue("lma:expected_value", 700.0);      
 
244
        lm1.setParameters(tmp);
 
245
        lm1.setOffset(680.0);
 
246
 
 
247
        TEST_REAL_SIMILAR(lm1.getCenter(), 681.2)
 
248
 
 
249
END_SECTION
 
250
 
 
251
START_SECTION((void setSamples()))
 
252
{
 
253
  // dummy subtest
 
254
        TEST_EQUAL(1,1)
 
255
}
 
256
END_SECTION
 
257
 
 
258
 
 
259
/////////////////////////////////////////////////////////////
 
260
/////////////////////////////////////////////////////////////
 
261
END_TEST