source: trunk/test/utility_test.cc @ 609

Last change on this file since 609 was 609, checked in by Markus Ringnér, 17 years ago

Fixes #98

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1// $Id: utility_test.cc 609 2006-08-30 08:49:45Z markus $
2
3#include <c++_tools/utility/utility.h>
4
5#include <fstream>
6#include <iostream>
7#include <string>
8
9int main(const int argc,const char* argv[])
10
11{ 
12  using namespace theplu;
13
14  std::ostream* error;
15  if (argc>1 && argv[1]==std::string("-v"))
16    error = &std::cerr;
17  else {
18    error = new std::ofstream("/dev/null");
19    if (argc>1)
20      std::cout << "utility_test -v : for printing extra information\n";
21  }
22  *error << "testing utility ... " << std::endl;
23
24  bool ok = true;
25
26  // test float/double
27  std::string s("1.2");
28  if (!utility::is_double(s)){
29    ok=false;
30  }
31  else if (!utility::is_float(s)) {
32    ok=false;
33  }
34  else if (utility::is_int(s)) {
35    ok=false;
36  }
37  else if (utility::is_nan(s)) {
38    ok=false;
39  }
40
41  // test int
42  s="23";
43  if (!utility::is_double(s)){
44    ok=false;
45  }
46  else if (!utility::is_float(s)) {
47    ok=false;
48  }
49  else if (!utility::is_int(s)) {
50    ok=false;
51  }
52  else if (utility::is_nan(s)) {
53    ok=false;
54  }
55
56  // test nan
57  s=" nAn  ";
58  if (utility::is_double(s)){
59    ok=false;
60  }
61  else if (utility::is_float(s)) {
62    ok=false;
63  }
64  else if (utility::is_int(s)) {
65    ok=false;
66  }
67  else if (!utility::is_nan(s)) {
68    ok=false;
69  }
70 
71  // testing trailing values
72  s=" 23 23   ";
73  if (utility::is_double(s)){
74    ok=false;
75  }
76  else if (utility::is_float(s)) {
77    ok=false;
78  }
79  else if (utility::is_int(s)) {
80    ok=false;
81  }
82  else if (utility::is_nan(s)) {
83    ok=false;
84  }
85
86
87
88
89  if(ok)
90    *error << "OK" << std::endl;
91  else
92    *error << "Failed" << std::endl;
93  if (error!=&std::cerr)
94    delete error;
95
96
97  if (ok) 
98    return 0;
99  return -1;
100
101}
Note: See TracBrowser for help on using the repository browser.