3 // Copyright (C) 2005-2023 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
44 #include <ext/pb_ds/assoc_container.hpp>
45 #include <io/prog_bar.hpp>
46 #include <testsuite_rng.h>
47 #include <regression/trait/assoc/trait.hpp>
48 #include <common_type/assoc/string_form.hpp>
49 #include <regression/rand/xml_formatter.hpp>
57 // Rand test specialized for a specific container.
58 template<typename Cntnr
>
59 class container_rand_regression_test
63 container_rand_regression_test(unsigned long, size_t, size_t, double,
64 double, double, double, double, bool);
67 ~container_rand_regression_test();
74 typedef typename
cntnr::allocator_type allocator_type
;
75 typedef typename
cntnr::size_type size_type
;
76 typedef regression_test_traits
<Cntnr
> test_traits
;
77 typedef typename
test_traits::key_type key_type
;
78 typedef typename
test_traits::key_const_reference key_const_reference
;
79 typedef typename
test_traits::value_type value_type
;
80 typedef typename
test_traits::native_type native_type
;
81 typedef twister_rand_gen gen
;
82 typedef __gnu_pbds::container_traits
<Cntnr
> container_traits
;
83 typedef __gnu_cxx::throw_allocator_random
<char> alloc_t
;
97 get_next_sub_op(size_t);
118 node_iterator_defs(__gnu_pbds::detail::false_type
);
121 node_iterator_defs(__gnu_pbds::detail::true_type
);
127 policy_defs(__gnu_pbds::basic_hash_tag
);
130 policy_defs(__gnu_pbds::cc_hash_tag
);
133 policy_defs(__gnu_pbds::gp_hash_tag
);
136 policy_defs(__gnu_pbds::tree_tag
);
139 policy_defs(__gnu_pbds::list_update_tag
);
142 policy_defs(__gnu_pbds::pat_trie_tag
);
148 policy_access(__gnu_pbds::basic_hash_tag
);
151 policy_access(__gnu_pbds::cc_hash_tag
);
154 policy_access(__gnu_pbds::gp_hash_tag
);
157 policy_access(__gnu_pbds::tree_tag
);
160 policy_access(__gnu_pbds::list_update_tag
);
163 policy_access(__gnu_pbds::pat_trie_tag
);
178 rev_it_copy_imp(__gnu_pbds::detail::false_type
);
181 rev_it_copy_imp(__gnu_pbds::detail::true_type
);
184 rev_it_assign_imp(__gnu_pbds::detail::false_type
);
187 rev_it_assign_imp(__gnu_pbds::detail::true_type
);
190 default_constructor();
199 assignment_operator();
205 it_constructor_imp(__gnu_pbds::cc_hash_tag
);
208 it_constructor_imp(__gnu_pbds::gp_hash_tag
);
211 it_constructor_imp(__gnu_pbds::tree_tag
);
214 it_constructor_imp(__gnu_pbds::list_update_tag
);
217 it_constructor_imp(__gnu_pbds::pat_trie_tag
);
229 erase_it_imp(__gnu_pbds::detail::false_type
);
232 erase_it_imp(__gnu_pbds::detail::true_type
);
238 erase_rev_it_imp(__gnu_pbds::detail::false_type
);
241 erase_rev_it_imp(__gnu_pbds::detail::true_type
);
253 resize_imp(__gnu_pbds::detail::true_type
);
256 resize_imp(__gnu_pbds::detail::false_type
);
262 get_set_loads_imp(__gnu_pbds::detail::true_type
);
265 get_set_loads_imp(__gnu_pbds::detail::false_type
);
271 get_set_load_imp(__gnu_pbds::detail::true_type
);
274 get_set_load_imp(__gnu_pbds::detail::false_type
);
280 subscript_imp(__gnu_pbds::detail::false_type
);
283 subscript_imp(__gnu_pbds::detail::true_type
);
289 split_join_imp(__gnu_pbds::detail::false_type
);
292 split_join_imp(__gnu_pbds::detail::true_type
);
295 cmp(const Cntnr
&, const native_type
&, const std::string
&);
298 basic_cmp_(const Cntnr
&, const native_type
&);
301 cmp_(const Cntnr
&, const native_type
&);
304 order_preserving_cmp_imp(const Cntnr
&, const native_type
&,
305 __gnu_pbds::detail::false_type
);
308 order_preserving_cmp_imp(const Cntnr
&, const native_type
&,
309 __gnu_pbds::detail::true_type
);
312 back_order_preserving_cmp_imp(const Cntnr
&, const native_type
&,
313 __gnu_pbds::detail::false_type
);
316 back_order_preserving_cmp_imp(const Cntnr
&, const native_type
&,
317 __gnu_pbds::detail::true_type
);
320 reverse_iteration_cmp_imp(const Cntnr
&, const native_type
&,
321 __gnu_pbds::detail::false_type
);
324 reverse_iteration_cmp_imp(const Cntnr
&, const native_type
&,
325 __gnu_pbds::detail::true_type
);
328 order_statistics_cmp_imp(const Cntnr
&, const native_type
&,
329 __gnu_pbds::detail::false_type
);
332 order_statistics_cmp_imp(const Cntnr
&, const native_type
&,
333 __gnu_pbds::detail::true_type
);
336 prefix_search_cmp_imp(const Cntnr
&, const native_type
&,
337 __gnu_pbds::detail::false_type
);
340 prefix_search_cmp_imp(const Cntnr
&, const native_type
&,
341 __gnu_pbds::detail::true_type
);
343 template<typename Const_It
, class Const_Native_It
>
345 it_cmp_imp(Const_It
, Const_It
, Const_Native_It
, Const_Native_It
);
347 template<typename Const_It
, class Const_Native_It
>
349 back_it_cmp_imp(Const_It
, Const_It
, Const_Native_It
, Const_Native_It
);
352 lower_bound_cmp_imp(const Cntnr
&, const native_type
&,
353 __gnu_pbds::detail::false_type
);
356 lower_bound_cmp_imp(const Cntnr
&, const native_type
&,
357 __gnu_pbds::detail::true_type
);
360 upper_bound_cmp_imp(const Cntnr
&, const native_type
&,
361 __gnu_pbds::detail::false_type
);
364 upper_bound_cmp_imp(const Cntnr
&, const native_type
&,
365 __gnu_pbds::detail::true_type
);
368 print_container(const native_type
&, std::ostream
& r_os
= std::cerr
) const;
371 print_container(const cntnr
&, std::ostream
& r_os
= std::cerr
) const;
373 struct destructor_printer
375 destructor_printer(const std::string
& r_msg
)
376 : m_msg(r_msg
), m_print(true) { }
382 ~destructor_printer()
387 std::cerr
<< std::endl
<< "Uncaught exception: " << std::endl
388 << m_msg
<< std::endl
;
392 const std::string m_msg
;
396 const unsigned long m_seed
;
405 twister_rand_gen m_g
;
407 native_type m_native_c
;
412 #ifdef PB_DS_REGRESSION_TRACE
413 #define PB_DS_TRACE(X) std::cerr << X << std::endl
415 #define PB_DS_TRACE(X)
418 #define PB_DS_CLASS_T_DEC \
419 template<typename Cntnr>
421 #define PB_DS_CLASS_C_DEC \
422 container_rand_regression_test<Cntnr>
424 #define PB_DS_COND_COMPARE(L, R) \
425 if (m_g.get_prob() < m_mp) \
426 cmp(L, R, __FUNCTION__);
428 #define PB_DS_RUN_MTHD(MTHD) \
436 #define PB_DS_THROW_IF_FAILED_(PRED, MORE, P_C, P_NC, F, L) \
439 std::cerr << "Failure at " << F << ": " << L << std::endl; \
440 std::cerr << MORE << std::endl; \
441 std::cerr << "container:" << std::endl; \
442 print_container(*(P_C)); \
443 std::cerr << std::endl; \
444 std::cerr << "native container:" << std::endl; \
445 print_container(*(P_NC)); \
446 std::cerr << std::endl; \
447 throw std::logic_error("fucked!"); \
450 #define PB_DS_THROW_IF_FAILED(PRED, MORE, P_C, P_NC) \
451 PB_DS_THROW_IF_FAILED_(PRED, MORE, P_C, P_NC, __FILE__, __LINE__)
453 #define PB_DS_SET_DESTRUCT_PRINT \
454 destructor_printer dest_print___(__FUNCTION__);
456 #define PB_DS_CANCEL_DESTRUCT_PRINT \
457 dest_print___.cancel_print();
459 #include <regression/rand/assoc/container_rand_regression_test.tcc>
461 #undef PB_DS_COND_COMPARE
462 #undef PB_DS_RUN_MTHD
463 #undef PB_DS_CLASS_T_DEC
464 #undef PB_DS_CLASS_C_DEC
465 #undef PB_DS_THROW_IF_FAILED_
466 #undef PB_DS_THROW_IF_FAILED
467 #undef PB_DS_SET_DESTRUCT_PRINT
468 #undef PB_DS_CANCEL_DESTRUCT_PRINT
471 } // namespace detail
473 } // namespace __gnu_pbds