3 // Copyright (C) 2005, 2006, 2009, 2010, 2011
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the terms
8 // of the GNU General Public License as published by the Free Software
9 // Foundation; either version 3, or (at your option) any later
12 // This library is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
24 // Permission to use, copy, modify, sell, and distribute this software
25 // is hereby granted without fee, provided that the above copyright
26 // notice appears in all copies, and that both that copyright notice
27 // and this permission notice appear in supporting documentation. None
28 // of the above authors, nor IBM Haifa Research Laboratories, make any
29 // representation about the suitability of this software for any
30 // purpose. It is provided "as is" without express or implied
34 * @file rand_regression_test.hpp
35 * Contains a random-operation test.
38 #ifndef PB_DS_ASSOC_RAND_REGRESSION_TEST_HPP
39 #define PB_DS_ASSOC_RAND_REGRESSION_TEST_HPP
43 #include <regression/rand/assoc/container_rand_regression_test.h>
44 #include <io/verified_cmd_line_input.hpp>
45 #include <common_type/assoc/common_type.hpp>
46 #include <regression/basic_type.hpp>
47 #include <regression/common_type.hpp>
55 #ifndef PB_DS_REGRESSION
56 #error "Must define PB_DS_REGRESSION"
62 rand_reg_test(size_t seed, size_t n, size_t m, double tp, double ip,
63 double ep, double cp, double mp, bool d)
64 : m_sd(seed), m_n(n), m_m(m), m_tp(tp), m_ip(ip), m_ep(ep), m_cp(cp),
68 xml_test_rand_regression_formatter(seed, n, m, tp, ip, ep, cp, mp);
71 template<typename Cntnr>
75 unsigned long ul = static_cast<unsigned long>(m_sd);
76 container_rand_regression_test<Cntnr> t(ul, m_n, m_n, m_tp, m_ip,
77 m_ep, m_cp, m_mp, m_disp);
94 usage(const std::string& r_name);
97 verify_params(size_t&, size_t&, size_t&,
98 double&, double&, double&, double&, double&, bool&);
101 template<typename TL>
103 rand_regression_test(size_t iter, size_t keys, const std::string name, TL tl)
108 size_t sd = twister_rand_gen::get_time_determined_seed();
114 bool disp = true; // show progress
118 detail::verify_params(sd, n, m, tp, ip, ep, cp, mp, disp);
120 catch(__gnu_pbds::test::illegal_input_error&)
132 detail::rand_reg_test tst(sd, n, m, tp, ip, ep, cp, mp, disp);
133 __gnu_cxx::typelist::apply(tst, tl);
137 std::cerr << "Test failed with seed " << sd << std::endl;
147 usage(const std::string& name)
150 cerr << "usage: " << name
151 << " <sd> <n> <m> <tp> <ip> <ep> <cp> <mp> ['t' | 'f']"
154 cerr << "This test performs basic regression tests on various associative containers."
155 "For each container, it performs a sequence of operations. At each iteration, it does "
156 "the following: " << endl;
157 cerr << "* Performs an operation on the container " << endl;
158 cerr << "* Performs the same operation on an cntnr object" << endl;
159 cerr << "* Possibly compares the container to the cntnr object" << endl;
160 cerr << "* Checks that exceptions (thrown by an allocator) "
161 "do not violate exception guarantees";
163 cerr << endl << endl;
165 cerr << "sd = seed for random-number generator; "
166 "0 = time determined value" << endl;
167 cerr << "n = number of iterations" << endl;
168 cerr << "m = number of distinct values" << endl;
169 cerr << "tp = probability that an exception will be actively thrown" << endl;
170 cerr << "ip = probability that an operation will be insert" << endl;
171 cerr << "ep = probability that an operation will be erase" << endl;
172 cerr << "cp = probability that an operation will be clear" << endl;
173 cerr << "(therefore, 1 - (ip + ep + cp) = probability of any other operation)" << endl;
174 cerr << "mp = probability that the container will be compared to the cntnr object" << endl;
175 cerr << "'t' or 'f' determine whether progress will be displayed" << endl;
179 verify_params(size_t& r_seed, size_t& r_n,
180 size_t& r_m, double& r_tp, double& r_ip, double& r_ep,
181 double& r_cp, double& r_mp, bool& r_d)
188 verify_prob(r_ip + r_ep + r_cp);
190 } // namespace detail
192 } // namespace __gnu_pbds