antioch-0.4.0
List of all members | Public Member Functions | Private Member Functions
AntiochTesting::StringUtilitiesTest Class Reference
Inheritance diagram for AntiochTesting::StringUtilitiesTest:

Public Member Functions

void setUp ()
 
void tearDown ()
 
 CPPUNIT_TEST_SUITE (StringUtilitiesTest)
 
 CPPUNIT_TEST (test_split_string)
 
 CPPUNIT_TEST (test_string_to_T)
 
 CPPUNIT_TEST (test_strip_newlines)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Member Functions

void test_split_string ()
 
void test_string_to_T ()
 
void test_strip_newlines ()
 

Detailed Description

Definition at line 39 of file string_utils_test.C.

Member Function Documentation

AntiochTesting::StringUtilitiesTest::CPPUNIT_TEST ( test_split_string  )
AntiochTesting::StringUtilitiesTest::CPPUNIT_TEST ( test_string_to_T  )
AntiochTesting::StringUtilitiesTest::CPPUNIT_TEST ( test_strip_newlines  )
AntiochTesting::StringUtilitiesTest::CPPUNIT_TEST_SUITE ( StringUtilitiesTest  )
AntiochTesting::StringUtilitiesTest::CPPUNIT_TEST_SUITE_END ( )
void AntiochTesting::StringUtilitiesTest::setUp ( )
inline

Definition at line 43 of file string_utils_test.C.

43 {}
void AntiochTesting::StringUtilitiesTest::tearDown ( )
inline

Definition at line 45 of file string_utils_test.C.

45 {}
void AntiochTesting::StringUtilitiesTest::test_split_string ( )
inlineprivate

Definition at line 57 of file string_utils_test.C.

References Antioch::split_string().

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  }
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
void AntiochTesting::StringUtilitiesTest::test_string_to_T ( )
inlineprivate

Definition at line 131 of file string_utils_test.C.

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  }
void AntiochTesting::StringUtilitiesTest::test_strip_newlines ( )
inlineprivate

Definition at line 153 of file string_utils_test.C.

References Antioch::remove_newline_from_strings().

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  }
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

The documentation for this class was generated from the following file:

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