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_linear_distribution
14 
15 // param_type(initializer_list<result_type> bl, UnaryOperation fw);
16 
17 #include <random>
18 #include <cassert>
19 
f(double x)20 double f(double x)
21 {
22     return x*2;
23 }
24 
main()25 int main()
26 {
27 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
28     {
29         typedef std::piecewise_linear_distribution<> D;
30         typedef D::param_type P;
31         P pa({}, f);
32         std::vector<double> iv = pa.intervals();
33         assert(iv.size() == 2);
34         assert(iv[0] == 0);
35         assert(iv[1] == 1);
36         std::vector<double> dn = pa.densities();
37         assert(dn.size() == 2);
38         assert(dn[0] == 1);
39         assert(dn[1] == 1);
40     }
41     {
42         typedef std::piecewise_linear_distribution<> D;
43         typedef D::param_type P;
44         P pa({12}, f);
45         std::vector<double> iv = pa.intervals();
46         assert(iv.size() == 2);
47         assert(iv[0] == 0);
48         assert(iv[1] == 1);
49         std::vector<double> dn = pa.densities();
50         assert(dn.size() == 2);
51         assert(dn[0] == 1);
52         assert(dn[1] == 1);
53     }
54     {
55         typedef std::piecewise_linear_distribution<> D;
56         typedef D::param_type P;
57         P pa({10, 12}, f);
58         std::vector<double> iv = pa.intervals();
59         assert(iv.size() == 2);
60         assert(iv[0] == 10);
61         assert(iv[1] == 12);
62         std::vector<double> dn = pa.densities();
63         assert(dn.size() == 2);
64         assert(dn[0] == 20./44);
65         assert(dn[1] == 24./44);
66     }
67     {
68         typedef std::piecewise_linear_distribution<> D;
69         typedef D::param_type P;
70         P pa({6, 10, 14}, f);
71         std::vector<double> iv = pa.intervals();
72         assert(iv.size() == 3);
73         assert(iv[0] == 6);
74         assert(iv[1] == 10);
75         assert(iv[2] == 14);
76         std::vector<double> dn = pa.densities();
77         assert(dn.size() == 3);
78         assert(dn[0] == 0.075);
79         assert(dn[1] == 0.125);
80         assert(dn[2] == 0.175);
81     }
82 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
83 }
84