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
54 #include <ext/pb_ds/assoc_container.hpp>
55 #include <io/prog_bar.hpp>
56 #include <rng/twister_rand_gen.hpp>
57 #include <regression/trait/assoc/trait.hpp>
58 #include <common_type/assoc/string_form.hpp>
59 #include <regression/rand/io/assoc/xml_formatter.hpp>
68 #ifdef PB_DS_REGRESSION_TRACE
69 #define PB_DS_TRACE(X) std::cerr << X << std::endl
71 #define PB_DS_TRACE(X)
74 #define PB_DS_CLASS_T_DEC \
75 template<typename Cntnr>
77 #define PB_DS_CLASS_C_DEC \
78 container_rand_regression_test<Cntnr>
80 #define PB_DS_COND_COMPARE(L, R) \
81 if (m_g.get_prob() < m_mp) \
82 cmp(L, R, __FUNCTION__);
84 #define PB_DS_RUN_MTHD(MTHD) \
92 #define PB_DS_THROW_IF_FAILED_(PRED, MORE, P_C, P_NC, F, L) \
95 std::cerr << "Failure at " << F << ": " << L << std::endl; \
96 std::cerr << MORE << std::endl; \
97 std::cerr << "container:" << std::endl; \
98 print_container(*(P_C)); \
99 std::cerr << std::endl; \
100 std::cerr << "native container:" << std::endl; \
101 print_container(*(P_NC)); \
102 std::cerr << std::endl; \
103 throw std::logic_error("fucked!"); \
106 #define PB_DS_THROW_IF_FAILED(PRED, MORE, P_C, P_NC) \
107 PB_DS_THROW_IF_FAILED_(PRED, MORE, P_C, P_NC, __FILE__, __LINE__)
109 #define PB_DS_SET_DESTRUCT_PRINT \
110 destructor_printer dest_print___(__FUNCTION__);
112 #define PB_DS_CANCEL_DESTRUCT_PRINT \
113 dest_print___.cancel_print();
115 // Rand test specialized for a specific container.
116 template<typename Cntnr
>
117 class container_rand_regression_test
121 container_rand_regression_test(unsigned long, size_t, size_t, double,
122 double, double, double, double, bool);
125 ~container_rand_regression_test();
132 typedef typename
cntnr::allocator allocator
;
133 typedef typename
cntnr::size_type size_type
;
134 typedef regression_test_traits
<Cntnr
> test_traits
;
135 typedef typename
test_traits::key_type key_type
;
136 typedef typename
test_traits::const_key_reference const_key_reference
;
137 typedef typename
test_traits::value_type value_type
;
138 typedef typename
test_traits::native_type native_type
;
139 typedef twister_rand_gen gen
;
140 typedef __gnu_pbds::container_traits
<Cntnr
> container_traits
;
141 typedef __gnu_cxx::throw_allocator
<char> alloc_t
;
155 get_next_sub_op(size_t);
176 node_iterator_defs(__gnu_pbds::detail::false_type
);
179 node_iterator_defs(__gnu_pbds::detail::true_type
);
185 policy_defs(__gnu_pbds::basic_hash_tag
);
188 policy_defs(__gnu_pbds::cc_hash_tag
);
191 policy_defs(__gnu_pbds::gp_hash_tag
);
194 policy_defs(__gnu_pbds::tree_tag
);
197 policy_defs(__gnu_pbds::list_update_tag
);
200 policy_defs(__gnu_pbds::pat_trie_tag
);
206 policy_access(__gnu_pbds::basic_hash_tag
);
209 policy_access(__gnu_pbds::cc_hash_tag
);
212 policy_access(__gnu_pbds::gp_hash_tag
);
215 policy_access(__gnu_pbds::tree_tag
);
218 policy_access(__gnu_pbds::list_update_tag
);
221 policy_access(__gnu_pbds::pat_trie_tag
);
236 rev_it_copy_imp(__gnu_pbds::detail::false_type
);
239 rev_it_copy_imp(__gnu_pbds::detail::true_type
);
242 rev_it_assign_imp(__gnu_pbds::detail::false_type
);
245 rev_it_assign_imp(__gnu_pbds::detail::true_type
);
248 default_constructor();
257 assignment_operator();
263 it_constructor_imp(__gnu_pbds::cc_hash_tag
);
266 it_constructor_imp(__gnu_pbds::gp_hash_tag
);
269 it_constructor_imp(__gnu_pbds::tree_tag
);
272 it_constructor_imp(__gnu_pbds::list_update_tag
);
275 it_constructor_imp(__gnu_pbds::pat_trie_tag
);
287 erase_it_imp(__gnu_pbds::detail::false_type
);
290 erase_it_imp(__gnu_pbds::detail::true_type
);
296 erase_rev_it_imp(__gnu_pbds::detail::false_type
);
299 erase_rev_it_imp(__gnu_pbds::detail::true_type
);
311 resize_imp(__gnu_pbds::detail::true_type
);
314 resize_imp(__gnu_pbds::detail::false_type
);
320 get_set_loads_imp(__gnu_pbds::detail::true_type
);
323 get_set_loads_imp(__gnu_pbds::detail::false_type
);
329 get_set_load_imp(__gnu_pbds::detail::true_type
);
332 get_set_load_imp(__gnu_pbds::detail::false_type
);
338 subscript_imp(__gnu_pbds::detail::false_type
);
341 subscript_imp(__gnu_pbds::detail::true_type
);
347 split_join_imp(__gnu_pbds::detail::false_type
);
350 split_join_imp(__gnu_pbds::detail::true_type
);
353 cmp(const Cntnr
&, const native_type
&, const std::string
&);
356 basic_cmp_(const Cntnr
&, const native_type
&);
359 cmp_(const Cntnr
&, const native_type
&);
362 order_preserving_cmp_imp(const Cntnr
&, const native_type
&,
363 __gnu_pbds::detail::false_type
);
366 order_preserving_cmp_imp(const Cntnr
&, const native_type
&,
367 __gnu_pbds::detail::true_type
);
370 back_order_preserving_cmp_imp(const Cntnr
&, const native_type
&,
371 __gnu_pbds::detail::false_type
);
374 back_order_preserving_cmp_imp(const Cntnr
&, const native_type
&,
375 __gnu_pbds::detail::true_type
);
378 reverse_iteration_cmp_imp(const Cntnr
&, const native_type
&,
379 __gnu_pbds::detail::false_type
);
382 reverse_iteration_cmp_imp(const Cntnr
&, const native_type
&,
383 __gnu_pbds::detail::true_type
);
386 order_statistics_cmp_imp(const Cntnr
&, const native_type
&,
387 __gnu_pbds::detail::false_type
);
390 order_statistics_cmp_imp(const Cntnr
&, const native_type
&,
391 __gnu_pbds::detail::true_type
);
394 prefix_search_cmp_imp(const Cntnr
&, const native_type
&,
395 __gnu_pbds::detail::false_type
);
398 prefix_search_cmp_imp(const Cntnr
&, const native_type
&,
399 __gnu_pbds::detail::true_type
);
401 template<typename Const_It
, class Const_Native_It
>
403 it_cmp_imp(Const_It
, Const_It
, Const_Native_It
, Const_Native_It
);
405 template<typename Const_It
, class Const_Native_It
>
407 back_it_cmp_imp(Const_It
, Const_It
, Const_Native_It
, Const_Native_It
);
410 lower_bound_cmp_imp(const Cntnr
&, const native_type
&,
411 __gnu_pbds::detail::false_type
);
414 lower_bound_cmp_imp(const Cntnr
&, const native_type
&,
415 __gnu_pbds::detail::true_type
);
418 upper_bound_cmp_imp(const Cntnr
&, const native_type
&,
419 __gnu_pbds::detail::false_type
);
422 upper_bound_cmp_imp(const Cntnr
&, const native_type
&,
423 __gnu_pbds::detail::true_type
);
426 print_container(const native_type
&, std::ostream
& r_os
= std::cerr
) const;
429 print_container(const cntnr
&, std::ostream
& r_os
= std::cerr
) const;
431 struct destructor_printer
433 destructor_printer(const std::string
& r_msg
)
434 : m_msg(r_msg
), m_print(true) { }
440 ~destructor_printer()
445 std::cerr
<< std::endl
<< "Uncaught exception: " << std::endl
446 << m_msg
<< std::endl
;
450 const std::string m_msg
;
454 const unsigned long m_seed
;
463 twister_rand_gen m_g
;
465 native_type m_native_c
;
470 #include <regression/rand/assoc/detail/constructor_destructor_fn_imps.hpp>
471 #include <regression/rand/assoc/detail/cmp_fn_imps.hpp>
472 #include <regression/rand/assoc/detail/operator_fn_imps.hpp>
473 #include <regression/rand/assoc/detail/insert_fn_imps.hpp>
474 #include <regression/rand/assoc/detail/subscript_fn_imps.hpp>
475 #include <regression/rand/assoc/detail/clear_fn_imps.hpp>
476 #include <regression/rand/assoc/detail/erase_fn_imps.hpp>
477 #include <regression/rand/assoc/detail/defs_fn_imps.hpp>
478 #include <regression/rand/assoc/detail/policy_access_fn_imps.hpp>
479 #include <regression/rand/assoc/detail/split_join_fn_imps.hpp>
480 #include <regression/rand/assoc/detail/it_conversion_fn_imps.hpp>
481 #include <regression/rand/assoc/detail/resize_fn_imps.hpp>
482 #include <regression/rand/assoc/detail/get_set_load_fn_imps.hpp>
483 #include <regression/rand/assoc/detail/get_set_loads_fn_imps.hpp>
484 #include <regression/rand/assoc/detail/diagnostic_fn_imps.hpp>
486 #undef PB_DS_COND_COMPARE
487 #undef PB_DS_RUN_MTHD
488 #undef PB_DS_CLASS_T_DEC
489 #undef PB_DS_CLASS_C_DEC
490 #undef PB_DS_THROW_IF_FAILED_
491 #undef PB_DS_THROW_IF_FAILED
492 #undef PB_DS_SET_DESTRUCT_PRINT
493 #undef PB_DS_CANCEL_DESTRUCT_PRINT
496 } // namespace detail
498 } // namespace __gnu_pbds