source: trunk/test/utility_test.cc @ 1304

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

quantile normalization closes #288

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1// $Id: utility_test.cc 1304 2008-05-14 20:11:57Z peter $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
5  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2008 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 "Suite.h"
27
28#include "yat/utility/Matrix.h"
29#include "yat/utility/utility.h"
30#include "yat/utility/stl_utility.h"
31
32#include <fstream>
33#include <iostream>
34#include <string>
35
36using namespace theplu::yat;
37void test_quantile_normalize(test::Suite&);
38
39int main(int argc, char* argv[])
40{ 
41  using namespace theplu::yat;
42  test::Suite suite(argc, argv);
43  suite.err() << "testing utility ... " << std::endl;
44
45  // test float/double
46  std::string s("1.2");
47  if (!utility::is_double(s)){
48    suite.add(false);
49  }
50  else if (!utility::is_float(s)) {
51    suite.add(false);
52  }
53  else if (utility::is_int(s)) {
54    suite.add(false);
55  }
56  else if (utility::is_nan(s)) {
57    suite.add(false);
58  }
59
60  // test int
61  s="23";
62  if (!utility::is_double(s)){
63    suite.add(false);
64  }
65  else if (!utility::is_float(s)) {
66    suite.add(false);
67  }
68  else if (!utility::is_int(s)) {
69    suite.add(false);
70  }
71  else if (utility::is_nan(s)) {
72    suite.add(false);
73  }
74
75  // test nan
76  s=" nAn  ";
77  if (!utility::is_double(s)){
78    suite.add(false);
79  }
80  else if (!utility::is_float(s)) {
81    suite.add(false);
82  }
83  else if (!utility::is_int(s)) {
84    suite.add(false);
85  }
86  else if (!utility::is_nan(s)) {
87    suite.add(false);
88  }
89 
90  // testing trailing values
91  s=" 23 23   ";
92  if (utility::is_double(s)){
93    suite.add(false);
94  }
95  else if (utility::is_float(s)) {
96    suite.add(false);
97  }
98  else if (utility::is_int(s)) {
99    suite.add(false);
100  }
101  else if (utility::is_nan(s)) {
102    suite.add(false);
103  }
104
105  if (utility::convert<double>("1.23")!=1.23)
106    suite.add(false);
107  utility::convert<double>("-inf");
108  utility::convert<double>("inf");
109  utility::convert<double>("NaN");
110
111  {
112    utility::Log<long double> f;
113    utility::Log<double> f2(1.3);
114    f(2.0);
115    utility::Exp<double> e;
116    e(3.2);
117  }
118
119  test_quantile_normalize(suite);
120
121  return suite.return_value();
122}
123
124void test_quantile_normalize(test::Suite& suite)
125{
126  suite.err() << "Testing quantile normalization\n";
127 
128  utility::Matrix m(2,2);
129  m(0,0) = 0;
130  m(0,1) = 10;
131  m(1,0) = 2;
132  m(1,1) = 4;
133  utility::quantile_normalize(m);
134  suite.err() << "Testing m(0,0)\n";
135  suite.add(suite.equal(m(0,0), 2));
136  suite.err() << "Testing m(0,1)\n";
137  suite.add(suite.equal(m(0,1), 6));
138  suite.err() << "Testing m(1,0)\n";
139  suite.add(suite.equal(m(1,0), 6));
140  suite.err() << "Testing m(1,1)\n";
141  suite.add(suite.equal(m(1,1), 2));
142
143}
Note: See TracBrowser for help on using the repository browser.