libcxx

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

ctor_init.pass.cpp (2163B)


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