1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <random>
10 
11 // template<class RealType = double>
12 // class piecewise_constant_distribution
13 
14 // template<class UnaryOperation>
15 //     piecewise_constant_distribution(size_t nw, result_type xmin,
16 //                                     result_type xmax, UnaryOperation fw);
17 
18 #include <random>
19 
20 #include <cassert>
21 #include <vector>
22 
23 #include "test_macros.h"
24 
fw(double x)25 double fw(double x)
26 {
27     return 2*x;
28 }
29 
main(int,char **)30 int main(int, char**)
31 {
32     {
33         typedef std::piecewise_constant_distribution<> D;
34         D d(0, 0, 1, fw);
35         std::vector<double> iv = d.intervals();
36         assert(iv.size() == 2);
37         assert(iv[0] == 0);
38         assert(iv[1] == 1);
39         std::vector<double> dn = d.densities();
40         assert(dn.size() == 1);
41         assert(dn[0] == 1);
42     }
43     {
44         typedef std::piecewise_constant_distribution<> D;
45         D d(1, 10, 12, fw);
46         std::vector<double> iv = d.intervals();
47         assert(iv.size() == 2);
48         assert(iv[0] == 10);
49         assert(iv[1] == 12);
50         std::vector<double> dn = d.densities();
51         assert(dn.size() == 1);
52         assert(dn[0] == 0.5);
53     }
54     {
55         typedef std::piecewise_constant_distribution<> D;
56         D d(2, 6, 14, fw);
57         std::vector<double> iv = d.intervals();
58         assert(iv.size() == 3);
59         assert(iv[0] == 6);
60         assert(iv[1] == 10);
61         assert(iv[2] == 14);
62         std::vector<double> dn = d.densities();
63         assert(dn.size() == 2);
64         assert(dn[0] == 0.1);
65         assert(dn[1] == 0.15);
66     }
67 
68   return 0;
69 }
70