source: trunk/test/statistics_test.cc @ 1210

Last change on this file since 1210 was 1210, checked in by Peter, 14 years ago

refs #223 change fabs to std::abs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1// $Id: statistics_test.cc 1210 2008-03-06 16:00:44Z peter $
2
3/*
4  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2005 Peter Johansson
6  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
7
8  This file is part of the yat library, http://trac.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 2 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "yat/statistics/utility.h"
27#include "yat/utility/Vector.h"
28
29#include <vector>
30#include <cstdlib>
31#include <iostream>
32#include <cmath>
33
34int main()
35{ 
36  using namespace theplu::yat;
37  utility::Vector gsl_vec(10);
38  std::vector<double> data;
39  for (unsigned int i=0; i<10; i++){
40    data.push_back(static_cast<double>(i));
41    gsl_vec(i)=i;
42  }
43
44  double m=statistics::median(data.begin(), data.end());
45  double m_gsl=statistics::median(gsl_vec.begin(), gsl_vec.end());
46  if (m!=4.5 || m!=m_gsl)
47    return -1;
48  statistics::percentile(data.begin(), data.end(), 100);
49  data.resize(1);
50  statistics::median(data.begin(), data.end());
51
52  double tolerance=1e-10;
53  double skewness_gsl=statistics::skewness(gsl_vec);
54  if (std::abs(skewness_gsl)>tolerance)
55    return -1;
56  double kurtosis_gsl=statistics::kurtosis(gsl_vec);
57  if (std::abs(kurtosis_gsl+1.5616363636363637113)>tolerance) 
58    return -1; 
59  return 0;
60}
Note: See TracBrowser for help on using the repository browser.