testStringCompare.cc
Go to the documentation of this file.
1 
11 #include <utl/StringCompare.h>
12 #include <string>
13 #include <vector>
14 
15 #include <utl/Test.h>
16 #include <cppunit/extensions/HelperMacros.h>
17 using namespace tst;
18 using namespace std;
19 using namespace utl;
20 
21 
22 typedef vector<string> VecStr;
23 
27 class testStringCompare : public CppUnit::TestFixture {
28 
29  CPPUNIT_TEST_SUITE(testStringCompare);
30  CPPUNIT_TEST(testEqual);
31  CPPUNIT_TEST(testEqualPred);
32  CPPUNIT_TEST(testNotEqual);
33  CPPUNIT_TEST(testNotEqualPred);
34 // CPPUNIT_TEST_EXCEPTION(testThrows, thisException);
35  CPPUNIT_TEST_SUITE_END();
36 
37 public:
38 
41 
42  void setUp()
43  {
44  if (!equals.size()) {
45  equals.push_back(string("string"));
46  equals.push_back(string("STRING"));
47  equals.push_back(string("String"));
48  equals.push_back(string("sTRING"));
49  equals.push_back(string("StRiNg"));
50  }
51 
52  if (!diffs.size()) {
53  diffs.push_back(string("string"));
54  diffs.push_back(string("spring"));
55  diffs.push_back(string("stringA"));
56  diffs.push_back(string("dog"));
57  diffs.push_back(string("cat"));
58  }
59  }
60 
61  void tearDown() { }
62 
63  void
65  {
66  for (VecStr::iterator a(equals.begin()), e(equals.end()); a != e; ++a)
67  for (VecStr::iterator b(equals.begin()); b != e; ++b) {
68  CPPUNIT_ASSERT( StringEquivalent(*a, *b) );
69  }
70  }
71 
72  void
74  {
75  for (VecStr::iterator a(equals.begin()), e(equals.end()); a != e; ++a)
76  for (VecStr::iterator b(equals.begin()); b != e; ++b) {
77  CPPUNIT_ASSERT( StringEquivalent(*a, *b, CharEqualNoCase()) );
78  }
79  }
80 
81  void
83  {
84  for (VecStr::iterator a(diffs.begin()), e(diffs.end()); a != e; ++a)
85  for (VecStr::iterator b(diffs.begin()); b != e; ++b) {
86  if (a != b) {
87  CPPUNIT_ASSERT( !StringEquivalent(*a, *b) );
88  }
89  }
90  }
91 
92  void
94  {
95  for (VecStr::iterator a(diffs.begin()), e(diffs.end()); a != e; ++a)
96  for (VecStr::iterator b(diffs.begin()); b != e; ++b) {
97  if (a != b) {
98  CPPUNIT_ASSERT( !StringEquivalent(*a, *b) );
99  }
100  }
101  }
102 
103 };
104 
105 
107 
108 
109 // Configure (x)emacs for this file ...
110 // Local Variables:
111 // mode:c++
112 // compile-command: "make -C .. -k testSTL && (cd ..; testSTL)"
113 // End:
vector< string > VecStr
bool StringEquivalent(const std::string &a, const std::string &b, Predicate p)
Utility to compare strings for equivalence. It takes a predicate to determine the equivalence of indi...
Definition: StringCompare.h:38
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Utility class to compare characters in a case-independent way.
Definition: StringCompare.h:24

, generated on Tue Sep 26 2023.