source: trunk/test/utility_test.cc @ 1288

Last change on this file since 1288 was 1288, checked in by Peter, 13 years ago

Fixes #337

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