text
stringlengths 0
2.2M
|
---|
// The primitive generators for our reverse iterator, the primary
|
// piece of test apparatus, are the 'rbegin' and 'rend' member
|
// functions of the sample container type 'MyFixedSizeArray'.
|
//
|
// Concerns:
|
//: 1 All public methods of the test container work correctly.
|
//:
|
//: 2 The iterators generated by 'begin' and 'end' shall delimit the
|
//: valid memory range allocated in test container.
|
//:
|
//: 3 The reverse iterators generated by 'rbegin' and 'rend' shall
|
//: delimit the valid memory range allocated in test container.
|
//:
|
//: 4 The iterators and reverse iterators refer to correct values.
|
//:
|
//: 5 The above concerns are also valid on constant iterators and
|
//: constant reverse iterators.
|
//
|
// Plan:
|
//: 1 Create a fixed size array 'A', assign values to each of its
|
//: elements. (C-1)
|
//:
|
//: 2 Verify iterators and reverse iterators generated by 'A' delimit
|
//: correct memory range. (C-1..3)
|
//:
|
//: 3 Verify the values in the memory range delimited by iterators and
|
//: reverse iterators generated by 'A' refer to correct values in
|
//: 'A'. (C-4)
|
//:
|
//: 4 Repeat the above three steps to verify constant iterators and
|
//: constant reverse iterators. (C-1..4)
|
//
|
// Testing:
|
// class MyFixedSizeArray<VALUE>;
|
// MyFixedSizeArray<VALUE, SIZE>::MyFixedSizeArray();
|
// MyFixedSizeArray<VALUE, SIZE>::begin();
|
// MyFixedSizeArray<VALUE, SIZE>::end();
|
// MyFixedSizeArray<VALUE, SIZE>::rbegin();
|
// MyFixedSizeArray<VALUE, SIZE>::rend();
|
// MyFixedSizeArray<VALUE, SIZE>::operator[](int);
|
// MyFixedSizeArray<VALUE, SIZE>::operator[](int) const;
|
// MyFixedSizeArray<VALUE, SIZE>::size() const;
|
// --------------------------------------------------------------------
|
if (verbose) printf("\nTESTING (PRIMITIVE) GENERATORS"
|
"\n==============================\n");
|
if (verbose) printf("\nValidating primitive test machinery\n");
|
if (verbose) printf("\nTesting class MyFixedSizeArray<int>\n");
|
using namespace testcontainer;
|
const int arrayLength = 5;
|
typedef MyFixedSizeArray<int, arrayLength> TestContainer;
|
typedef TestContainer::iterator iterator;
|
typedef TestContainer::const_iterator const_iterator;
|
typedef TestContainer::reverse_iterator reverse_iterator;
|
typedef TestContainer::const_reverse_iterator const_reverse_iterator;
|
TestContainer tc;
|
ASSERT(arrayLength == tc.size());
|
if (verbose) printf("\nCheck 'operator[]' and 'operator[] const'\n");
|
for (int i = 0; i < tc.size(); ++i) {
|
tc[i] = i + 1;
|
}
|
const TestContainer &tc2 = tc;
|
for (int i = 0; i < tc2.size(); ++i) {
|
ASSERT(i + 1 == tc2[i]);
|
}
|
if (verbose) printf("\nCheck iterator has right range\n");
|
int length = 0;
|
iterator itBegin = tc.begin();
|
iterator itEnd = tc.end();
|
while(itBegin != itEnd) {
|
++length;
|
++itBegin;
|
}
|
LOOP_ASSERT(length, arrayLength == length);
|
if (verbose) printf("\nCheck reverse iterator has right range\n");
|
length = 0;
|
reverse_iterator ritBegin = tc.rbegin();
|
reverse_iterator ritEnd = tc.rend();
|
while(ritBegin != ritEnd) {
|
++length;
|
++ritBegin;
|
}
|
LOOP_ASSERT(length, arrayLength == length);
|
if (verbose) printf("\nCheck iterators refer to right values\n");
|
itBegin = tc.begin();
|
for (int i = 0;i < tc.size(); ++i) {
|
LOOP_ASSERT(*itBegin, i + 1 == *(itBegin++));
|
}
|
if (verbose) printf(
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.