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_linear_distribution |
13 | |
14 | // explicit piecewise_linear_distribution(const param_type& parm); |
15 | |
16 | #include <random> |
17 | |
18 | #include <cassert> |
19 | #include <vector> |
20 | |
21 | #include "test_macros.h" |
22 | |
23 | int main(int, char**) |
24 | { |
25 | { |
26 | typedef std::piecewise_linear_distribution<> D; |
27 | typedef D::param_type P; |
28 | double b[] = {10, 14, 16, 17}; |
29 | double p[] = {25, 62.5, 12.5, 0}; |
30 | P pa(b, b+4, p); |
31 | D d(pa); |
32 | std::vector<double> iv = d.intervals(); |
33 | assert(iv.size() == 4); |
34 | assert(iv[0] == 10); |
35 | assert(iv[1] == 14); |
36 | assert(iv[2] == 16); |
37 | assert(iv[3] == 17); |
38 | std::vector<double> dn = d.densities(); |
39 | assert(dn.size() == 4); |
40 | assert(dn[0] == 25/256.25); |
41 | assert(dn[1] == 62.5/256.25); |
42 | assert(dn[2] == 12.5/256.25); |
43 | assert(dn[3] == 0); |
44 | } |
45 | |
46 | return 0; |
47 | } |
48 | |