ProteoWizard
basetest.cpp
Go to the documentation of this file.
1 //
2 // $Id: basetest.cpp 5313 2013-12-17 18:06:54Z chambm $
3 //
4 //
5 // Original author: Witold Wolski <wewolski@gmail.com>
6 //
7 // Copyright : ETH Zurich
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
22 #include <boost/cstdint.hpp>
23 
26 
27 namespace {
28  using namespace pwiz::util;
29  typedef boost::int32_t int32_t;
30  // Tests that the Foo::Bar() method does Abc.
31  void testseq() {
32  std::vector<double> res;
33  ralab::base::base::seq(1.,10.,0.5,res);
34  ralab::base::base::seq(10.,2.,res);
35  ralab::base::base::seq(2.,10.,res);
36  ralab::base::base::seq(10., 2. , -0.5 , res);
37 
38  std::vector<int32_t> res2;
39  ralab::base::base::seq(10,2,res2);
40  ralab::base::base::seq(10,res);
41  ralab::base::base::seq(res2,res);
42 
43  std::vector<unsigned int> resunsigned;
44  ralab::base::base::seq(1u,10u,1u,resunsigned);
45  ralab::base::base::seq(1u,10u,resunsigned);
46 
47  std::vector<double> resdouble;
48  ralab::base::base::seq_length(100. , 1300.,18467,resdouble);
49  unit_assert(resdouble.size() == 18467);
50  ralab::base::base::seq_length(100. , 1300.,19467,resdouble);
51  unit_assert(resdouble.size() == 19467);
52 
53  ralab::base::base::seq_length(0.,1000.,1000,resdouble);
54  unit_assert(resdouble.size() == 1000);
55  }
56 
57  // Tests that Foo does Xyz.
58  void testmean() {
59  std::vector<double> x;
60  x.push_back(1.0);
61  x.push_back(1.0);
62  x.push_back(1.0);
63  x.push_back(1.);
64  x.push_back(2.);
65  x.push_back(3.);
66  x.push_back(5.);
67  x.push_back(5.);
68  x.push_back(6.);
69  x.push_back(7.);
70  x.push_back(8.);
71  double res = ralab::base::base::mean(x);
72  unit_assert_equal ( 3.636364, res, 1e-4);
73  res = ralab::base::base::mean(x, 0.3);
74  unit_assert_equal ( 3.2, res, 1e-4);
75  res = ralab::base::base::mean(x, 0.4);
76  unit_assert_equal ( 3.33333, res, 1e-4);
77  res = ralab::base::base::mean(x, 0.5);
78  std::cout << res << std::endl;
79  unit_assert_equal ( 3., res, 1e-4);
80  res = ralab::base::base::mean(x.begin(),x.end());
81  unit_assert_equal ( 3.636364, res, 1e-4);
82 
83  }
84 
85  void testgeometricmean(){
86  std::vector<double> x;
87  x.push_back(1.0);
88  x.push_back(2.0);
89  x.push_back(3.0);
90 
91  double res = ralab::base::base::geometricMean(x.begin(), x.end());
92  unit_assert_equal( 1.817121, res, 1e-4 );
93 
94  }
95 } // namespace
96 
97 int main(int argc, char **argv) {
98  testseq();
99 testmean();
100 testgeometricmean();
101 }
std::iterator_traits< InputIterator >::value_type mean(InputIterator begin, InputIterator end)
MEAN Trimmed arithmetic mean.
Definition: base.hpp:187
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
void seq(TReal from, TReal to, std::vector< TReal > &result)
generates the sequence from, from+/-1, ..., to (identical to from:to).
Definition: base.hpp:49
boost::int32_t int32_t
Definition: bin1d.hpp:40
void seq_length(TReal from, TReal to, unsigned int length, std::vector< TReal > &result)
generates sequence: from, to of length calls seq with $[ by = ( ( to - from ) / ( length - 1...
Definition: base.hpp:111
std::iterator_traits< Iter_T >::value_type geometricMean(Iter_T first, Iter_T last)
computes the mean
Definition: base.hpp:229
KernelTraitsBase< Kernel >::space_type::abscissa_type x
int main(int argc, char **argv)
Definition: basetest.cpp:97
#define unit_assert(x)
Definition: unit.hpp:85