this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Contributing authors:
7 * Mikael Lagerkvist <lagerkvist@gecode.org>
8 *
9 * Copyright:
10 * Christian Schulte, 2005
11 * Mikael Lagerkvist, 2005
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.org
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
49/// General test support
50namespace Test {
51
52 /**
53 * \defgroup TaskTestTest General test support
54 *
55 * \ingroup TaskTest
56 */
57 //@{
58 /**
59 * \brief Stream used for logging
60 *
61 * The olog is buffered and printed only if an error has
62 * occured.
63 */
64 extern std::ostringstream olog;
65
66 /// Simple class for describing identation
67 class ind {
68 public:
69 /// Which indentation level
70 int l;
71 /// Indent by level \a i
72 ind(int i) : l(i) {}
73 };
74
75 /// How to match
76 enum MatchType {
77 MT_ANY, //< Positive match anywhere in string
78 MT_NOT, //< Negative match
79 MT_FIRST //< Positive match at beginning
80 };
81
82 /// Commandline options
83 class Options {
84 public:
85 /// Number of threads to use
86 unsigned int threads;
87 /// The random seed to be used
88 unsigned int seed;
89 /// Number of iterations for each test
90 unsigned int iter;
91 /// Default number of iterations
92 static const int defiter = 5;
93 /// The probability for computing a fixpoint
94 unsigned int fixprob;
95 /// Default fixpoint probaibility
96 static const unsigned int deffixprob = 10;
97 /// Whether to stop on an error
98 bool stop;
99 /// Whether to log the tests
100 bool log;
101 /// Patterns to test against
102 std::vector<std::pair<MatchType, const char*> > testpat;
103 /// Name of first test to start with
104 const char* start_from;
105 /// Whether to list all tests
106 bool list;
107
108 /// Initialize options with defaults
109 Options(void);
110 /// Parse commandline arguments
111 void parse(int argc, char* argv[]);
112
113 /// True iff a test name should be executed according to the patterns. With no patterns, always true.
114 bool is_test_name_matching(const std::string& test_name);
115 };
116
117 /// The options
118 extern Options opt;
119
120 /// %Base class for all tests to be run
121 class Base {
122 private:
123 /// Name of the test
124 std::string _name;
125 /// Next test
126 Base* _next;
127 /// All tests
128 static Base* _tests;
129 /// How many tests
130 static unsigned int _n_tests;
131 public:
132 /// Create and register test with name \a s
133 Base(std::string s);
134 /// Sort tests alphabetically
135 static void sort(void);
136 /// Return name of test
137 const std::string& name(void) const;
138 /// Return all tests
139 static Base* tests(void);
140 /// Return next test
141 Base* next(void) const;
142 /// Set next test
143 void next(Base* n);
144 /// Run test
145 virtual bool run(void) = 0;
146 /// Throw a coin whether to compute a fixpoint
147 bool fixpoint(void);
148 /// Throw a coin whether to compute a fixpoint
149 static bool fixpoint(Gecode::Support::RandomGenerator& rand);
150 /// Destructor
151 virtual ~Base(void);
152
153 /// \name Mapping scalar values to strings
154 //@{
155 /// Map bool to string
156 static std::string str(bool b);
157 /// Map integer to string
158 static std::string str(int i);
159 /// Map integer array to string
160 static std::string str(const Gecode::IntArgs& i);
161 //@}
162
163 /// Random number generator
164 mutable Gecode::Support::RandomGenerator _rand;
165 };
166 //@}
167
168}
169
170/**
171 * \brief Main function
172 * \relates Test::Base
173 */
174int main(int argc, char* argv[]);
175
176/**
177 * \brief Print indentation
178 * \relates Test::ind
179 */
180std::ostream&
181operator<<(std::ostream& os, const Test::ind& i);
182
183#include "test/test.hpp"
184
185#endif
186
187// STATISTICS: test-core