Generated on for Gecode by doxygen 1.17.0
test.hpp
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 * Copyright:
7 * Christian Schulte, 2007
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Test {
35
36 /*
37 * Test tags
38 *
39 */
40 inline
42 : _mask(0) {}
43 inline
45 : _mask(static_cast<unsigned int>(t)) {}
46 inline
48 : _mask(static_cast<unsigned int>(t0) |
49 static_cast<unsigned int>(t1)) {}
50 inline TestTags
54 inline TestTags
58 inline TestTags
61 }
62 inline bool
63 TestTags::empty(void) const {
64 return _mask == 0;
65 }
66 inline bool
68 return (_mask & t._mask) != 0;
69 }
70 inline void
72 _mask |= t._mask;
73 }
74
75 /*
76 * Commandline options
77 *
78 */
79 inline
81 : threads(1), seed(0), replay(false), iter(defiter), fixprob(deffixprob),
82 stop(true), log(false), testpat(), testtags(),
83 start_from(nullptr), list(false), list_tags(false), list_with_tags(false)
84 {}
85
86 /*
87 * Base class for tests
88 *
89 */
90 inline const std::string&
91 Base::name(void) const {
92 return _name;
93 }
94 inline TestTags
95 Base::tags(void) const {
96 return _tags;
97 }
98 inline Base*
100 return _tests;
101 }
102 inline Base*
103 Base::next(void) const {
104 return _next;
105 }
106 inline void
108 _next=n;
109 }
110 inline bool
112 return fixpoint(_rand);
113 }
114
115 inline bool
117 return rand(opt.fixprob) == 0;
118 }
119
120 inline std::string
121 Base::str(bool b) {
122 std::stringstream s;
123 if (b)
124 s << "+";
125 else
126 s << "-";
127 return s.str();
128 }
129
130 inline std::string
131 Base::str(int i) {
132 std::stringstream s;
133 s << i;
134 return s.str();
135 }
136
137 inline std::string
139 std::string s = "";
140 for (int i=0; i<x.size()-1; i++)
141 s += str(x[i]) + ",";
142 return "[" + s + str(x[x.size()-1]) + "]";
143 }
144
145
146}
147
148// STATISTICS: test-core
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1606
Passing integer arguments.
Definition int.hh:653
Base class for all tests to be run
Definition test.hh:186
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
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
const std::string & name(void) const
Return name of test.
Definition test.hpp:91
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
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 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
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
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
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
General test support.
Definition afc.cpp:41
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