40 #define CHECK_TEST(T,M) \ 42 olog << ind(3) << "Check: " << (M) << std::endl; \ 44 problem = (M); goto failed; \ 48 #define START_TEST(T) \ 51 olog << ind(2) << "Testing: " << (T) << std::endl; \ 61 static const std::string prefix(
"Array::Iterator::");
67 static const int n = 16;
73 const char* test =
"NONE";
74 const char* problem =
"NONE";
76 const Array& const_a =
a;
80 typedef typename Array::reference reference;
81 typedef typename Array::pointer pointer;
82 typedef typename Array::iterator iterator;
83 const iterator begin = a.begin(), end = a.end();
84 CHECK_TEST(end-begin==a.size(),
"Distance != size");
86 iterator iter = begin;
87 for(; iter != end; ++iter, ++index) {
88 reference ref = *iter;
89 const pointer ptr = &ref;
90 CHECK_TEST(ptr==&a[index],
"Iterator points to the wrong element (going forward)");
92 CHECK_TEST(index==a.size(),
"Iteration covered the wrong number of elements (going forward)");
93 for(; iter != begin; --iter, --index) {
94 reference ref = *(iter-1);
95 const pointer ptr = &ref;
96 CHECK_TEST(ptr==&a[index-1],
"Iterator points to the wrong element (going backwards)");
98 CHECK_TEST(index==0,
"Iteration covered the wrong number of elements (going backward)");
102 typedef typename Array::const_reference reference;
103 typedef typename Array::const_pointer pointer;
104 typedef typename Array::const_iterator iterator;
105 const iterator begin = const_a.begin(), end = const_a.end();
106 CHECK_TEST(end-begin==const_a.size(),
"Distance != size");
108 iterator iter = begin;
109 for(; iter != end; ++iter, ++index) {
110 reference ref = *iter;
111 const pointer ptr = &ref;
112 CHECK_TEST(ptr==&const_a[index],
"Iterator points to the wrong element (going forward)");
114 CHECK_TEST(index==const_a.size(),
"Iteration covered the wrong number of elements (going forward)");
115 for(; iter != begin; --iter, --index) {
116 reference ref = *(iter-1);
117 const pointer ptr = &ref;
118 CHECK_TEST(ptr==&const_a[index-1],
"Iterator points to the wrong element (going backwards)");
120 CHECK_TEST(index==0,
"Iteration covered the wrong number of elements (going backward)");
125 typedef typename Array::reference reference;
126 typedef typename Array::pointer pointer;
127 typedef typename Array::reverse_iterator iterator;
128 const iterator begin = a.rbegin(), end = a.rend();
129 CHECK_TEST(end-begin==a.size(),
"Distance != size");
130 int index = a.size();
131 iterator iter = begin;
132 for(; iter != end; ++iter, --index) {
133 reference ref = *iter;
134 const pointer ptr = &ref;
135 CHECK_TEST(ptr==&a[index-1],
"Iterator points to the wrong element (going forward)");
137 CHECK_TEST(index==0,
"Iteration covered the wrong number of elements (going forward)");
138 for(; iter != begin; --iter, ++index) {
139 reference ref = *(iter-1);
140 const pointer ptr = &ref;
141 CHECK_TEST(ptr==&a[index],
"Iterator points to the wrong element (going backwards)");
143 CHECK_TEST(index==a.size(),
"Iteration covered the wrong number of elements (going backward)");
148 typedef typename Array::const_reference reference;
149 typedef typename Array::const_pointer pointer;
150 typedef typename Array::const_reverse_iterator iterator;
151 const iterator begin = const_a.rbegin(), end = const_a.rend();
152 CHECK_TEST(end-begin==const_a.size(),
"Distance != size");
153 int index = a.size();
154 iterator iter = begin;
155 for(; iter != end; ++iter, --index) {
156 reference ref = *iter;
157 const pointer ptr = &ref;
158 CHECK_TEST(ptr==&const_a[index-1],
"Iterator points to the wrong element (going forward)");
160 CHECK_TEST(index==0,
"Iteration covered the wrong number of elements (going forward)");
161 for(; iter != begin; --iter, ++index) {
162 reference ref = *(iter-1);
163 const pointer ptr = &ref;
164 CHECK_TEST(ptr==&const_a[index],
"Iterator points to the wrong element (going backwards)");
166 CHECK_TEST(index==a.size(),
"Iteration covered the wrong number of elements (going backward)");
172 olog <<
"FAILURE" << std::endl
173 <<
ind(1) <<
"Test: " << test << std::endl
174 <<
ind(1) <<
"Problem: " << problem << std::endl;
193 static const int n = 16;
214 static const int n = 16;
235 static const int n = 16;
256 static const int n = 16;
Simple class for describing identation.
Test::Array::VarArgsIterator varArgsIteratorTest
const std::string & name(void) const
Return name of test.
virtual Space * copy(void)
Copying member function.
static Gecode::Support::RandomGenerator rand
Random number generator.
VarArrayIterator(void)
Initialize test.
Gecode::ArgArrayBase< int > Array
Array type being tested.
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
Test::Array::ViewArrayIterator viewArrayIteratorTest
SharedArrayIterator(void)
Initialize test.
bool run(void)
Perform actual tests.
ViewArrayIterator(void)
Initialize test.
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
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.
#define START_TEST(T)
Start new test.
Class for testing the VarArgs iterator
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
static const int n
Maximum array size.