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 IntType = int> |
12 | // class discrete_distribution |
13 | |
14 | // template<class InputIterator> |
15 | // param_type(InputIterator firstW, InputIterator lastW); |
16 | |
17 | #include <random> |
18 | |
19 | #include <cassert> |
20 | #include <vector> |
21 | |
22 | #include "test_macros.h" |
23 | |
24 | int main(int, char**) |
25 | { |
26 | { |
27 | typedef std::discrete_distribution<> D; |
28 | typedef D::param_type P; |
29 | double p0[] = {1}; |
30 | P pa(p0, p0); |
31 | std::vector<double> p = pa.probabilities(); |
32 | assert(p.size() == 1); |
33 | assert(p[0] == 1); |
34 | } |
35 | { |
36 | typedef std::discrete_distribution<> D; |
37 | typedef D::param_type P; |
38 | double p0[] = {10}; |
39 | P pa(p0, p0+1); |
40 | std::vector<double> p = pa.probabilities(); |
41 | assert(p.size() == 1); |
42 | assert(p[0] == 1); |
43 | } |
44 | { |
45 | typedef std::discrete_distribution<> D; |
46 | typedef D::param_type P; |
47 | double p0[] = {10, 30}; |
48 | P pa(p0, p0+2); |
49 | std::vector<double> p = pa.probabilities(); |
50 | assert(p.size() == 2); |
51 | assert(p[0] == 0.25); |
52 | assert(p[1] == 0.75); |
53 | } |
54 | { |
55 | typedef std::discrete_distribution<> D; |
56 | typedef D::param_type P; |
57 | double p0[] = {30, 10}; |
58 | P pa(p0, p0+2); |
59 | std::vector<double> p = pa.probabilities(); |
60 | assert(p.size() == 2); |
61 | assert(p[0] == 0.75); |
62 | assert(p[1] == 0.25); |
63 | } |
64 | { |
65 | typedef std::discrete_distribution<> D; |
66 | typedef D::param_type P; |
67 | double p0[] = {30, 0, 10}; |
68 | P pa(p0, p0+3); |
69 | std::vector<double> p = pa.probabilities(); |
70 | assert(p.size() == 3); |
71 | assert(p[0] == 0.75); |
72 | assert(p[1] == 0); |
73 | assert(p[2] == 0.25); |
74 | } |
75 | { |
76 | typedef std::discrete_distribution<> D; |
77 | typedef D::param_type P; |
78 | double p0[] = {0, 30, 10}; |
79 | P pa(p0, p0+3); |
80 | std::vector<double> p = pa.probabilities(); |
81 | assert(p.size() == 3); |
82 | assert(p[0] == 0); |
83 | assert(p[1] == 0.75); |
84 | assert(p[2] == 0.25); |
85 | } |
86 | { |
87 | typedef std::discrete_distribution<> D; |
88 | typedef D::param_type P; |
89 | double p0[] = {0, 0, 10}; |
90 | P pa(p0, p0+3); |
91 | std::vector<double> p = pa.probabilities(); |
92 | assert(p.size() == 3); |
93 | assert(p[0] == 0); |
94 | assert(p[1] == 0); |
95 | assert(p[2] == 1); |
96 | } |
97 | |
98 | return 0; |
99 | } |
100 | |