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 constructor_destructor_fn_imps.hpp
44 * Containsert a random regression test for a specific container type.
49 container_rand_regression_test(unsigned long seed
, size_t n
, size_t m
,
50 double tp
, double ip
, double ep
, double cp
,
52 : m_seed((seed
== 0) ? twister_rand_gen::get_time_determined_seed() : seed
),
53 m_n(n
), m_m(m
), m_tp(tp
), m_ip(ip
), m_ep(ep
), m_cp(cp
), m_mp(mp
),
54 m_disp(disp
), m_p_c(NULL
)
59 ~container_rand_regression_test()
67 PB_DS_TRACE("default_constructor");
69 m_alloc
.set_throw_prob(m_tp
);
75 catch(__gnu_cxx::forced_exception_error
&)
81 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);
91 m_alloc
.set_throw_prob(0);
92 Cntnr
* p_c
= new Cntnr
;
93 m_alloc
.set_throw_prob(1);
95 std::swap(p_c
, m_p_c
);
97 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);
105 PB_DS_TRACE("copy_constructor");
108 m_alloc
.set_throw_prob(m_tp
);
109 typename
alloc_t::group_throw_prob_adjustor
adjust(m_p_c
->size());
113 p_c
= new Cntnr(*m_p_c
);
114 std::swap(p_c
, m_p_c
);
116 catch(__gnu_cxx::forced_exception_error
& )
122 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);
129 assignment_operator()
131 PB_DS_TRACE("assignment operator");
134 m_alloc
.set_throw_prob(m_tp
);
135 typename
alloc_t::group_throw_prob_adjustor
adjust(m_p_c
->size());
141 std::swap(p_c
, m_p_c
);
143 catch(__gnu_cxx::forced_exception_error
& )
149 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);
158 PB_DS_TRACE("it_constructor");
159 return it_constructor_imp(typename
Cntnr::container_category());
165 it_constructor_imp(__gnu_pbds::cc_hash_tag
)
169 m_alloc
.set_throw_prob(m_tp
);
170 typename
alloc_t::group_throw_prob_adjustor
adjust(m_p_c
->size());
174 switch(get_next_sub_op(8))
177 p_c
= new Cntnr(m_p_c
->get_hash_fn());
181 p_c
= new Cntnr(m_p_c
->get_hash_fn(), m_p_c
->get_eq_fn());
185 p_c
= new Cntnr(m_p_c
->get_hash_fn(), m_p_c
->get_eq_fn(),
186 m_p_c
->get_comb_hash_fn());
190 p_c
= new Cntnr(m_p_c
->get_hash_fn(), m_p_c
->get_eq_fn(),
191 m_p_c
->get_comb_hash_fn(),
192 m_p_c
->get_resize_policy());
196 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end());
199 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn());
202 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn(),
206 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn(),
207 m_p_c
->get_eq_fn(), m_p_c
->get_comb_hash_fn());
210 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn(),
211 m_p_c
->get_eq_fn(), m_p_c
->get_comb_hash_fn(),
212 m_p_c
->get_resize_policy());
215 PB_DS_THROW_IF_FAILED(false, "", m_p_c
, & m_native_c
);
217 std::swap(p_c
, m_p_c
);
219 catch (__gnu_cxx::forced_exception_error
&)
225 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);
232 it_constructor_imp(__gnu_pbds::gp_hash_tag
)
236 m_alloc
.set_throw_prob(m_tp
);
237 typename
alloc_t::group_throw_prob_adjustor
adjust(m_p_c
->size());
241 switch(get_next_sub_op(11))
244 p_c
= new Cntnr(m_p_c
->get_hash_fn());
248 p_c
= new Cntnr(m_p_c
->get_hash_fn(), m_p_c
->get_eq_fn());
252 p_c
= new Cntnr(m_p_c
->get_hash_fn(), m_p_c
->get_eq_fn(),
253 m_p_c
->get_comb_probe_fn());
257 p_c
= new Cntnr(m_p_c
->get_hash_fn(), m_p_c
->get_eq_fn(),
258 m_p_c
->get_comb_probe_fn());
262 p_c
= new Cntnr(m_p_c
->get_hash_fn(), m_p_c
->get_eq_fn(),
263 m_p_c
->get_comb_probe_fn(), m_p_c
->get_probe_fn());
267 p_c
= new Cntnr(m_p_c
->get_hash_fn(), m_p_c
->get_eq_fn(),
268 m_p_c
->get_comb_probe_fn(), m_p_c
->get_probe_fn(),
269 m_p_c
->get_resize_policy());
273 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn());
276 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn(),
280 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn(),
281 m_p_c
->get_eq_fn(), m_p_c
->get_comb_probe_fn());
284 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn(),
285 m_p_c
->get_eq_fn(), m_p_c
->get_comb_probe_fn());
288 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn(),
289 m_p_c
->get_eq_fn(), m_p_c
->get_comb_probe_fn(),
290 m_p_c
->get_probe_fn());
293 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_hash_fn(),
294 m_p_c
->get_eq_fn(), m_p_c
->get_comb_probe_fn(),
295 m_p_c
->get_probe_fn(), m_p_c
->get_resize_policy());
298 PB_DS_THROW_IF_FAILED(false, "", m_p_c
, & m_native_c
);
300 std::swap(p_c
, m_p_c
);
302 catch (__gnu_cxx::forced_exception_error
&)
308 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);
315 it_constructor_imp(__gnu_pbds::tree_tag
)
319 m_alloc
.set_throw_prob(m_tp
);
320 typename
alloc_t::group_throw_prob_adjustor
adjust(m_p_c
->size());
324 switch(get_next_sub_op(2))
327 p_c
= new Cntnr(m_p_c
->get_cmp_fn());
331 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(), m_p_c
->get_cmp_fn());
334 PB_DS_THROW_IF_FAILED(false, "", m_p_c
, &m_native_c
);
336 std::swap(p_c
, m_p_c
);
338 catch (__gnu_cxx::forced_exception_error
&)
344 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);
351 it_constructor_imp(__gnu_pbds::list_update_tag
)
355 m_alloc
.set_throw_prob(m_tp
);
356 typename
alloc_t::group_throw_prob_adjustor
adjust(m_p_c
->size());
360 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end());
361 std::swap(p_c
, m_p_c
);
363 catch (__gnu_cxx::forced_exception_error
&)
369 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);
376 it_constructor_imp(__gnu_pbds::pat_trie_tag
)
380 m_alloc
.set_throw_prob(m_tp
);
381 typename
alloc_t::group_throw_prob_adjustor
adjust(m_p_c
->size());
385 switch(get_next_sub_op(2))
388 p_c
= new Cntnr(m_p_c
->get_e_access_traits());
392 p_c
= new Cntnr(m_p_c
->begin(), m_p_c
->end(),
393 m_p_c
->get_e_access_traits());
396 PB_DS_THROW_IF_FAILED(false, "", m_p_c
, & m_native_c
);
399 std::swap(p_c
, m_p_c
);
401 catch (__gnu_cxx::forced_exception_error
&)
407 PB_DS_COND_COMPARE(*m_p_c
, m_native_c
);