Home | History | Annotate | Download | only in rand.dist.samp.pconst
      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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <random>
     13 
     14 // template<class RealType = double>
     15 // class piecewise_constant_distribution
     16 
     17 // piecewise_constant_distribution(initializer_list<result_type> bl,
     18 //                                 UnaryOperation fw);
     19 
     20 #include <iostream>
     21 
     22 #include <random>
     23 #include <cassert>
     24 
     25 double f(double x)
     26 {
     27     return x*2;
     28 }
     29 
     30 int main()
     31 {
     32     {
     33         typedef std::piecewise_constant_distribution<> D;
     34         D d({}, f);
     35         std::vector<double> iv = d.intervals();
     36         assert(iv.size() == 2);
     37         assert(iv[0] == 0);
     38         assert(iv[1] == 1);
     39         std::vector<double> dn = d.densities();
     40         assert(dn.size() == 1);
     41         assert(dn[0] == 1);
     42     }
     43     {
     44         typedef std::piecewise_constant_distribution<> D;
     45         D d({12}, f);
     46         std::vector<double> iv = d.intervals();
     47         assert(iv.size() == 2);
     48         assert(iv[0] == 0);
     49         assert(iv[1] == 1);
     50         std::vector<double> dn = d.densities();
     51         assert(dn.size() == 1);
     52         assert(dn[0] == 1);
     53     }
     54     {
     55         typedef std::piecewise_constant_distribution<> D;
     56         D d({12, 14}, f);
     57         std::vector<double> iv = d.intervals();
     58         assert(iv.size() == 2);
     59         assert(iv[0] == 12);
     60         assert(iv[1] == 14);
     61         std::vector<double> dn = d.densities();
     62         assert(dn.size() == 1);
     63         assert(dn[0] == 0.5);
     64     }
     65     {
     66         typedef std::piecewise_constant_distribution<> D;
     67         D d({5.5, 7.5, 11.5}, f);
     68         std::vector<double> iv = d.intervals();
     69         assert(iv.size() == 3);
     70         assert(iv[0] == 5.5);
     71         assert(iv[1] == 7.5);
     72         assert(iv[2] == 11.5);
     73         std::vector<double> dn = d.densities();
     74         assert(dn.size() == 2);
     75         assert(dn[0] == 0.203125);
     76         assert(dn[1] == 0.1484375);
     77     }
     78 }
     79