antioch-0.4.0
string_utils_test.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This 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 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 
27 #include "antioch_config.h"
28 
29 #ifdef ANTIOCH_HAVE_CPPUNIT
30 
31 #include <cppunit/extensions/HelperMacros.h>
32 #include <cppunit/TestCase.h>
33 
34 // Antioch
35 #include "antioch/string_utils.h"
36 
37 namespace AntiochTesting
38 {
39  class StringUtilitiesTest : public CppUnit::TestCase
40  {
41  public:
42 
43  void setUp(){}
44 
45  void tearDown(){}
46 
48 
52 
54 
55  private:
56 
58  {
59  {
60  std::string str("N->N2");
61  std::vector<std::string> str_split;
62  Antioch::split_string( str, "->", str_split);
63 
64  CPPUNIT_ASSERT_EQUAL(2,(int)str_split.size());
65  CPPUNIT_ASSERT_EQUAL(str_split[0],std::string("N"));
66  CPPUNIT_ASSERT_EQUAL(str_split[1],std::string("N2"));
67  }
68 
69  {
70  std::string str("N+C(s)->CN");
71  std::vector<std::string> str_split;
72  Antioch::split_string( str, "->", str_split);
73 
74  CPPUNIT_ASSERT_EQUAL(2,(int)str_split.size());
75  CPPUNIT_ASSERT_EQUAL(str_split[0],std::string("N+C(s)"));
76  CPPUNIT_ASSERT_EQUAL(str_split[1],std::string("CN"));
77  }
78 
79  {
80  std::string str("u:v:w:T:p:w_N:w_N2:p0");
81  std::vector<std::string> str_split;
82  Antioch::split_string( str, ":", str_split);
83 
84  CPPUNIT_ASSERT_EQUAL(8,(int)str_split.size());
85  CPPUNIT_ASSERT_EQUAL(str_split[0],std::string("u"));
86  CPPUNIT_ASSERT_EQUAL(str_split[1],std::string("v"));
87  CPPUNIT_ASSERT_EQUAL(str_split[2],std::string("w"));
88  CPPUNIT_ASSERT_EQUAL(str_split[3],std::string("T"));
89  CPPUNIT_ASSERT_EQUAL(str_split[4],std::string("p"));
90  CPPUNIT_ASSERT_EQUAL(str_split[5],std::string("w_N"));
91  CPPUNIT_ASSERT_EQUAL(str_split[6],std::string("w_N2"));
92  CPPUNIT_ASSERT_EQUAL(str_split[7],std::string("p0"));
93  }
94 
95  {
96  std::string str("u v w T p w_N w_N2 p0");
97  std::vector<std::string> str_split;
98  Antioch::split_string( str, " ", str_split);
99 
100  CPPUNIT_ASSERT_EQUAL(8,(int)str_split.size());
101  CPPUNIT_ASSERT_EQUAL(str_split[0],std::string("u"));
102  CPPUNIT_ASSERT_EQUAL(str_split[1],std::string("v"));
103  CPPUNIT_ASSERT_EQUAL(str_split[2],std::string("w"));
104  CPPUNIT_ASSERT_EQUAL(str_split[3],std::string("T"));
105  CPPUNIT_ASSERT_EQUAL(str_split[4],std::string("p"));
106  CPPUNIT_ASSERT_EQUAL(str_split[5],std::string("w_N"));
107  CPPUNIT_ASSERT_EQUAL(str_split[6],std::string("w_N2"));
108  CPPUNIT_ASSERT_EQUAL(str_split[7],std::string("p0"));
109  }
110 
111  {
112  std::string str("2.25853318e+03, -1.57454401e+00, 2.50363759e+00, -5.20253954e-06, ");
113  str += " 4.51647956e-09, -2.18115104e-12, 4.49430845e-16, 2.16895191e+05, 4.34577527e+00";
114 
115  std::vector<std::string> str_split;
116  Antioch::split_string( str, " ,", str_split);
117 
118  CPPUNIT_ASSERT_EQUAL(9,(int)str_split.size());
119  CPPUNIT_ASSERT_EQUAL(str_split[0],std::string("2.25853318e+03"));
120  CPPUNIT_ASSERT_EQUAL(str_split[1],std::string("-1.57454401e+00"));
121  CPPUNIT_ASSERT_EQUAL(str_split[2],std::string("2.50363759e+00"));
122  CPPUNIT_ASSERT_EQUAL(str_split[3],std::string("-5.20253954e-06"));
123  CPPUNIT_ASSERT_EQUAL(str_split[4],std::string("4.51647956e-09"));
124  CPPUNIT_ASSERT_EQUAL(str_split[5],std::string("-2.18115104e-12"));
125  CPPUNIT_ASSERT_EQUAL(str_split[6],std::string("4.49430845e-16"));
126  CPPUNIT_ASSERT_EQUAL(str_split[7],std::string("2.16895191e+05"));
127  CPPUNIT_ASSERT_EQUAL(str_split[8],std::string("4.34577527e+00"));
128  }
129  }
130 
132  {
133  {
134  std::string str("1");
135  int test = Antioch::string_to_T<int>(str);
136  CPPUNIT_ASSERT_EQUAL(1,test);
137  }
138 
139  {
140  std::string str("1.0");
141  double test = Antioch::string_to_T<double>(str);
142  CPPUNIT_ASSERT_EQUAL(1.0,test);
143  }
144 
145  {
146  std::string str("4.34577527e+00");
147  double test = Antioch::string_to_T<double>(str);
148  CPPUNIT_ASSERT_DOUBLES_EQUAL(4.34577527e+00, test, 1.0e-8);
149  }
150 
151  }
152 
154  {
155  std::vector<std::string> strings;
156  strings.push_back("\n");
157  strings.push_back("2.9087450987e-01\n");
158  strings.push_back("3.1415926539e+00\n");
159  strings.push_back("1.1111111111e+10\n");
160 
161  std::vector<std::string> strings_exact;
162  strings_exact.push_back("2.9087450987e-01");
163  strings_exact.push_back("3.1415926539e+00");
164  strings_exact.push_back("1.1111111111e+10");
165 
167  CPPUNIT_ASSERT_EQUAL(strings_exact.size(), strings.size());
168 
169  for( unsigned int i = 0; i < strings_exact.size(); i++ )
170  CPPUNIT_ASSERT_EQUAL(strings_exact[i], strings[i]);
171  }
172 
173  };
174 
175  CPPUNIT_TEST_SUITE_REGISTRATION( StringUtilitiesTest );
176 
177 } // end namespace AntiochTesting
178 
179 #endif // ANTIOCH_HAVE_CPPUNIT
void remove_newline_from_strings(std::vector< std::string > &strings)
Strips newline characters from strings in the input vector, strings.
Definition: string_utils.C:56
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
All characters in delimiter will be treated as a delimiter.
Definition: string_utils.C:34
CPPUNIT_TEST_SUITE(StringUtilitiesTest)
CPPUNIT_TEST_SUITE_REGISTRATION(ArrheniusRateEigenFloatTest)

Generated on Thu Jul 7 2016 11:09:47 for antioch-0.4.0 by  doxygen 1.8.8