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_constant_distribution
13
14// template<class InputIterator>
15// param_type(InputIteratorB firstB, InputIteratorB lastB,
16// InputIteratorW firstW);
17
18#include <random>
19
20#include <cassert>
21#include <vector>
22
23#include "test_macros.h"
24
25int main(int, char**)
26{
27 {
28 typedef std::piecewise_constant_distribution<> D;
29 typedef D::param_type P;
30 double b[] = {10};
31 double p[] = {12};
32 P pa(b, b, p);
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() == 1);
39 assert(dn[0] == 1);
40 }
41 {
42 typedef std::piecewise_constant_distribution<> D;
43 typedef D::param_type P;
44 double b[] = {10};
45 double p[] = {12};
46 P pa(b, b+1, p);
47 std::vector<double> iv = pa.intervals();
48 assert(iv.size() == 2);
49 assert(iv[0] == 0);
50 assert(iv[1] == 1);
51 std::vector<double> dn = pa.densities();
52 assert(dn.size() == 1);
53 assert(dn[0] == 1);
54 }
55 {
56 typedef std::piecewise_constant_distribution<> D;
57 typedef D::param_type P;
58 double b[] = {10, 15};
59 double p[] = {12};
60 P pa(b, b+2, p);
61 std::vector<double> iv = pa.intervals();
62 assert(iv.size() == 2);
63 assert(iv[0] == 10);
64 assert(iv[1] == 15);
65 std::vector<double> dn = pa.densities();
66 assert(dn.size() == 1);
67 assert(dn[0] == 1/5.);
68 }
69 {
70 typedef std::piecewise_constant_distribution<> D;
71 typedef D::param_type P;
72 double b[] = {10, 15, 16};
73 double p[] = {.25, .75};
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() == 2);
82 assert(dn[0] == .25/5.);
83 assert(dn[1] == .75);
84 }
85 {
86 typedef std::piecewise_constant_distribution<> D;
87 typedef D::param_type P;
88 double b[] = {10, 14, 16, 17};
89 double p[] = {25, 62.5, 12.5};
90 P pa(b, b+4, p);
91 std::vector<double> iv = pa.intervals();
92 assert(iv.size() == 4);
93 assert(iv[0] == 10);
94 assert(iv[1] == 14);
95 assert(iv[2] == 16);
96 assert(iv[3] == 17);
97 std::vector<double> dn = pa.densities();
98 assert(dn.size() == 3);
99 assert(dn[0] == .0625);
100 assert(dn[1] == .3125);
101 assert(dn[2] == .125);
102 }
103
104 return 0;
105}
106

source code of libcxx/test/std/numerics/rand/rand.dist/rand.dist.samp/rand.dist.samp.pconst/param_ctor_iterator.pass.cpp