Generated on for Gecode by doxygen 1.17.0
test.hh
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 *
6 * Contributing authors:
7 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
8 *
9 * Copyright:
10 * Christian Schulte, 2005
11 * Mikael Zayenz Lagerkvist, 2005
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.dev
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38#ifndef GECODE_TEST_TEST_HH
39#define GECODE_TEST_TEST_HH
40
41#include <gecode/kernel.hh>
42#include <gecode/search.hh>
43#include <gecode/int.hh>
44
45#include <iostream>
46#include <sstream>
47#include <string>
48#include <vector>
49
50/* Configure linking, as for the Gecode variable libraries. */
51#if !defined(GECODE_STATIC_LIBS) && \
52 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
53#ifdef GECODE_BUILD_TEST
54#define GECODE_TEST_EXPORT __declspec( dllexport )
55#else
56#define GECODE_TEST_EXPORT __declspec( dllimport )
57#endif
58#elif defined(GECODE_GCC_HAS_CLASS_VISIBILITY)
59#define GECODE_TEST_EXPORT __attribute__ ((visibility("default")))
60#else
61#define GECODE_TEST_EXPORT
62#endif
63
65namespace Test {
66
73
79 extern GECODE_TEST_EXPORT std::ostringstream olog;
80
83 public:
85 int l;
87 ind(int i) : l(i) {}
88 };
89
91 enum MatchType {
92 MT_ANY, //< Positive match anywhere in string
93 MT_NOT, //< Negative match
94 MT_FIRST //< Positive match at beginning
95 };
96
98 enum class TestTag : unsigned int {
99 check = 1U << 0,
100 standard = 1U << 1,
101 sweep = 1U << 2
102 };
103
106 private:
108 unsigned int _mask;
109 public:
111 TestTags(void);
113 TestTags(TestTag t);
115 TestTags(TestTag t0, TestTag t1);
117 static TestTags check(void);
119 static TestTags standard(void);
121 static TestTags sweep(void);
123 static TestTags all(void);
125 bool empty(void) const;
127 bool overlaps(TestTags t) const;
129 void add(TestTags t);
130 };
131
134 public:
136 unsigned int threads;
138 unsigned int seed;
140 bool replay;
142 unsigned int iter;
144 static const int defiter = 5;
146 unsigned int fixprob;
148 static const unsigned int deffixprob = 10;
150 bool stop;
152 bool log;
154 std::vector<std::pair<MatchType, const char*> > testpat;
158 const char* start_from;
160 bool list;
165
167 Options(void);
169 void parse(int argc, char* argv[]);
170
177 bool is_test_name_matching(const std::string& test_name) const;
179 bool is_test_tags_matching(TestTags tags) const;
180 };
181
184
187 private:
189 std::string _name;
191 TestTags _tags;
193 Base* _next;
195 static Base* _tests;
197 static unsigned int _n_tests;
198 public:
200 Base(std::string s);
205 Base(std::string s, TestTags t);
207 static void sort(void);
209 const std::string& name(void) const;
211 TestTags tags(void) const;
213 static Base* tests(void);
215 Base* next(void) const;
217 void next(Base* n);
219 virtual bool run(void) = 0;
221 bool fixpoint(void);
225 virtual ~Base(void);
226
228
229
230 static std::string str(bool b);
232 static std::string str(int i);
234 static std::string str(const Gecode::IntArgs& i);
236
239 };
240
261 GECODE_TEST_EXPORT int run_registered_tests(int argc, char* argv[]);
263
264}
265
270GECODE_TEST_EXPORT std::ostream&
271operator<<(std::ostream& os, const Test::ind& i);
272
273#include "test/test.hpp"
274
275#endif
276
277// STATISTICS: test-core
Passing integer arguments.
Definition int.hh:653
Gecode::Support::RandomGenerator _rand
Random number generator.
Definition test.hh:238
Base(std::string s)
Create and register a standard test with name s.
Definition test.cpp:125
static Base * tests(void)
Return all tests.
Definition test.hpp:99
virtual ~Base(void)
Destructor.
bool fixpoint(void)
Throw a coin whether to compute a fixpoint.
Definition test.hpp:111
Base * next(void) const
Return next test.
Definition test.hpp:103
virtual bool run(void)=0
Run test.
const std::string & name(void) const
Return name of test.
Definition test.hpp:91
static void sort(void)
Sort tests alphabetically.
Definition test.cpp:146
static std::string str(bool b)
Map bool to string.
Definition test.hpp:121
TestTags tags(void) const
Return tags for test.
Definition test.hpp:95
Commandline options.
Definition test.hh:133
bool list_tags
Whether to list known tags.
Definition test.hh:162
std::vector< std::pair< MatchType, const char * > > testpat
Patterns to test against.
Definition test.hh:154
bool is_test_name_matching(const std::string &test_name) const
Test whether a test name should be executed.
Definition test.cpp:314
void parse(int argc, char *argv[])
Parse commandline arguments.
Definition test.cpp:177
bool log
Whether to log the tests.
Definition test.hh:152
unsigned int seed
The random seed to be used.
Definition test.hh:138
const char * start_from
Name of first test to start with.
Definition test.hh:158
Options(void)
Initialize options with defaults.
Definition test.hpp:80
bool is_test_tags_matching(TestTags tags) const
True iff test tags should be executed according to the requested tags. With no tag request,...
Definition test.cpp:356
static const unsigned int deffixprob
Default fixpoint probability.
Definition test.hh:148
bool replay
Replay one named test from its reported random state.
Definition test.hh:140
bool list
Whether to list all tests.
Definition test.hh:160
unsigned int iter
Number of iterations for each test.
Definition test.hh:142
bool stop
Whether to stop on an error.
Definition test.hh:150
unsigned int threads
Number of threads to use.
Definition test.hh:136
unsigned int fixprob
The probability for computing a fixpoint.
Definition test.hh:146
static const int defiter
Default number of iterations.
Definition test.hh:144
TestTags testtags
Tags to test against.
Definition test.hh:156
bool list_with_tags
Whether to include tags when listing tests.
Definition test.hh:164
Set of test tags.
Definition test.hh:105
static TestTags sweep(void)
Expensive parameter sweeps.
Definition test.hpp:59
static TestTags standard(void)
Standard suite without expensive sweeps.
Definition test.hpp:55
static TestTags check(void)
Integrity tests, also part of the standard suite.
Definition test.hpp:51
static TestTags all(void)
Return set with all known tags.
Definition test.cpp:70
void add(TestTags t)
Add tags t.
Definition test.hpp:71
bool overlaps(TestTags t) const
Whether this set contains any tag from t.
Definition test.hpp:67
bool empty(void) const
Whether no tags are set.
Definition test.hpp:63
TestTags(void)
Initialize with no tags.
Definition test.hpp:41
Simple class for describing indentation.
Definition test.hh:82
int l
Which indentation level.
Definition test.hh:85
ind(int i)
Indent by level i.
Definition test.hh:87
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
General test support.
Definition afc.cpp:41
std::ostringstream olog
Stream used for logging.
Definition test.cpp:54
MatchType
How to match.
Definition test.hh:91
@ MT_FIRST
Definition test.hh:94
@ MT_ANY
Definition test.hh:92
@ MT_NOT
Definition test.hh:93
int run_registered_tests(int argc, char *argv[])
Definition test.cpp:603
TestTag
Tags for test selection.
Definition test.hh:98
@ check
Basic integrity tests.
Definition test.hh:99
@ standard
Standard test suite.
Definition test.hh:100
@ sweep
Really heavy sweep tests.
Definition test.hh:101
Options opt
The options.
Definition test.cpp:163
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition scowl.hpp:13625
#define GECODE_TEST_EXPORT
Definition test.hh:61