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