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 // template<class InputIterator>
16 //     param_type(InputIteratorB firstB, InputIteratorB lastB,
17 //                InputIteratorW firstW);
18 
19 #include <random>
20 #include <cassert>
21 
main()22 int main()
23 {
24     {
25         typedef std::piecewise_linear_distribution<> D;
26         typedef D::param_type P;
27         double b[] = {10};
28         double p[] = {12};
29         P pa(b, b, p);
30         std::vector<double> iv = pa.intervals();
31         assert(iv.size() == 2);
32         assert(iv[0] == 0);
33         assert(iv[1] == 1);
34         std::vector<double> dn = pa.densities();
35         assert(dn.size() == 2);
36         assert(dn[0] == 1);
37         assert(dn[1] == 1);
38     }
39     {
40         typedef std::piecewise_linear_distribution<> D;
41         typedef D::param_type P;
42         double b[] = {10};
43         double p[] = {12};
44         P pa(b, b+1, p);
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         double b[] = {10, 15};
58         double p[] = {12, 12};
59         P pa(b, b+2, p);
60         std::vector<double> iv = pa.intervals();
61         assert(iv.size() == 2);
62         assert(iv[0] == 10);
63         assert(iv[1] == 15);
64         std::vector<double> dn = pa.densities();
65         assert(dn.size() == 2);
66         assert(dn[0] == 1/5.);
67         assert(dn[1] == 1/5.);
68     }
69     {
70         typedef std::piecewise_linear_distribution<> D;
71         typedef D::param_type P;
72         double b[] = {10, 15, 16};
73         double p[] = {.25, .75, .25};
74         P pa(b, b+3, p);
75         std::vector<double> iv = pa.intervals();
76         assert(iv.size() == 3);
77         assert(iv[0] == 10);
78         assert(iv[1] == 15);
79         assert(iv[2] == 16);
80         std::vector<double> dn = pa.densities();
81         assert(dn.size() == 3);
82         assert(dn[0] == .25/3);
83         assert(dn[1] == .75/3);
84         assert(dn[2] == .25/3);
85     }
86     {
87         typedef std::piecewise_linear_distribution<> D;
88         typedef D::param_type P;
89         double b[] = {10, 14, 16, 17};
90         double p[] = {0, 1, 1, 0};
91         P pa(b, b+4, p);
92         std::vector<double> iv = pa.intervals();
93         assert(iv.size() == 4);
94         assert(iv[0] == 10);
95         assert(iv[1] == 14);
96         assert(iv[2] == 16);
97         assert(iv[3] == 17);
98         std::vector<double> dn = pa.densities();
99         assert(dn.size() == 4);
100         assert(dn[0] == 0);
101         assert(dn[1] == 1/4.5);
102         assert(dn[2] == 1/4.5);
103         assert(dn[3] == 0);
104     }
105 }
106