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 rand_regression_test.hpp
44 * Contains a random-operation test.
47 #ifndef PB_DS_PQ_RAND_REGRESSION_TEST_HPP
48 #define PB_DS_PQ_RAND_REGRESSION_TEST_HPP
52 #include <regression/rand/priority_queue/container_rand_regression_test.hpp>
53 #include <io/verified_cmd_line_input.hpp>
54 #include <common_type/priority_queue/common_type.hpp>
55 #include <regression/basic_type.hpp>
56 #include <regression/priority_queue/common_type.hpp>
64 #ifndef PB_DS_REGRESSION
65 #error "Must define PB_DS_REGRESSION"
71 rand_reg_test(size_t seed, size_t n, size_t m, double tp, double ip,
72 double dp, double ep, double cp, double mp, bool d)
73 : m_sd(seed), m_n(n), m_m(m), m_tp(tp), m_ip(ip), m_dp(dp), m_ep(ep),
74 m_cp(cp), m_mp(mp), m_disp(d)
77 template<typename Cntnr>
79 operator()(pb_ds::detail::type_to_type<Cntnr>)
81 unsigned long ul = static_cast<unsigned long>(m_sd);
82 container_rand_regression_test<Cntnr> t(ul, m_n, m_n, m_tp, m_ip, m_dp,
83 m_ep, m_cp, m_mp, m_disp);
101 usage(const std::string& r_name);
104 verify_params(size_t&, size_t&, size_t&,
105 double&, double&, double&, double&, double&, double&, bool&);
106 } // namespace detail
108 template<typename TL>
110 rand_regression_test(size_t iter, size_t keys, const std::string name, TL tl)
115 size_t sd = 0; // 0 = time-determined arbitrary
122 bool disp = false; // show progress
126 detail::verify_params(sd, n, m, tp, ip, dp, ep, cp, mp, disp);
128 catch(pb_ds::test::illegal_input_error&)
138 xml_test_rand_regression_formatter* p_fmt = NULL;
140 sd = twister_rand_gen::get_time_determined_seed();
142 p_fmt = new xml_test_rand_regression_formatter(sd, n, m, tp, ip, dp,
147 detail::rand_reg_test tst(sd, n, m, tp, ip, dp, ep, cp, mp, disp);
148 pb_ds::detail::typelist_apply(tst, tl);
152 std::cerr << "Test failed with seed " << sd << std::endl;
166 usage(const std::string& name)
169 cerr << "usage: " << name << " <sd> <n> <m> <tp> <ip> <dp> <ep> <cp> <mp> ['t' | 'f']" <<
172 cerr << "This test performs basic regression tests on various priority queues."
173 "For each container, it performs a sequence of operations. At each iteration, it does "
174 "the following: " << endl;
175 cerr << "* Performs an operation on the container " << endl;
176 cerr << "* Performs the same operation on an cntnr object" << endl;
177 cerr << "* Possibly compares the container to the cntnr object" << endl;
178 cerr << "* Checks that exceptions (thrown by an allocator) "
179 "do not violate exception guarantees";
181 cerr << endl << endl;
183 cerr << "sd = seed for random-number generator; 0 = "
184 "time determined value" << endl;
185 cerr << "n = number of iterations" << endl;
186 cerr << "m = number of distinct values" << endl;
187 cerr << "tp = probability that an exception will be actively thrown" << endl;
188 cerr << "ip = probability that an operation will be insert" << endl;
189 cerr << "dp = probability that an operation will be modify" << endl;
190 cerr << "ep = probability that an operation will be erase" << endl;
191 cerr << "cp = probability that an operation will be clear" << endl;
192 cerr << "(therefore, 1 - (ip + dp + ep + cp) = probability of any other operation)" << endl;
193 cerr << "mp = probability that the container will be compared to the cntnr object" << endl;
194 cerr << "'t' or 'f' determine whether progress will be displayed" << endl;
198 verify_params(size_t& r_seed, size_t& r_n,
199 size_t& r_m, double& r_tp, double& r_ip, double& r_dp,
200 double& r_ep, double& r_cp, double& r_mp, bool& r_d)
208 verify_prob(r_ip + r_dp + r_ep + r_cp);
210 } // namespace detail