OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [util/] [regression/] [rand/] [assoc/] [rand_regression_test.hpp] - Blame information for rev 826

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// -*- C++ -*-
2
 
3
// Copyright (C) 2005, 2006, 2009 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 3, 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 COPYING3.  If not see
18
// <http://www.gnu.org/licenses/>.
19
 
20
 
21
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
22
 
23
// Permission to use, copy, modify, sell, and distribute this software
24
// is hereby granted without fee, provided that the above copyright
25
// notice appears in all copies, and that both that copyright notice
26
// and this permission notice appear in supporting documentation. None
27
// of the above authors, nor IBM Haifa Research Laboratories, make any
28
// representation about the suitability of this software for any
29
// purpose. It is provided "as is" without express or implied
30
// warranty.
31
 
32
/**
33
 * @file rand_regression_test.hpp
34
 * Contains a random-operation test.
35
 */
36
 
37
#ifndef PB_DS_ASSOC_RAND_REGRESSION_TEST_HPP
38
#define PB_DS_ASSOC_RAND_REGRESSION_TEST_HPP
39
 
40
#include <iostream>
41
#include <vector>
42
#include <regression/rand/assoc/container_rand_regression_test.h>
43
#include <io/verified_cmd_line_input.hpp>
44
#include <common_type/assoc/common_type.hpp>
45
#include <regression/basic_type.hpp>
46
#include <regression/common_type.hpp>
47
 
48
namespace __gnu_pbds
49
{
50
namespace test
51
{
52
namespace detail
53
{
54
#ifndef PB_DS_REGRESSION
55
#error "Must define PB_DS_REGRESSION"
56
#endif
57
 
58
  struct rand_reg_test
59
  {
60
  public:
61
    rand_reg_test(size_t seed, size_t n, size_t m, double tp, double ip,
62
                  double ep, double cp, double mp, bool d)
63
    : m_sd(seed), m_n(n), m_m(m), m_tp(tp), m_ip(ip), m_ep(ep), m_cp(cp),
64
      m_mp(mp), m_disp(d)
65
    { }
66
 
67
    template<typename Cntnr>
68
    void
69
    operator()(Cntnr)
70
    {
71
      unsigned long ul = static_cast<unsigned long>(m_sd);
72
      container_rand_regression_test<Cntnr> t(ul, m_n, m_n, m_tp, m_ip,
73
                                              m_ep, m_cp, m_mp, m_disp);
74
      t();
75
    }
76
 
77
  private:
78
    const size_t m_sd;
79
    const size_t m_n;
80
    const size_t m_m;
81
    const double m_tp;
82
    const double m_ip;
83
    const double m_ep;
84
    const double m_cp;
85
    const double m_mp;
86
    const bool m_disp;
87
  };
88
 
89
  void
90
  usage(const std::string& r_name);
91
 
92
  void
93
  verify_params(size_t&, size_t&, size_t&,
94
                double&, double&, double&, double&, double&, bool&);
95
} // namespace detail
96
 
97
  template<typename TL>
98
  int
99
  rand_regression_test(size_t iter, size_t keys, const std::string name, TL tl)
100
  {
101
    // Sane defaults.
102
    size_t n = iter;
103
    size_t m = keys;
104
    size_t sd = twister_rand_gen::get_time_determined_seed();
105
    double tp = 0.2;
106
    double ip = 0.6;
107
    double ep = 0.2;
108
    double cp = 0.001;
109
    double mp = 0.25;
110
    bool disp = false; // show progress
111
 
112
    try
113
      {
114
        detail::verify_params(sd, n, m, tp, ip, ep, cp, mp, disp);
115
      }
116
    catch (__gnu_pbds::test::illegal_input_error&)
117
      {
118
        detail::usage(name);
119
        return -1;
120
      }
121
    catch (...)
122
      {
123
        return -2;
124
      };
125
 
126
    // XXX RAII, constructor takes bool for display
127
    xml_test_rand_regression_formatter* p_fmt = NULL;
128
    if (disp)
129
      p_fmt = new xml_test_rand_regression_formatter(sd, n, m, tp, ip, ep, cp, mp);
130
 
131
    try
132
      {
133
        detail::rand_reg_test tst(sd, n, m, tp, ip, ep, cp, mp, disp);
134
        __gnu_cxx::typelist::apply(tst, tl);
135
      }
136
    catch (...)
137
      {
138
        std::cerr << "Test failed with seed " << sd << std::endl;
139
        if (disp)
140
          delete p_fmt;
141
        throw;
142
      }
143
 
144
    if (disp)
145
      delete p_fmt;
146
    return 0;
147
  }
148
 
149
namespace detail
150
{
151
  inline void
152
  usage(const std::string& name)
153
  {
154
    using namespace std;
155
    cerr << "usage: " << name << " <sd> <n> <m> <tp> <ip> <ep> <cp> <mp> ['t' | 'f']" <<
156
      endl << endl;
157
 
158
    cerr << "This test performs basic regression tests on various associative containers."
159
      "For each container, it performs a sequence of operations. At each iteration, it does "
160
      "the following: " << endl;
161
    cerr << "*  Performs an operation on the container " << endl;
162
    cerr << "*  Performs the same operation on an cntnr object" << endl;
163
    cerr << "*  Possibly compares the container to the cntnr object" << endl;
164
    cerr << "*  Checks that exceptions (thrown by an allocator) "
165
            "do not violate exception guarantees";
166
 
167
    cerr << endl << endl;
168
 
169
    cerr << "sd = seed for random-number generator; "
170
            "0 = time determined value" << endl;
171
    cerr << "n = number of iterations" << endl;
172
    cerr << "m = number of distinct values" << endl;
173
    cerr << "tp = probability that an exception will be actively thrown" << endl;
174
    cerr << "ip = probability that an operation will be insert" << endl;
175
    cerr << "ep = probability that an operation will be erase" << endl;
176
    cerr << "cp = probability that an operation will be clear" << endl;
177
    cerr << "(therefore, 1 - (ip + ep + cp) = probability of any other operation)" << endl;
178
    cerr << "mp = probability that the container will be compared to the cntnr object" << endl;
179
    cerr << "'t' or 'f' determine whether progress will be displayed" << endl;
180
  }
181
 
182
  inline void
183
  verify_params(size_t& r_seed, size_t& r_n,
184
                size_t& r_m, double& r_tp, double& r_ip, double& r_ep,
185
                double& r_cp, double& r_mp, bool& r_d)
186
  {
187
    verify_prob(r_tp);
188
    verify_prob(r_ip);
189
    verify_prob(r_ep);
190
    verify_prob(r_cp);
191
    verify_prob(r_mp);
192
    verify_prob(r_ip + r_ep + r_cp);
193
  }
194
} // namespace detail
195
} // namespace test
196
} // namespace __gnu_pbds
197
 
198
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.