44 #define CHECK_TEST(T,M) \
46 olog << ind(3) << "Check: " << (M) << std::endl; \
48 problem = (M); goto failed; \
52 #define START_TEST(T) \
55 olog << ind(2) << "Testing: " << (T) << std::endl; \
65 static const std::string prefix(
"Array::Iterator::");
71 static const int n = 16;
77 const char* test =
"NONE";
78 const char* problem =
"NONE";
80 const Array& const_a =
a;
84 typedef typename Array::reference reference;
85 typedef typename Array::pointer pointer;
86 typedef typename Array::iterator iterator;
87 const iterator begin = a.begin(), end = a.end();
88 CHECK_TEST(end-begin==a.size(),
"Distance != size");
90 iterator iter = begin;
91 for(; iter != end; ++iter, ++index) {
92 reference ref = *iter;
93 const pointer ptr = &ref;
94 CHECK_TEST(ptr==&a[index],
"Iterator points to the wrong element (going forward)");
96 CHECK_TEST(index==a.size(),
"Iteration covered the wrong number of elements (going forward)");
97 for(; iter != begin; --iter, --index) {
98 reference ref = *(iter-1);
99 const pointer ptr = &ref;
100 CHECK_TEST(ptr==&a[index-1],
"Iterator points to the wrong element (going backwards)");
102 CHECK_TEST(index==0,
"Iteration covered the wrong number of elements (going backward)");
106 typedef typename Array::const_reference reference;
107 typedef typename Array::const_pointer pointer;
108 typedef typename Array::const_iterator iterator;
109 const iterator begin = const_a.begin(), end = const_a.end();
110 CHECK_TEST(end-begin==const_a.size(),
"Distance != size");
112 iterator iter = begin;
113 for(; iter != end; ++iter, ++index) {
114 reference ref = *iter;
115 const pointer ptr = &ref;
116 CHECK_TEST(ptr==&const_a[index],
"Iterator points to the wrong element (going forward)");
118 CHECK_TEST(index==const_a.size(),
"Iteration covered the wrong number of elements (going forward)");
119 for(; iter != begin; --iter, --index) {
120 reference ref = *(iter-1);
121 const pointer ptr = &ref;
122 CHECK_TEST(ptr==&const_a[index-1],
"Iterator points to the wrong element (going backwards)");
124 CHECK_TEST(index==0,
"Iteration covered the wrong number of elements (going backward)");
129 typedef typename Array::reference reference;
130 typedef typename Array::pointer pointer;
131 typedef typename Array::reverse_iterator iterator;
132 const iterator begin = a.rbegin(), end = a.rend();
133 CHECK_TEST(end-begin==a.size(),
"Distance != size");
134 int index = a.size();
135 iterator iter = begin;
136 for(; iter != end; ++iter, --index) {
137 reference ref = *iter;
138 const pointer ptr = &ref;
139 CHECK_TEST(ptr==&a[index-1],
"Iterator points to the wrong element (going forward)");
141 CHECK_TEST(index==0,
"Iteration covered the wrong number of elements (going forward)");
142 for(; iter != begin; --iter, ++index) {
143 reference ref = *(iter-1);
144 const pointer ptr = &ref;
145 CHECK_TEST(ptr==&a[index],
"Iterator points to the wrong element (going backwards)");
147 CHECK_TEST(index==a.size(),
"Iteration covered the wrong number of elements (going backward)");
152 typedef typename Array::const_reference reference;
153 typedef typename Array::const_pointer pointer;
154 typedef typename Array::const_reverse_iterator iterator;
155 const iterator begin = const_a.rbegin(), end = const_a.rend();
156 CHECK_TEST(end-begin==const_a.size(),
"Distance != size");
157 int index = a.size();
158 iterator iter = begin;
159 for(; iter != end; ++iter, --index) {
160 reference ref = *iter;
161 const pointer ptr = &ref;
162 CHECK_TEST(ptr==&const_a[index-1],
"Iterator points to the wrong element (going forward)");
164 CHECK_TEST(index==0,
"Iteration covered the wrong number of elements (going forward)");
165 for(; iter != begin; --iter, ++index) {
166 reference ref = *(iter-1);
167 const pointer ptr = &ref;
168 CHECK_TEST(ptr==&const_a[index],
"Iterator points to the wrong element (going backwards)");
170 CHECK_TEST(index==a.size(),
"Iteration covered the wrong number of elements (going backward)");
176 olog <<
"FAILURE" << std::endl
177 <<
ind(1) <<
"Test: " << test << std::endl
178 <<
ind(1) <<
"Problem: " << problem << std::endl;
197 static const int n = 16;
218 static const int n = 16;
239 static const int n = 16;
260 static const int n = 16;
const std::string & name(void) const
Return name of test.
static const int n
Maximum array size.
Simple class for describing identation.
Test::Array::VarArgsIterator varArgsIteratorTest
static Gecode::Support::RandomGenerator rand
Random number generator.
VarArrayIterator(void)
Initialize test.
Gecode::ArgArrayBase< int > Array
Array type being tested.
virtual Space * copy(bool share)
Copying member function.
Gecode::ViewArray< Gecode::IntVar > Array
Array type being tested.
Iterator(const std::string &name)
Initialize test.
VarArgsIterator(void)
Initialize test.
bool run(void)
Perform actual tests.
Test::Array::SharedArrayIterator sharedArrayIteratorTest
static const int n
Maximum array size.
static const int n
Maximum array size.
Test::Array::ViewArrayIterator viewArrayIteratorTest
SharedArrayIterator(void)
Initialize test.
bool run(void)
Perform actual tests.
ViewArrayIterator(void)
Initialize test.
TestSpace(bool share, TestSpace &s)
Base class for testing iterators
bool run(void)
Perform actual tests.
Gecode::VarArray< Gecode::IntVar > Array
Array type being tested.
Base class for all tests to be run
#define CHECK_TEST(T, M)
Check the test result and handle failed test.
bool log
Whether to log the tests.
Gecode::SharedArray< int > Array
Array type being tested.
Test::Array::VarArrayIterator varArrayIteratorTest
Space(void)
Default constructor.
Class for testing the VarArray iterator
std::ostringstream olog
Stream used for logging.
bool run(void)
Perform actual tests.
Class for testing the ViewArray iterator
Class for testing the SharedArray iterator
bool runTestForArray(Array &a)
Perform actual tests.
static const int n
Maximum array size.
#define START_TEST(T)
Start new test.
Class for testing the VarArgs iterator
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
static const int n
Maximum array size.