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 // template<class InputIterator>
16 //     piecewise_constant_distribution(InputIteratorB firstB,
17 //                                     InputIteratorB lastB,
18 //                                     InputIteratorW firstW);
19 
20 #include <random>
21 #include <cassert>
22 
23 int main()
24 {
25     {
26         typedef std::piecewise_constant_distribution<> D;
27         double b[] = {10};
28         double p[] = {12};
29         D d(b, b, p);
30         std::vector<double> iv = d.intervals();
31         assert(iv.size() == 2);
32         assert(iv[0] == 0);
33         assert(iv[1] == 1);
34         std::vector<double> dn = d.densities();
35         assert(dn.size() == 1);
36         assert(dn[0] == 1);
37     }
38     {
39         typedef std::piecewise_constant_distribution<> D;
40         double b[] = {10};
41         double p[] = {12};
42         D d(b, b+1, p);
43         std::vector<double> iv = d.intervals();
44         assert(iv.size() == 2);
45         assert(iv[0] == 0);
46         assert(iv[1] == 1);
47         std::vector<double> dn = d.densities();
48         assert(dn.size() == 1);
49         assert(dn[0] == 1);
50     }
51     {
52         typedef std::piecewise_constant_distribution<> D;
53         double b[] = {10, 15};
54         double p[] = {12};
55         D d(b, b+2, p);
56         std::vector<double> iv = d.intervals();
57         assert(iv.size() == 2);
58         assert(iv[0] == 10);
59         assert(iv[1] == 15);
60         std::vector<double> dn = d.densities();
61         assert(dn.size() == 1);
62         assert(dn[0] == 1/5.);
63     }
64     {
65         typedef std::piecewise_constant_distribution<> D;
66         double b[] = {10, 15, 16};
67         double p[] = {.25, .75};
68         D d(b, b+3, p);
69         std::vector<double> iv = d.intervals();
70         assert(iv.size() == 3);
71         assert(iv[0] == 10);
72         assert(iv[1] == 15);
73         assert(iv[2] == 16);
74         std::vector<double> dn = d.densities();
75         assert(dn.size() == 2);
76         assert(dn[0] == .25/5.);
77         assert(dn[1] == .75);
78     }
79     {
80         typedef std::piecewise_constant_distribution<> D;
81         double b[] = {10, 14, 16, 17};
82         double p[] = {25, 62.5, 12.5};
83         D d(b, b+4, p);
84         std::vector<double> iv = d.intervals();
85         assert(iv.size() == 4);
86         assert(iv[0] == 10);
87         assert(iv[1] == 14);
88         assert(iv[2] == 16);
89         assert(iv[3] == 17);
90         std::vector<double> dn = d.densities();
91         assert(dn.size() == 3);
92         assert(dn[0] == .0625);
93         assert(dn[1] == .3125);
94         assert(dn[2] == .125);
95     }
96 }
97