GRINS-0.6.0
Functions
split_string_unit.C File Reference
#include <string>
#include <vector>
#include <iostream>
#include "grins/string_utils.h"
Include dependency graph for split_string_unit.C:

Go to the source code of this file.

Functions

bool test_string (const std::vector< std::string > &test, const std::vector< std::string > &exact)
 
int main ()
 

Function Documentation

int main ( )

Definition at line 34 of file split_string_unit.C.

References GRINS::StringUtilities::split_string(), and test_string().

35 {
36  int return_flag = 0;
37 
38  std::string str_1("N->N2");
39  std::vector<std::string> test_1_split_exact(2);
40  test_1_split_exact[0] = std::string("N");
41  test_1_split_exact[1] = std::string("N2");
42 
43  std::vector<std::string> str_1_split;
44  GRINS::StringUtilities::split_string( str_1, "->", str_1_split);
45  if( !test_string( str_1_split, test_1_split_exact ) )
46  return_flag = 1;
47 
48  std::string str_2("N+C(s)->CN");
49  std::vector<std::string> test_2_split_exact(2);
50  test_2_split_exact[0] = std::string("N+C(s)");
51  test_2_split_exact[1] = std::string("CN");
52 
53  std::vector<std::string> str_2_split;
54  GRINS::StringUtilities::split_string( str_2, "->", str_2_split);
55  if( !test_string( str_2_split, test_2_split_exact ) )
56  return_flag = 1;
57 
58  std::string str_3("u:v:w:T:p:w_N:w_N2:p0");
59  std::vector<std::string> test_3_split_exact(8);
60  test_3_split_exact[0] = std::string("u");
61  test_3_split_exact[1] = std::string("v");
62  test_3_split_exact[2] = std::string("w");
63  test_3_split_exact[3] = std::string("T");
64  test_3_split_exact[4] = std::string("p");
65  test_3_split_exact[5] = std::string("w_N");
66  test_3_split_exact[6] = std::string("w_N2");
67  test_3_split_exact[7] = std::string("p0");
68 
69  std::vector<std::string> str_3_split;
70  GRINS::StringUtilities::split_string( str_3, ":", str_3_split);
71  if( !test_string( str_3_split, test_3_split_exact ) )
72  return_flag = 1;
73 
74  std::string str_4("u v w T p w_N w_N2 p0");
75  std::vector<std::string> test_4_split_exact(8);
76  test_4_split_exact[0] = std::string("u");
77  test_4_split_exact[1] = std::string("v");
78  test_4_split_exact[2] = std::string("w");
79  test_4_split_exact[3] = std::string("T");
80  test_4_split_exact[4] = std::string("p");
81  test_4_split_exact[5] = std::string("w_N");
82  test_4_split_exact[6] = std::string("w_N2");
83  test_4_split_exact[7] = std::string("p0");
84 
85  std::vector<std::string> str_4_split;
86  GRINS::StringUtilities::split_string( str_4, " ", str_4_split);
87  if( !test_string( str_4_split, test_4_split_exact ) )
88  return_flag = 1;
89 
90  return return_flag;
91 }
bool test_string(const std::vector< std::string > &test, const std::vector< std::string > &exact)
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31
bool test_string ( const std::vector< std::string > &  test,
const std::vector< std::string > &  exact 
)

Definition at line 93 of file split_string_unit.C.

Referenced by main().

95 {
96  bool test_passed = true;
97 
98  if( test.size() != exact.size() )
99  {
100  test_passed = false;
101  std::cerr << "Error: split_string size mismatch!" << std::endl
102  << "Test string size = " << test.size() << std::endl
103  << "Exact string size = " << exact.size() << std::endl;
104  }
105 
106  if( test_passed )
107  {
108  for( unsigned int s = 0; s < test.size(); s++ )
109  {
110  if( test[s] != exact[s] )
111  {
112  test_passed = false;
113  break;
114  }
115  }
116 
117  if( !test_passed)
118  {
119  std::cerr << "Error: split_string value mismatch!" << std::endl
120  << "Test string, Exact string" << std::endl;
121 
122  for( unsigned int s = 0; s < test.size(); s++ )
123  {
124  std::cerr << test[s] << ", " << exact[s] << std::endl;
125  }
126  }
127  }
128 
129  return test_passed;
130 }
int test(ChemicalMixture &chem_mixture)

Generated on Mon Jun 22 2015 21:32:21 for GRINS-0.6.0 by  doxygen 1.8.9.1