source: trunk/test/rnd_test.cc @ 798

Last change on this file since 798 was 798, checked in by Jari Häkkinen, 16 years ago

Removed unnecessary #include. Added tests for random number distributions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1// $Id: rnd_test.cc 798 2007-03-12 23:52:43Z jari $
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "yat/random/random.h"
25#include "yat/statistics/Histogram.h"
26
27#include <iostream>
28#include <sstream>
29#include <fstream>
30
31int main(const int argc,const char* argv[])
32{
33  using namespace theplu::yat::random;
34  std::ostream* message;
35  if (argc>1 && argv[1]==std::string("-v"))
36    message = &std::cerr;
37  else {
38    message = new std::ofstream("/dev/null");
39    if (argc>1)
40      std::cout << "rnd_test -v : for printing extra information\n";
41  }
42  *message << "testing rnd" << std::endl;
43  bool ok = true;
44
45  RNG* rng=RNG::instance();
46  rng->seed_from_devurandom();
47
48  // testing that minimal integer is zero for the generator
49  *message << "Checking that RNG minimum value is zero" << std::endl;
50  if (rng->min()){
51    *message << "Error: rng->min is not zero" << std::endl;
52    ok = false;
53  }
54
55  *message << "Checking that all random generator can be constructed"
56           << std::endl;
57  theplu::yat::statistics::Histogram histogram(0,100,1000);
58  DiscreteGeneral dg(histogram);
59  DiscreteUniform du;
60  Poisson p;
61  ContinuousUniform cu;
62  ContinuousGeneral cg(histogram);
63  Exponential e;
64  Gaussian g;
65
66  if (message!=&std::cerr)
67    delete message;
68
69  return (ok ? 0 : -1);
70}
Note: See TracBrowser for help on using the repository browser.