source: trunk/test/utility_test.cc @ 1000

Last change on this file since 1000 was 1000, checked in by Jari Häkkinen, 15 years ago

trac moved to new location.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1// $Id: utility_test.cc 1000 2007-12-23 20:09:15Z jari $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
5
6  This file is part of the yat library, http://trac.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "yat/utility/utility.h"
25
26#include <fstream>
27#include <iostream>
28#include <string>
29
30int main(const int argc,const char* argv[])
31
32{ 
33  using namespace theplu::yat;
34
35  std::ostream* error;
36  if (argc>1 && argv[1]==std::string("-v"))
37    error = &std::cerr;
38  else {
39    error = new std::ofstream("/dev/null");
40    if (argc>1)
41      std::cout << "utility_test -v : for printing extra information\n";
42  }
43  *error << "testing utility ... " << std::endl;
44
45  bool ok = true;
46
47  // test float/double
48  std::string s("1.2");
49  if (!utility::is_double(s)){
50    ok=false;
51  }
52  else if (!utility::is_float(s)) {
53    ok=false;
54  }
55  else if (utility::is_int(s)) {
56    ok=false;
57  }
58  else if (utility::is_nan(s)) {
59    ok=false;
60  }
61
62  // test int
63  s="23";
64  if (!utility::is_double(s)){
65    ok=false;
66  }
67  else if (!utility::is_float(s)) {
68    ok=false;
69  }
70  else if (!utility::is_int(s)) {
71    ok=false;
72  }
73  else if (utility::is_nan(s)) {
74    ok=false;
75  }
76
77  // test nan
78  s=" nAn  ";
79  if (!utility::is_double(s)){
80    ok=false;
81  }
82  else if (!utility::is_float(s)) {
83    ok=false;
84  }
85  else if (!utility::is_int(s)) {
86    ok=false;
87  }
88  else if (!utility::is_nan(s)) {
89    ok=false;
90  }
91 
92  // testing trailing values
93  s=" 23 23   ";
94  if (utility::is_double(s)){
95    ok=false;
96  }
97  else if (utility::is_float(s)) {
98    ok=false;
99  }
100  else if (utility::is_int(s)) {
101    ok=false;
102  }
103  else if (utility::is_nan(s)) {
104    ok=false;
105  }
106
107
108
109
110  if(ok)
111    *error << "OK" << std::endl;
112  else
113    *error << "Failed" << std::endl;
114  if (error!=&std::cerr)
115    delete error;
116
117
118  if (ok) 
119    return 0;
120  return -1;
121
122}
Note: See TracBrowser for help on using the repository browser.