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