3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
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
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
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
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
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>
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< \
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) \
97 #define PB_DS_THROW_IF_FAILED_(PRED, MORE, P_C, P_NC, F, L) \
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
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);
136 ~container_rand_regression_test();
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;
163 typedef __gnu_cxx::throw_allocator<char> alloc_t;
165 typedef regression_test_traits<Cntnr> test_traits;
173 get_next_sub_op(size_t max);
200 default_constructor();
209 assignment_operator();
236 cmp(const Cntnr& r_container, const native_type& r_native_c, const std::string& r_call_fn);
239 print_container(const native_type& r_cnt, std::ostream& r_os = std::cerr) const;
242 print_container(const cntnr& r_cnt, std::ostream& r_os = std::cerr) const;
245 struct destructor_printer
247 destructor_printer(const std::string& r_msg) : m_msg(r_msg),
257 ~destructor_printer()
262 std::cerr << std::endl <<
263 "Uncaught exception: " << std::endl <<
268 const std::string m_msg;
274 const unsigned long m_seed;
286 twister_rand_gen m_g;
290 native_type m_native_c;
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
328 } // namespace detail
332 } // namespace __gnu_pbds
334 #endif // #ifndef PB_DS_CONTAINER_RAND_REGRESSION_TEST_HPP