• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // 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_constant_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() == 1);
38         assert(dn[0] == 1);
39     }
40     {
41         typedef std::piecewise_constant_distribution<> D;
42         typedef D::param_type P;
43         P pa({12}, f);
44         std::vector<double> iv = pa.intervals();
45         assert(iv.size() == 2);
46         assert(iv[0] == 0);
47         assert(iv[1] == 1);
48         std::vector<double> dn = pa.densities();
49         assert(dn.size() == 1);
50         assert(dn[0] == 1);
51     }
52     {
53         typedef std::piecewise_constant_distribution<> D;
54         typedef D::param_type P;
55         P pa({12, 14}, f);
56         std::vector<double> iv = pa.intervals();
57         assert(iv.size() == 2);
58         assert(iv[0] == 12);
59         assert(iv[1] == 14);
60         std::vector<double> dn = pa.densities();
61         assert(dn.size() == 1);
62         assert(dn[0] == 0.5);
63     }
64     {
65         typedef std::piecewise_constant_distribution<> D;
66         typedef D::param_type P;
67         P pa({5.5, 7.5, 11.5}, f);
68         std::vector<double> iv = pa.intervals();
69         assert(iv.size() == 3);
70         assert(iv[0] == 5.5);
71         assert(iv[1] == 7.5);
72         assert(iv[2] == 11.5);
73         std::vector<double> dn = pa.densities();
74         assert(dn.size() == 2);
75         assert(dn[0] == 0.203125);
76         assert(dn[1] == 0.1484375);
77     }
78 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
79 }
80