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