Home | History | Annotate | Download | only in rand.dist.samp.discrete
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <random>
     11 
     12 // template<class IntType = int>
     13 // class discrete_distribution
     14 
     15 // template<class InputIterator>
     16 //     discrete_distribution(InputIterator firstW, InputIterator lastW);
     17 
     18 #include <random>
     19 #include <cassert>
     20 
     21 int main()
     22 {
     23     {
     24         typedef std::discrete_distribution<> D;
     25         double p0[] = {1};
     26         D d(p0, p0);
     27         std::vector<double> p = d.probabilities();
     28         assert(p.size() == 1);
     29         assert(p[0] == 1);
     30     }
     31     {
     32         typedef std::discrete_distribution<> D;
     33         double p0[] = {10};
     34         D d(p0, p0+1);
     35         std::vector<double> p = d.probabilities();
     36         assert(p.size() == 1);
     37         assert(p[0] == 1);
     38     }
     39     {
     40         typedef std::discrete_distribution<> D;
     41         double p0[] = {10, 30};
     42         D d(p0, p0+2);
     43         std::vector<double> p = d.probabilities();
     44         assert(p.size() == 2);
     45         assert(p[0] == 0.25);
     46         assert(p[1] == 0.75);
     47     }
     48     {
     49         typedef std::discrete_distribution<> D;
     50         double p0[] = {30, 10};
     51         D d(p0, p0+2);
     52         std::vector<double> p = d.probabilities();
     53         assert(p.size() == 2);
     54         assert(p[0] == 0.75);
     55         assert(p[1] == 0.25);
     56     }
     57     {
     58         typedef std::discrete_distribution<> D;
     59         double p0[] = {30, 0, 10};
     60         D d(p0, p0+3);
     61         std::vector<double> p = d.probabilities();
     62         assert(p.size() == 3);
     63         assert(p[0] == 0.75);
     64         assert(p[1] == 0);
     65         assert(p[2] == 0.25);
     66     }
     67     {
     68         typedef std::discrete_distribution<> D;
     69         double p0[] = {0, 30, 10};
     70         D d(p0, p0+3);
     71         std::vector<double> p = d.probabilities();
     72         assert(p.size() == 3);
     73         assert(p[0] == 0);
     74         assert(p[1] == 0.75);
     75         assert(p[2] == 0.25);
     76     }
     77     {
     78         typedef std::discrete_distribution<> D;
     79         double p0[] = {0, 0, 10};
     80         D d(p0, p0+3);
     81         std::vector<double> p = d.probabilities();
     82         assert(p.size() == 3);
     83         assert(p[0] == 0);
     84         assert(p[1] == 0);
     85         assert(p[2] == 1);
     86     }
     87 }
     88