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 76 /// Commandline options 77 class Options { 78 public: 79 /// The random seed to be used 80 unsigned int seed; 81 /// Number of iterations for each test 82 unsigned int iter; 83 /// Default number of iterations 84 static const int defiter = 5; 85 /// The probability for computing a fixpoint 86 unsigned int fixprob; 87 /// Default fixpoint probaibility 88 static const unsigned int deffixprob = 10; 89 /// Whether to stop on an error 90 bool stop; 91 /// Whether to log the tests 92 bool log; 93 94 /// Initialize options with defaults 95 Options(void); 96 /// Parse commandline arguments 97 void parse(int argc, char* argv[]); 98 }; 99 100 /// The options 101 extern Options opt; 102 103 /// %Base class for all tests to be run 104 class Base { 105 private: 106 /// Name of the test 107 std::string _name; 108 /// Next test 109 Base* _next; 110 /// All tests 111 static Base* _tests; 112 /// How many tests 113 static unsigned int _n_tests; 114 public: 115 /// Create and register test with name \a s 116 Base(std::string s); 117 /// Sort tests alphabetically 118 static void sort(void); 119 /// Return name of test 120 const std::string& name(void) const; 121 /// Return all tests 122 static Base* tests(void); 123 /// Return next test 124 Base* next(void) const; 125 /// Set next test 126 void next(Base* n); 127 /// Run test 128 virtual bool run(void) = 0; 129 /// Throw a coin whether to compute a fixpoint 130 static bool fixpoint(void); 131 /// Destructor 132 virtual ~Base(void); 133 134 /// \name Mapping scalar values to strings 135 //@{ 136 /// Map bool to string 137 static std::string str(bool b); 138 /// Map integer to string 139 static std::string str(int i); 140 /// Map integer array to string 141 static std::string str(const Gecode::IntArgs& i); 142 //@} 143 144 /// Random number generator 145 static Gecode::Support::RandomGenerator rand; 146 }; 147 //@} 148 149} 150 151/** 152 * \brief Main function 153 * \relates Test::Base 154 */ 155int main(int argc, char* argv[]); 156 157/** 158 * \brief Print indentation 159 * \relates Test::ind 160 */ 161std::ostream& 162operator<<(std::ostream& os, const Test::ind& i); 163 164#include "test/test.hpp" 165 166#endif 167 168// STATISTICS: test-core