libcxx

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

ctor_func.pass.cpp (1813B)


      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 RealType = double>
     13 // class piecewise_constant_distribution
     14 
     15 // template<class UnaryOperation>
     16 //     piecewise_constant_distribution(size_t nw, result_type xmin,
     17 //                                     result_type xmax, UnaryOperation fw);
     18 
     19 #include <random>
     20 #include <cassert>
     21 
     22 double fw(double x)
     23 {
     24     return 2*x;
     25 }
     26 
     27 int main()
     28 {
     29     {
     30         typedef std::piecewise_constant_distribution<> D;
     31         D d(0, 0, 1, fw);
     32         std::vector<double> iv = d.intervals();
     33         assert(iv.size() == 2);
     34         assert(iv[0] == 0);
     35         assert(iv[1] == 1);
     36         std::vector<double> dn = d.densities();
     37         assert(dn.size() == 1);
     38         assert(dn[0] == 1);
     39     }
     40     {
     41         typedef std::piecewise_constant_distribution<> D;
     42         D d(1, 10, 12, fw);
     43         std::vector<double> iv = d.intervals();
     44         assert(iv.size() == 2);
     45         assert(iv[0] == 10);
     46         assert(iv[1] == 12);
     47         std::vector<double> dn = d.densities();
     48         assert(dn.size() == 1);
     49         assert(dn[0] == 0.5);
     50     }
     51     {
     52         typedef std::piecewise_constant_distribution<> D;
     53         D d(2, 6, 14, fw);
     54         std::vector<double> iv = d.intervals();
     55         assert(iv.size() == 3);
     56         assert(iv[0] == 6);
     57         assert(iv[1] == 10);
     58         assert(iv[2] == 14);
     59         std::vector<double> dn = d.densities();
     60         assert(dn.size() == 2);
     61         assert(dn[0] == 0.1);
     62         assert(dn[1] == 0.15);
     63     }
     64 }