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

« back to all changes in this revision

Viewing changes to source/TEST/GammaDistributionFitter_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: Andreas Bertsch$
 
25
// $Authors: Andreas Bertsch $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/CONCEPT/ClassTest.h>
 
29
 
 
30
///////////////////////////
 
31
#include <OpenMS/MATH/STATISTICS/GammaDistributionFitter.h>
 
32
///////////////////////////
 
33
 
 
34
using namespace OpenMS;
 
35
using namespace Math;
 
36
using namespace std;
 
37
 
 
38
START_TEST(GammaDistributionFitter, "$Id: GammaDistributionFitter_test.C 8210 2011-03-28 13:19:52Z aiche $")
 
39
 
 
40
/////////////////////////////////////////////////////////////
 
41
/////////////////////////////////////////////////////////////
 
42
 
 
43
GammaDistributionFitter* ptr = 0;
 
44
GammaDistributionFitter* nullPointer = 0;
 
45
START_SECTION(GammaDistributionFitter())
 
46
{
 
47
        ptr = new GammaDistributionFitter();
 
48
        TEST_NOT_EQUAL(ptr, nullPointer)
 
49
}
 
50
END_SECTION
 
51
 
 
52
START_SECTION(virtual ~GammaDistributionFitter())
 
53
{
 
54
        delete ptr;
 
55
}
 
56
END_SECTION
 
57
 
 
58
START_SECTION((GammaDistributionFitResult fit(std::vector< DPosition< 2 > > & points)))
 
59
{
 
60
        DPosition<2> pos;
 
61
  vector<DPosition<2> > points;
 
62
 
 
63
        pos.setX(0.0001); pos.setY(0.1); points.push_back(pos);
 
64
        pos.setX(0.0251); pos.setY(0.3); points.push_back(pos);
 
65
        pos.setX(0.0501); pos.setY(0); points.push_back(pos);
 
66
        pos.setX(0.0751); pos.setY(0.7); points.push_back(pos);
 
67
        pos.setX(0.1001); pos.setY(0); points.push_back(pos);
 
68
        pos.setX(0.1251); pos.setY(1.6); points.push_back(pos);
 
69
        pos.setX(0.1501); pos.setY(0); points.push_back(pos);
 
70
        pos.setX(0.1751); pos.setY(2.1); points.push_back(pos);
 
71
        pos.setX(0.2001); pos.setY(0); points.push_back(pos);
 
72
        pos.setX(0.2251); pos.setY(3.7); points.push_back(pos);
 
73
        pos.setX(0.2501); pos.setY(0); points.push_back(pos);
 
74
        pos.setX(0.2751); pos.setY(4); points.push_back(pos);
 
75
        pos.setX(0.3001); pos.setY(0); points.push_back(pos);
 
76
        pos.setX(0.3251); pos.setY(3); points.push_back(pos);
 
77
        pos.setX(0.3501); pos.setY(0); points.push_back(pos);
 
78
        pos.setX(0.3751); pos.setY(2.6); points.push_back(pos);
 
79
        pos.setX(0.4001); pos.setY(0); points.push_back(pos);
 
80
        pos.setX(0.4251); pos.setY(3); points.push_back(pos);
 
81
        pos.setX(0.4501); pos.setY(0); points.push_back(pos);
 
82
        pos.setX(0.4751); pos.setY(3); points.push_back(pos);
 
83
        pos.setX(0.5001); pos.setY(0); points.push_back(pos);
 
84
        pos.setX(0.5251); pos.setY(2.5); points.push_back(pos);
 
85
        pos.setX(0.5501); pos.setY(0); points.push_back(pos);
 
86
        pos.setX(0.5751); pos.setY(1.7); points.push_back(pos);
 
87
        pos.setX(0.6001); pos.setY(0); points.push_back(pos);
 
88
        pos.setX(0.6251); pos.setY(1); points.push_back(pos);
 
89
        pos.setX(0.6501); pos.setY(0); points.push_back(pos);
 
90
        pos.setX(0.6751); pos.setY(0.5); points.push_back(pos);
 
91
        pos.setX(0.7001); pos.setY(0); points.push_back(pos);
 
92
        pos.setX(0.7251); pos.setY(0.3); points.push_back(pos);
 
93
        pos.setX(0.7501); pos.setY(0); points.push_back(pos);
 
94
        pos.setX(0.7751); pos.setY(0.4); points.push_back(pos);
 
95
        pos.setX(0.8001); pos.setY(0); points.push_back(pos);
 
96
        pos.setX(0.8251); pos.setY(0); points.push_back(pos);
 
97
        pos.setX(0.8501); pos.setY(0); points.push_back(pos);
 
98
        pos.setX(0.8751); pos.setY(0.1); points.push_back(pos);
 
99
        pos.setX(0.9001); pos.setY(0); points.push_back(pos);
 
100
        pos.setX(0.9251); pos.setY(0.1); points.push_back(pos);
 
101
        pos.setX(0.9501); pos.setY(0); points.push_back(pos);
 
102
        pos.setX(0.9751); pos.setY(0.2); points.push_back(pos);
 
103
 
 
104
        GammaDistributionFitter::GammaDistributionFitResult init_param;
 
105
        init_param.b = 1.0;
 
106
        init_param.p = 3.0;     
 
107
 
 
108
  ptr = new GammaDistributionFitter;
 
109
        ptr->setInitialParameters(init_param);
 
110
  GammaDistributionFitter::GammaDistributionFitResult result = ptr->fit(points);
 
111
 
 
112
  TOLERANCE_ABSOLUTE(0.01)
 
113
  TEST_REAL_SIMILAR(result.b, 7.25)
 
114
  TEST_REAL_SIMILAR(result.p, 3.11)
 
115
}
 
116
END_SECTION
 
117
 
 
118
START_SECTION((void setInitialParameters(const GammaDistributionFitResult & result)))
 
119
{
 
120
  GammaDistributionFitter f1;
 
121
  GammaDistributionFitter::GammaDistributionFitResult result;
 
122
  f1.setInitialParameters(result);
 
123
        
 
124
        NOT_TESTABLE //implicitly tested in fit method
 
125
}
 
126
END_SECTION
 
127
 
 
128
START_SECTION((const String& getGnuplotFormula() const ))
 
129
        TEST_EQUAL(ptr->getGnuplotFormula().hasPrefix("f(x)="), true)
 
130
END_SECTION
 
131
 
 
132
 
 
133
/////////////////////////////////////////////////////////////
 
134
/////////////////////////////////////////////////////////////
 
135
END_TEST
 
136
 
 
137
 
 
138