2008-07-03 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / libstdc++-v3 / testsuite / util / regression / rand / priority_queue / container_rand_regression_test.hpp
blobeeedc27bdcacced9708119dcb8a955a7d657ab1f
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
40 // warranty.
42 /**
43 * @file container_rand_regression_test.hpp
44 * Contains a random regression test for a specific container type.
47 #ifndef PB_DS_CONTAINER_RAND_REGRESSION_TEST_HPP
48 #define PB_DS_CONTAINER_RAND_REGRESSION_TEST_HPP
50 #include <algorithm>
51 #include <string>
52 #include <sstream>
53 #include <utility>
54 #include <cassert>
55 #include <regression/basic_type.hpp>
56 #include <ext/pb_ds/priority_queue.hpp>
57 #include <io/prog_bar.hpp>
58 #include <rng/twister_rand_gen.hpp>
59 #include <common_type/priority_queue/string_form.hpp>
60 #include <regression/rand/io/priority_queue/xml_formatter.hpp>
61 #include <regression/trait/priority_queue/trait.hpp>
63 namespace __gnu_pbds
66 namespace test
69 namespace detail
72 #ifdef PB_DS_REGRESSION_TRACE
73 #define PB_DS_TRACE(X) std::cerr << X << std::endl
74 #else // #ifdef PB_DS_REGRESSION_TRACE
75 #define PB_DS_TRACE(X)
76 #endif // #ifdef PB_DS_REGRESSION_TRACE
78 #define PB_DS_CLASS_T_DEC \
79 template<typename Cntnr>
81 #define PB_DS_CLASS_C_DEC \
82 container_rand_regression_test< \
83 Cntnr>
85 #define PB_DS_COND_COMPARE(L, R) \
86 if (m_g.get_prob() < m_mp) \
87 cmp(L, R, __FUNCTION__);
89 #define PB_DS_RUN_MTHD(MTHD) \
90 { \
91 bool done = false; \
93 while (!done) \
94 done = MTHD(); \
97 #define PB_DS_THROW_IF_FAILED_(PRED, MORE, P_C, P_NC, F, L) \
98 if (!(PRED)) \
99 { \
100 std::cerr << "Failure at " << F << ": " << L << std::endl; \
102 std::cerr << MORE << std::endl; \
104 std::cerr << "container:" << std::endl; \
106 print_container(*(P_C)); \
107 std::cerr << std::endl; \
109 std::cerr << "native container:" << std::endl; \
111 print_container(*(P_NC)); \
112 std::cerr << std::endl; \
114 throw std::logic_error("fucked!"); \
117 #define PB_DS_THROW_IF_FAILED(PRED, MORE, P_C, P_NC) \
118 PB_DS_THROW_IF_FAILED_(PRED, MORE, P_C, P_NC, __FILE__, __LINE__)
120 #define PB_DS_SET_DESTRUCT_PRINT \
121 destructor_printer dest_print___(__FUNCTION__);
123 #define PB_DS_CANCEL_DESTRUCT_PRINT \
124 dest_print___.cancel_print();
126 // Rand test specialized for a specific container.
127 template<typename Cntnr>
128 class container_rand_regression_test
131 public:
133 container_rand_regression_test(unsigned long seed, size_t n, size_t m, double tp, double ip, double dp, double ep, double cp, double mp, bool disp);
135 virtual
136 ~container_rand_regression_test();
138 void
139 operator()();
141 private:
142 typedef Cntnr cntnr;
144 typedef typename cntnr::allocator allocator;
146 typedef typename cntnr::size_type size_type;
148 typedef twister_rand_gen gen;
150 typedef basic_type value_type;
152 typedef native_priority_queue<std::string, true> native_type;
154 enum op
156 insert_op,
157 modify_op,
158 erase_op,
159 clear_op,
160 other_op
163 typedef __gnu_cxx::throw_allocator<char> alloc_t;
165 typedef regression_test_traits<Cntnr> test_traits;
167 private:
170 get_next_op();
172 size_t
173 get_next_sub_op(size_t max);
175 static void
176 defs();
178 static void
179 value_defs();
181 static void
182 ds_defs();
184 static void
185 iterator_defs();
187 static void
188 policy_defs();
190 void
191 policy_access();
193 void
194 it_copy();
196 void
197 it_assign();
199 bool
200 default_constructor();
202 void
203 swap();
205 bool
206 copy_constructor();
208 bool
209 assignment_operator();
211 bool
212 it_constructor();
214 bool
215 push();
217 bool
218 modify();
220 bool
221 pop();
223 bool
224 erase_if();
226 bool
227 erase_it();
229 bool
230 clear();
232 bool
233 split_join();
235 void
236 cmp(const Cntnr& r_container, const native_type& r_native_c, const std::string& r_call_fn);
238 void
239 print_container(const native_type& r_cnt, std::ostream& r_os = std::cerr) const;
241 void
242 print_container(const cntnr& r_cnt, std::ostream& r_os = std::cerr) const;
244 private:
245 struct destructor_printer
247 destructor_printer(const std::string& r_msg) : m_msg(r_msg),
248 m_print(true)
251 void
252 cancel_print()
254 m_print = false;
257 ~destructor_printer()
259 if (!m_print)
260 return;
262 std::cerr << std::endl <<
263 "Uncaught exception: " << std::endl <<
264 m_msg << std::endl;
267 private:
268 const std::string m_msg;
270 bool m_print;
273 private:
274 const unsigned long m_seed;
276 const size_t m_n;
277 const size_t m_m;
278 const double m_tp;
279 const double m_ip;
280 const double m_dp;
281 const double m_ep;
282 const double m_cp;
283 const double m_mp;
284 const bool m_disp;
286 twister_rand_gen m_g;
288 Cntnr* m_p_c;
290 native_type m_native_c;
292 alloc_t m_alloc;
294 size_t m_i;
297 #include <regression/rand/priority_queue/detail/constructor_destructor_fn_imps.hpp>
298 #include <regression/rand/priority_queue/detail/cmp_fn_imps.hpp>
299 #include <regression/rand/priority_queue/detail/operator_fn_imps.hpp>
300 #include <regression/rand/priority_queue/detail/insert_fn_imps.hpp>
301 #include <regression/rand/priority_queue/detail/modify_fn_imps.hpp>
302 #include <regression/rand/priority_queue/detail/clear_fn_imps.hpp>
303 #include <regression/rand/priority_queue/detail/erase_fn_imps.hpp>
304 #include <regression/rand/priority_queue/detail/defs_fn_imps.hpp>
305 #include <regression/rand/priority_queue/detail/policy_access_fn_imps.hpp>
306 #include <regression/rand/priority_queue/detail/split_join_fn_imps.hpp>
307 #include <regression/rand/priority_queue/detail/it_conversion_fn_imps.hpp>
308 #include <regression/rand/priority_queue/detail/diagnostic_fn_imps.hpp>
310 #undef PB_DS_COND_COMPARE
312 #undef PB_DS_RUN_MTHD
314 #undef PB_DS_CLASS_T_DEC
316 #undef PB_DS_CLASS_C_DEC
318 #undef PB_DS_THROW_IF_FAILED_
320 #undef PB_DS_THROW_IF_FAILED
322 #undef PB_DS_SET_DESTRUCT_PRINT
324 #undef PB_DS_CANCEL_DESTRUCT_PRINT
326 #undef PB_DS_TRACE
328 } // namespace detail
330 } // namespace test
332 } // namespace __gnu_pbds
334 #endif // #ifndef PB_DS_CONTAINER_RAND_REGRESSION_TEST_HPP