test/rnd.cc

Code
Comments
Other
Rev Date Author Line
42 26 Feb 04 jari 1 // $Id$
42 26 Feb 04 jari 2
675 10 Oct 06 jari 3 /*
831 27 Mar 07 peter 4   Copyright (C) 2003 Daniel Dalevi
2119 12 Dec 09 peter 5   Copyright (C) 2004 Jari Häkkinen
2119 12 Dec 09 peter 6   Copyright (C) 2005 Jari Häkkinen, Peter Johansson
2119 12 Dec 09 peter 7   Copyright (C) 2006 Jari Häkkinen
2119 12 Dec 09 peter 8   Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
4207 26 Aug 22 peter 9   Copyright (C) 2012, 2015, 2016, 2020, 2022 Peter Johansson
377 07 Aug 05 jari 10
1437 25 Aug 08 peter 11   This file is part of the yat library, http://dev.thep.lu.se/yat
675 10 Oct 06 jari 12
675 10 Oct 06 jari 13   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 14   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 15   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 16   License, or (at your option) any later version.
675 10 Oct 06 jari 17
675 10 Oct 06 jari 18   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 19   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 21   General Public License for more details.
675 10 Oct 06 jari 22
675 10 Oct 06 jari 23   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 24   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 25 */
675 10 Oct 06 jari 26
2881 18 Nov 12 peter 27 #include <config.h>
2881 18 Nov 12 peter 28
1245 17 Mar 08 peter 29 #include "Suite.h"
1245 17 Mar 08 peter 30
675 10 Oct 06 jari 31 #include "yat/random/random.h"
798 12 Mar 07 jari 32 #include "yat/statistics/Histogram.h"
675 10 Oct 06 jari 33
13 19 Jun 03 daniel 34 #include <iostream>
379 08 Aug 05 peter 35 #include <sstream>
379 08 Aug 05 peter 36 #include <fstream>
13 19 Jun 03 daniel 37
1245 17 Mar 08 peter 38 int main(int argc, char* argv[])
13 19 Jun 03 daniel 39 {
798 12 Mar 07 jari 40   using namespace theplu::yat::random;
1245 17 Mar 08 peter 41   theplu::yat::test::Suite suite(argc, argv);
1245 17 Mar 08 peter 42   suite.err() << "testing rnd" << std::endl;
379 08 Aug 05 peter 43
798 12 Mar 07 jari 44   RNG* rng=RNG::instance();
798 12 Mar 07 jari 45   rng->seed_from_devurandom();
798 12 Mar 07 jari 46
425 07 Dec 05 jari 47   // testing that minimal integer is zero for the generator
1245 17 Mar 08 peter 48   suite.err() << "Checking that RNG minimum value is zero" << std::endl;
379 08 Aug 05 peter 49   if (rng->min()){
1245 17 Mar 08 peter 50     suite.err() << "Error: rng->min is not zero" << std::endl;
1245 17 Mar 08 peter 51     suite.add(false);
379 08 Aug 05 peter 52   }
379 08 Aug 05 peter 53
1610 04 Nov 08 peter 54   suite.err() << "Checking that all random generators can be constructed\n";
798 12 Mar 07 jari 55   theplu::yat::statistics::Histogram histogram(0,100,1000);
4009 19 Oct 20 peter 56   std::vector<DiscreteGeneral> discrete(10);
798 12 Mar 07 jari 57   DiscreteGeneral dg(histogram);
798 12 Mar 07 jari 58   DiscreteUniform du;
3893 27 Mar 20 peter 59   {
3893 27 Mar 20 peter 60     DiscreteUniform::result_type x = 0;
3893 27 Mar 20 peter 61     theplu::yat::test::avoid_compiler_warning(x);
3893 27 Mar 20 peter 62     DiscreteUniform::argument_type y = 0;
3893 27 Mar 20 peter 63     theplu::yat::test::avoid_compiler_warning(y);
3893 27 Mar 20 peter 64   }
798 12 Mar 07 jari 65   Poisson p;
798 12 Mar 07 jari 66   ContinuousUniform cu;
798 12 Mar 07 jari 67   ContinuousGeneral cg(histogram);
798 12 Mar 07 jari 68   Exponential e;
798 12 Mar 07 jari 69   Gaussian g;
379 08 Aug 05 peter 70
2889 07 Dec 12 peter 71   Binomial bin(0.5, 10);
3446 02 Dec 15 peter 72   Geometric geo(0.5);
3446 02 Dec 15 peter 73   geo();
3446 02 Dec 15 peter 74   geo(0.1);
3465 10 Feb 16 peter 75   HyperGeometric hg;
3465 10 Feb 16 peter 76   hg(10, 100, 4);
3465 10 Feb 16 peter 77   HyperGeometric hg2(10, 100, 4);
3465 10 Feb 16 peter 78   hg2();
3465 10 Feb 16 peter 79   hg2(11, 100, 4);
2889 07 Dec 12 peter 80
3469 29 Feb 16 peter 81   NegativeHyperGeometric nhg;
3469 29 Feb 16 peter 82   nhg(10, 100, 4);
3469 29 Feb 16 peter 83   HyperGeometric nhg2(10, 100, 4);
3469 29 Feb 16 peter 84   nhg2();
3469 29 Feb 16 peter 85   // test that symmetric case doesn't get stuck
3469 29 Feb 16 peter 86   nhg2(11, 100, 6);
3469 29 Feb 16 peter 87
4147 28 Feb 22 peter 88   NegativeBinomial nb(0.5, 12);
4147 28 Feb 22 peter 89
1245 17 Mar 08 peter 90   return suite.return_value();
13 19 Jun 03 daniel 91 }