38#ifdef GECODE_HAS_MTRACE
60 : _name(s), _next(_tests) {
61 _tests =
this; _n_tests++;
64 Base* Base::_tests = NULL;
65 unsigned int Base::_n_tests = 0;
72 return x->name() > y->name();
86 for ( ; i < _n_tests; i++) {
87 b[i]->next(_tests); _tests =
b[i];
100 std::cout <<
"Options: -seed " <<
opt.
seed;
103 std::cout <<
" -test " << name << std::endl;
105 std::cout <<
olog.str();
115 std::vector<std::pair<MatchType, const char*> >
testpat;
123 if (!strcmp(argv[i],
"-help") || !strcmp(argv[i],
"--help")) {
124 std::cerr <<
"Options for testing:" << std::endl
125 <<
"\t-seed (unsigned int or \"time\") default: "
127 <<
"\t\tseed for random number generator (unsigned int),"
129 <<
"\t\tor \"time\" for a random seed based on "
130 <<
"current time" << std::endl
131 <<
"\t-fixprob (unsigned int) default: "
133 <<
"\t\t1/fixprob is the probability of computing a fixpoint"
135 <<
"\t-iter (unsigned int) default: " <<
iter<< std::endl
136 <<
"\t\tthe number of iterations" << std::endl
137 <<
"\t-test (string) default: (none)" << std::endl
138 <<
"\t\tsimple pattern for the tests to run" << std::endl
139 <<
"\t\tprefixing with \"-\" negates the pattern" << std::endl
140 <<
"\t\tprefixing with \"^\" requires a match at the beginning" << std::endl
141 <<
"\t\tmultiple pattern-options may be given"
143 <<
"\t-start (string) default: (none)" << std::endl
144 <<
"\t\tsimple pattern for the first test to run" << std::endl
147 <<
"\t\tlog execution of tests"
149 <<
"\t\tthe optional argument determines the style of the log"
151 <<
"\t\twith text as the default style"
153 <<
"\t-stop (boolean) default: "
154 << (
stop ?
"true" :
"false") << std::endl
155 <<
"\t\tstop on first error or continue" << std::endl
156 <<
"\t-list" << std::endl
157 <<
"\t\toutput list of all test cases and exit" << std::endl
160 }
else if (!strcmp(argv[i],
"-seed")) {
161 if (++i == argc)
goto missing;
162 if (!strcmp(argv[i],
"time")) {
163 seed =
static_cast<unsigned int>(time(NULL));
165 seed =
static_cast<unsigned int>(atoi(argv[i]));
167 }
else if (!strcmp(argv[i],
"-iter")) {
168 if (++i == argc)
goto missing;
169 iter =
static_cast<unsigned int>(atoi(argv[i]));
170 }
else if (!strcmp(argv[i],
"-fixprob")) {
171 if (++i == argc)
goto missing;
172 fixprob =
static_cast<unsigned int>(atoi(argv[i]));
173 }
else if (!strcmp(argv[i],
"-test")) {
174 if (++i == argc)
goto missing;
175 if (argv[i][0] ==
'^')
177 else if (argv[i][0] ==
'-')
181 }
else if (!strcmp(argv[i],
"-start")) {
182 if (++i == argc)
goto missing;
184 }
else if (!strcmp(argv[i],
"-log")) {
186 }
else if (!strcmp(argv[i],
"-stop")) {
187 if (++i == argc)
goto missing;
188 if(argv[i][0] ==
't') {
190 }
else if (argv[i][0] ==
'f') {
193 }
else if (!strcmp(argv[i],
"-list")) {
200 std::cerr <<
"Erroneous argument (" << argv[i-1] <<
")" << std::endl
201 <<
" missing parameter" << std::endl;
209 using namespace Test;
210#ifdef GECODE_HAS_MTRACE
219 for (
Base*
t = Base::tests() ;
t != NULL;
t =
t->
next() ) {
220 std::cout <<
t->name() << std::endl;
227 bool started =
startFrom == NULL ? true :
false;
229 for (
Base*
t = Base::tests() ;
t != NULL;
t =
t->
next() ) {
232 if (
t->name().find(
startFrom) != std::string::npos)
238 bool match_found =
false;
239 bool some_positive =
false;
240 for (
unsigned int i = 0; i <
testpat.size(); ++i) {
242 if (
t->name().find(
testpat[i].second) != std::string::npos)
245 some_positive =
true;
247 (
t->name().find(
testpat[i].second) != std::string::npos)) ||
249 (
t->name().find(
testpat[i].second) == 0)))
253 if (some_positive && !match_found)
goto next;
255 std::cout <<
t->name() <<
" ";
257 for (
unsigned int i =
opt.
iter; i--; ) {
263 std::cout <<
"-" << std::endl;
269 std::cout << std::endl;
271 std::cout <<
"Exception in \"Gecode::" << e.
what()
273 <<
"Stopping..." << std::endl;
285 for (
int j=i.l; j--; )
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Node * x
Pointer to corresponding Boolean expression node.
Exception: Base-class for exceptions
virtual const char * what(void) const
Return information.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Template for linear congruential generators.
Base class for all tests to be run
static Gecode::Support::RandomGenerator rand
Random number generator.
Base(const std::string &s)
Create and register test with name s.
virtual ~Base(void)
Destructor.
Base * next(void) const
Return next test.
static void sort(void)
Sort tests alphabetically.
void parse(int argc, char *argv[])
Parse commandline arguments.
bool log
Whether to log the tests.
unsigned int seed
The random seed to be used.
static const unsigned int deffixprob
Default fixpoint probaibility.
unsigned int iter
Number of iterations for each test.
bool stop
Whether to stop on an error.
unsigned int fixprob
The probability for computing a fixpoint.
bool operator()(Base *x, Base *y)
Simple class for describing identation.
Heap heap
The single global heap.
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
std::ostringstream olog
Stream used for logging.
void report_error(std::string name)
std::vector< std::pair< MatchType, const char * > > testpat
int main(int argc, char *argv[])
std::ostream & operator<<(std::ostream &os, const Test::ind &i)