libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

param_ctor_func.pass.cpp (1696B)


      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 UnaryOperation>
     16 //     param_type(size_t nw, double xmin, double xmax,
     17 //                           UnaryOperation fw);
     18 
     19 #include <random>
     20 #include <cassert>
     21 
     22 double fw(double x)
     23 {
     24     return x+1;
     25 }
     26 
     27 int main()
     28 {
     29     {
     30         typedef std::discrete_distribution<> D;
     31         typedef D::param_type P;
     32         P pa(0, 0, 1, fw);
     33         std::vector<double> p = pa.probabilities();
     34         assert(p.size() == 1);
     35         assert(p[0] == 1);
     36     }
     37     {
     38         typedef std::discrete_distribution<> D;
     39         typedef D::param_type P;
     40         P pa(1, 0, 1, fw);
     41         std::vector<double> p = pa.probabilities();
     42         assert(p.size() == 1);
     43         assert(p[0] == 1);
     44     }
     45     {
     46         typedef std::discrete_distribution<> D;
     47         typedef D::param_type P;
     48         P pa(2, 0.5, 1.5, fw);
     49         std::vector<double> p = pa.probabilities();
     50         assert(p.size() == 2);
     51         assert(p[0] == .4375);
     52         assert(p[1] == .5625);
     53     }
     54     {
     55         typedef std::discrete_distribution<> D;
     56         typedef D::param_type P;
     57         P pa(4, 0, 2, fw);
     58         std::vector<double> p = pa.probabilities();
     59         assert(p.size() == 4);
     60         assert(p[0] == .15625);
     61         assert(p[1] == .21875);
     62         assert(p[2] == .28125);
     63     }
     64 }