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

source code of libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.plinear/param_ctor_init_func.pass.cpp