3 // Copyright (C) 2005-2022 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
23 // Permission to use, copy, modify, sell, and distribute this software
24 // is hereby granted without fee, provided that the above copyright
25 // notice appears in all copies, and that both that copyright notice
26 // and this permission notice appear in supporting documentation. None
27 // of the above authors, nor IBM Haifa Research Laboratories, make any
28 // representation about the suitability of this software for any
29 // purpose. It is provided "as is" without express or implied
33 * @file container_rand_regression_test.h
34 * Contains a random regression test for a specific container type.
37 #ifndef PB_DS_CONTAINER_RAND_REGRESSION_TEST_H
38 #define PB_DS_CONTAINER_RAND_REGRESSION_TEST_H
45 #include <regression/basic_type.hpp>
46 #include <ext/pb_ds/priority_queue.hpp>
47 #include <io/prog_bar.hpp>
48 #include <testsuite_rng.h>
49 #include <common_type/priority_queue/string_form.hpp>
50 #include <regression/rand/xml_formatter.hpp>
51 #include <regression/trait/priority_queue/trait.hpp>
59 // Rand test specialized for a specific container.
60 template<typename Cntnr
>
61 class container_rand_regression_test
65 typedef typename
cntnr::allocator_type allocator_type
;
66 typedef typename
cntnr::size_type size_type
;
67 typedef twister_rand_gen gen
;
68 typedef basic_type value_type
;
69 typedef native_priority_queue
<std::string
, true> native_type
;
70 typedef regression_test_traits
<cntnr
> test_traits
;
85 get_next_sub_op(size_t max
);
112 default_constructor();
121 assignment_operator();
148 cmp(const Cntnr
& r_container
, const native_type
& r_native_c
,
149 const std::string
& r_call_fn
);
152 print_container(const native_type
& r_cnt
,
153 std::ostream
& r_os
= std::cerr
) const;
156 print_container(const cntnr
& r_cnt
,
157 std::ostream
& r_os
= std::cerr
) const;
159 struct destructor_printer
161 destructor_printer(const std::string
& r_msg
)
162 : m_msg(r_msg
), m_print(true) { }
168 ~destructor_printer()
172 std::cerr
<< std::endl
<< "Uncaught exception: " << std::endl
173 << m_msg
<< std::endl
;
177 const std::string m_msg
;
181 const unsigned long m_seed
;
191 twister_rand_gen m_g
;
193 native_type m_native_c
;
194 allocator_type m_alloc
;
198 container_rand_regression_test(unsigned long seed
, size_t n
, size_t m
,
199 double tp
, double ip
, double dp
,
200 double ep
, double cp
, double mp
,
204 ~container_rand_regression_test();
211 #ifdef PB_DS_REGRESSION_TRACE
212 # define PB_DS_TRACE(X) std::cerr << X << std::endl
214 # define PB_DS_TRACE(X)
217 #define PB_DS_CLASS_T_DEC \
218 template<typename Cntnr>
220 #define PB_DS_CLASS_C_DEC \
221 container_rand_regression_test<Cntnr>
223 #define PB_DS_COND_COMPARE(L, R) \
224 if (m_g.get_prob() < m_mp) \
225 cmp(L, R, __FUNCTION__);
227 #define PB_DS_RUN_MTHD(MTHD) \
234 #define _GLIBCXX_THROW_IF_(PRED, MORE, P_C, P_NC, F, L) \
237 std::cerr << "Failure at " << F << ": " << L << std::endl; \
238 std::cerr << MORE << std::endl; \
239 std::cerr << "container:" << std::endl; \
240 print_container(*(P_C)); \
241 std::cerr << std::endl; \
242 std::cerr << "native container:" << std::endl; \
243 print_container(*(P_NC)); \
244 std::cerr << std::endl; \
245 throw std::logic_error("pbds throw if failed"); \
248 #define _GLIBCXX_THROW_IF(PRED, MORE, P_C, P_NC) \
249 _GLIBCXX_THROW_IF_(PRED, MORE, P_C, P_NC, __FILE__, __LINE__)
251 #include <regression/rand/priority_queue/container_rand_regression_test.tcc>
253 #undef PB_DS_COND_COMPARE
254 #undef PB_DS_RUN_MTHD
255 #undef PB_DS_CLASS_T_DEC
256 #undef PB_DS_CLASS_C_DEC
257 #undef _GLIBCXX_THROW_IF_
258 #undef _GLIBCXX_THROW_IF
261 } // namespace detail
263 } // namespace __gnu_pbds