00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <list>
00022 #include <vector>
00023 #include <algorithm>
00024
00025 #include "BasicsAllocator.H"
00026
00027
00028 static const Text testTexts[] = {
00029 "The quick brown fox jumped over the lazy dog.",
00030 "Now is the Time for All Good Men to Come to the Aid of their Country.",
00031 "It was the best of times, it was the worst of times"
00032 };
00033
00034 using std::list;
00035 using std::vector;
00036 using std::cout;
00037 using std::endl;
00038 using std::reverse;
00039
00040
00041
00042 typedef list<char, Basics::Allocator<char> > charList;
00043 typedef vector<char, Basics::Allocator<char> > charVector;
00044
00045
00046
00047
00048 charList listFromText(const Text &in)
00049 {
00050 const char *s = in.cchars();
00051 charList result;
00052 while(*s)
00053 result.push_back(*s++);
00054 return result;
00055 }
00056
00057 charVector vectorFromText(const Text &in)
00058 {
00059 const char *s = in.cchars();
00060 charVector result;
00061 while(*s)
00062 result.push_back(*s++);
00063 return result;
00064 }
00065
00066
00067
00068 int main(void)
00069 {
00070 unsigned int nTexts = sizeof(testTexts) / sizeof(testTexts[0]);
00071
00072 for(unsigned int i = 0; i < nTexts; i++)
00073 {
00074 const Text &testText = testTexts[i];
00075
00076
00077
00078 charList l = listFromText(testText);
00079 charVector v = vectorFromText(testText);
00080
00081
00082 reverse(l.begin(), l.end());
00083 reverse(v.begin(), v.end());
00084
00085
00086 for(unsigned int j = 0; j < testText.Length(); j++)
00087 {
00088
00089
00090 assert(v.size() == l.size());
00091 assert(v.size() == (testText.Length() - j));
00092
00093
00094
00095 char cv = v.back(), cl = l.back(), ct = testText[j];
00096
00097
00098 assert(cv == ct);
00099 assert(cl == ct);
00100
00101 v.pop_back();
00102 l.pop_back();
00103 }
00104 }
00105
00106 cout << "All tests passed!" << endl;
00107 return 0;
00108 }