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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [util/] [regression/] [rand/] [assoc/] [rand_regression_test.hpp] - Blame information for rev 742

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// -*- C++ -*-
2
 
3
// Copyright (C) 2005, 2006, 2009, 2010, 2011
4
// Free Software Foundation, Inc.
5
//
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
10
// version.
11
 
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.
16
 
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/>.
20
 
21
 
22
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
23
 
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
31
// warranty.
32
 
33
/**
34
 * @file rand_regression_test.hpp
35
 * Contains a random-operation test.
36
 */
37
 
38
#ifndef PB_DS_ASSOC_RAND_REGRESSION_TEST_HPP
39
#define PB_DS_ASSOC_RAND_REGRESSION_TEST_HPP
40
 
41
#include <iostream>
42
#include <vector>
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>
48
 
49
namespace __gnu_pbds
50
{
51
namespace test
52
{
53
namespace detail
54
{
55
#ifndef PB_DS_REGRESSION
56
#error "Must define PB_DS_REGRESSION"
57
#endif
58
 
59
  struct rand_reg_test
60
  {
61
  public:
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),
65
      m_mp(mp), m_disp(d)
66
    {
67
      if (m_disp)
68
        xml_test_rand_regression_formatter(seed, n, m, tp, ip, ep, cp, mp);
69
    }
70
 
71
    template<typename Cntnr>
72
    void
73
    operator()(Cntnr)
74
    {
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);
78
      t();
79
    }
80
 
81
  private:
82
    const size_t m_sd;
83
    const size_t m_n;
84
    const size_t m_m;
85
    const double m_tp;
86
    const double m_ip;
87
    const double m_ep;
88
    const double m_cp;
89
    const double m_mp;
90
    const bool m_disp;
91
  };
92
 
93
  void
94
  usage(const std::string& r_name);
95
 
96
  void
97
  verify_params(size_t&, size_t&, size_t&,
98
                double&, double&, double&, double&, double&, bool&);
99
} // namespace detail
100
 
101
  template<typename TL>
102
  int
103
  rand_regression_test(size_t iter, size_t keys, const std::string name, TL tl)
104
  {
105
    // Sane defaults.
106
    size_t n = iter;
107
    size_t m = keys;
108
    size_t sd = twister_rand_gen::get_time_determined_seed();
109
    double tp = 0.2;
110
    double ip = 0.6;
111
    double ep = 0.2;
112
    double cp = 0.001;
113
    double mp = 0.25;
114
    bool disp = true; // show progress
115
 
116
    try
117
      {
118
        detail::verify_params(sd, n, m, tp, ip, ep, cp, mp, disp);
119
      }
120
    catch(__gnu_pbds::test::illegal_input_error&)
121
      {
122
        detail::usage(name);
123
        return -1;
124
      }
125
    catch(...)
126
      {
127
        return -2;
128
      };
129
 
130
    try
131
      {
132
        detail::rand_reg_test tst(sd, n, m, tp, ip, ep, cp, mp, disp);
133
        __gnu_cxx::typelist::apply(tst, tl);
134
      }
135
    catch (...)
136
      {
137
        std::cerr << "Test failed with seed " << sd << std::endl;
138
        throw;
139
      }
140
 
141
    return 0;
142
  }
143
 
144
namespace detail
145
{
146
  inline void
147
  usage(const std::string& name)
148
  {
149
    using namespace std;
150
    cerr << "usage: " << name
151
         << " <sd> <n> <m> <tp> <ip> <ep> <cp> <mp> ['t' | 'f']"
152
         << endl << endl;
153
 
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";
162
 
163
    cerr << endl << endl;
164
 
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;
176
  }
177
 
178
  inline void
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)
182
  {
183
    verify_prob(r_tp);
184
    verify_prob(r_ip);
185
    verify_prob(r_ep);
186
    verify_prob(r_cp);
187
    verify_prob(r_mp);
188
    verify_prob(r_ip + r_ep + r_cp);
189
  }
190
} // namespace detail
191
} // namespace test
192
} // namespace __gnu_pbds
193
 
194
#endif

powered by: WebSVN 2.1.0

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