libcxx

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

param_ctor_init.pass.cpp (2397B)


      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 IntType = int>
     15 // class discrete_distribution
     16 
     17 // param_type(initializer_list<double> wl);
     18 
     19 #include <random>
     20 #include <cassert>
     21 
     22 int main()
     23 {
     24     {
     25         typedef std::discrete_distribution<> D;
     26         typedef D::param_type P;
     27         P pa = {};
     28         std::vector<double> p = pa.probabilities();
     29         assert(p.size() == 1);
     30         assert(p[0] == 1);
     31     }
     32     {
     33         typedef std::discrete_distribution<> D;
     34         typedef D::param_type P;
     35         P pa = {10};
     36         std::vector<double> p = pa.probabilities();
     37         assert(p.size() == 1);
     38         assert(p[0] == 1);
     39     }
     40     {
     41         typedef std::discrete_distribution<> D;
     42         typedef D::param_type P;
     43         P pa = {10, 30};
     44         std::vector<double> p = pa.probabilities();
     45         assert(p.size() == 2);
     46         assert(p[0] == 0.25);
     47         assert(p[1] == 0.75);
     48     }
     49     {
     50         typedef std::discrete_distribution<> D;
     51         typedef D::param_type P;
     52         P pa = {30, 10};
     53         std::vector<double> p = pa.probabilities();
     54         assert(p.size() == 2);
     55         assert(p[0] == 0.75);
     56         assert(p[1] == 0.25);
     57     }
     58     {
     59         typedef std::discrete_distribution<> D;
     60         typedef D::param_type P;
     61         P pa = {30, 0, 10};
     62         std::vector<double> p = pa.probabilities();
     63         assert(p.size() == 3);
     64         assert(p[0] == 0.75);
     65         assert(p[1] == 0);
     66         assert(p[2] == 0.25);
     67     }
     68     {
     69         typedef std::discrete_distribution<> D;
     70         typedef D::param_type P;
     71         P pa = {0, 30, 10};
     72         std::vector<double> p = pa.probabilities();
     73         assert(p.size() == 3);
     74         assert(p[0] == 0);
     75         assert(p[1] == 0.75);
     76         assert(p[2] == 0.25);
     77     }
     78     {
     79         typedef std::discrete_distribution<> D;
     80         typedef D::param_type P;
     81         P pa = {0, 0, 10};
     82         std::vector<double> p = pa.probabilities();
     83         assert(p.size() == 3);
     84         assert(p[0] == 0);
     85         assert(p[1] == 0);
     86         assert(p[2] == 1);
     87     }
     88 }