source: trunk/test/utility_test.cc @ 1275

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

Updating copyright statements.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1// $Id: utility_test.cc 1275 2008-04-11 06:10:12Z jari $
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/utility.h"
29
30#include <fstream>
31#include <iostream>
32#include <string>
33
34int main(int argc, char* argv[])
35{ 
36  using namespace theplu::yat;
37  test::Suite suite(argc, argv);
38  suite.err() << "testing utility ... " << std::endl;
39
40  // test float/double
41  std::string s("1.2");
42  if (!utility::is_double(s)){
43    suite.add(false);
44  }
45  else if (!utility::is_float(s)) {
46    suite.add(false);
47  }
48  else if (utility::is_int(s)) {
49    suite.add(false);
50  }
51  else if (utility::is_nan(s)) {
52    suite.add(false);
53  }
54
55  // test int
56  s="23";
57  if (!utility::is_double(s)){
58    suite.add(false);
59  }
60  else if (!utility::is_float(s)) {
61    suite.add(false);
62  }
63  else if (!utility::is_int(s)) {
64    suite.add(false);
65  }
66  else if (utility::is_nan(s)) {
67    suite.add(false);
68  }
69
70  // test nan
71  s=" nAn  ";
72  if (!utility::is_double(s)){
73    suite.add(false);
74  }
75  else if (!utility::is_float(s)) {
76    suite.add(false);
77  }
78  else if (!utility::is_int(s)) {
79    suite.add(false);
80  }
81  else if (!utility::is_nan(s)) {
82    suite.add(false);
83  }
84 
85  // testing trailing values
86  s=" 23 23   ";
87  if (utility::is_double(s)){
88    suite.add(false);
89  }
90  else if (utility::is_float(s)) {
91    suite.add(false);
92  }
93  else if (utility::is_int(s)) {
94    suite.add(false);
95  }
96  else if (utility::is_nan(s)) {
97    suite.add(false);
98  }
99
100  if (utility::convert<double>("1.23")!=1.23)
101    suite.add(false);
102  utility::convert<double>("-inf");
103  utility::convert<double>("inf");
104  utility::convert<double>("NaN");
105
106  return suite.return_value();
107}
Note: See TracBrowser for help on using the repository browser.