OSDN Git Service

310d59b01545491d2cd4ef5eb404fd7c74405039
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / util / regression / rand / priority_queue / container_rand_regression_test.hpp
1 // -*- C++ -*-
2
3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4 //
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
9 // version.
10
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.
15
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.
20
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
29 // Public License.
30
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32
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
40 // warranty.
41
42 /**
43  * @file container_rand_regression_test.hpp
44  * Contains a random regression test for a specific container type.
45  */
46
47 #ifndef PB_DS_CONTAINER_RAND_REGRESSION_TEST_HPP
48 #define PB_DS_CONTAINER_RAND_REGRESSION_TEST_HPP
49
50 #include <algorithm>
51 #include <string>
52 #include <sstream>
53 #include <utility>
54 #include <cassert>
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>
62
63 namespace pb_ds
64 {
65
66   namespace test
67   {
68
69     namespace detail
70     {
71
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
77
78 #define PB_DS_CLASS_T_DEC                       \
79       template<typename Cntnr>
80
81 #define PB_DS_CLASS_C_DEC                               \
82       container_rand_regression_test<                   \
83                                                 Cntnr>
84
85 #define PB_DS_COND_COMPARE(L, R)                \
86       if (m_g.get_prob() < m_mp)                \
87         cmp(L, R, __FUNCTION__);
88
89 #define PB_DS_RUN_MTHD(MTHD)                    \
90       {                                         \
91         bool done = false;                      \
92                                                 \
93         while (!done)                           \
94           done = MTHD();                        \
95       }
96
97 #define PB_DS_THROW_IF_FAILED_(PRED, MORE, P_C, P_NC, F, L)             \
98       if (!(PRED))                                                      \
99         {                                                               \
100           std::cerr << "Failure at " << F << ": " << L << std::endl;    \
101                                                                         \
102           std::cerr << MORE << std::endl;                               \
103                                                                         \
104           std::cerr << "container:" << std::endl;                       \
105                                                                         \
106           print_container(*(P_C));                                      \
107           std::cerr << std::endl;                                       \
108                                                                         \
109           std::cerr << "native container:" << std::endl;                \
110                                                                         \
111           print_container(*(P_NC));                                     \
112           std::cerr << std::endl;                                       \
113                                                                         \
114           throw std::logic_error("fucked!");                            \
115         }
116
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__)
119
120 #define PB_DS_SET_DESTRUCT_PRINT                        \
121       destructor_printer dest_print___(__FUNCTION__);
122
123 #define PB_DS_CANCEL_DESTRUCT_PRINT             \
124       dest_print___.cancel_print();
125
126       // Rand test specialized for a specific container.
127       template<typename Cntnr>
128       class container_rand_regression_test
129       {
130
131       public:
132
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);
134
135         virtual
136         ~container_rand_regression_test();
137
138         void
139         operator()();
140
141       private:
142         typedef Cntnr cntnr;
143
144         typedef typename cntnr::allocator allocator;
145
146         typedef typename cntnr::size_type size_type;
147
148         typedef twister_rand_gen gen;
149
150         typedef basic_type value_type;
151
152         typedef native_priority_queue< std::string, true> native_type;
153
154         enum op
155           {
156             insert_op,
157             modify_op,
158             erase_op,
159             clear_op,
160             other_op
161           };
162
163         typedef dbg_ex_allocator< char> alloc_t;
164
165         typedef regression_test_traits< Cntnr> test_traits;
166
167       private:
168
169         op
170         get_next_op();
171
172         size_t
173         get_next_sub_op(size_t max);
174
175         static void
176         defs();
177
178         static void
179         value_defs();
180
181         static void
182         ds_defs();
183
184         static void
185         iterator_defs();
186
187         static void
188         policy_defs();
189
190         void
191         policy_access();
192
193         void
194         it_copy();
195
196         void
197         it_assign();
198
199         bool
200         default_constructor();
201
202         void
203         swap();
204
205         bool
206         copy_constructor();
207
208         bool
209         assignment_operator();
210
211         bool
212         it_constructor();
213
214         bool
215         push();
216
217         bool
218         modify();
219
220         bool
221         pop();
222
223         bool
224         erase_if();
225
226         bool
227         erase_it();
228
229         bool
230         clear();
231
232         bool
233         split_join();
234
235         void
236         cmp(const Cntnr& r_container, const native_type& r_native_c, const std::string& r_call_fn);
237
238         void
239         print_container(const native_type& r_cnt, std::ostream& r_os = std::cerr) const;
240
241         void
242         print_container(const cntnr& r_cnt, std::ostream& r_os = std::cerr) const;
243
244       private:
245         struct destructor_printer
246         {
247           destructor_printer(const std::string& r_msg) : m_msg(r_msg),
248                                                          m_print(true)
249           { }
250
251           void
252           cancel_print()
253           {
254             m_print = false;
255           }
256
257           ~destructor_printer()
258           {
259             if (!m_print)
260               return;
261
262             std::cerr << std::endl <<
263               "Uncaught exception: " << std::endl <<
264               m_msg << std::endl;
265           }
266
267         private:
268           const std::string m_msg;
269
270           bool m_print;
271         };
272
273       private:
274         const unsigned long m_seed;
275
276         const size_t m_n;
277         const size_t m_m;
278         const double m_tp;
279         const double m_ip;
280         const double m_dp;
281         const double m_ep;
282         const double m_cp;
283         const double m_mp;
284         const bool m_disp;
285
286         twister_rand_gen m_g;
287
288         Cntnr* m_p_c;
289
290         native_type m_native_c;
291
292         alloc_t m_alloc;
293
294         size_t m_i;
295       };
296
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>
309
310 #undef PB_DS_COND_COMPARE
311
312 #undef PB_DS_RUN_MTHD
313
314 #undef PB_DS_CLASS_T_DEC
315
316 #undef PB_DS_CLASS_C_DEC
317
318 #undef PB_DS_THROW_IF_FAILED_
319
320 #undef PB_DS_THROW_IF_FAILED
321
322 #undef PB_DS_SET_DESTRUCT_PRINT
323
324 #undef PB_DS_CANCEL_DESTRUCT_PRINT
325
326 #undef PB_DS_TRACE
327
328     } // namespace detail
329
330   } // namespace test
331
332 } // namespace pb_ds
333
334 #endif // #ifndef PB_DS_CONTAINER_RAND_REGRESSION_TEST_HPP