blob: 8668f25538b4ac558823e04a1d1f2f32a6420119 [file] [log] [blame]
Howard Hinnant551d8e42010-05-19 01:53:57 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <random>
11
12// template<class IntType = int>
13// class discrete_distribution
14
15// param_type(initializer_list<double> wl);
16
17#include <random>
18#include <cassert>
19
20int main()
21{
Howard Hinnant73d21a42010-09-04 23:28:19 +000022#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant551d8e42010-05-19 01:53:57 +000023 {
24 typedef std::discrete_distribution<> D;
25 typedef D::param_type P;
26 P pa = {};
27 std::vector<double> p = pa.probabilities();
28 assert(p.size() == 1);
29 assert(p[0] == 1);
30 }
31 {
32 typedef std::discrete_distribution<> D;
33 typedef D::param_type P;
34 P pa = {10};
35 std::vector<double> p = pa.probabilities();
36 assert(p.size() == 1);
37 assert(p[0] == 1);
38 }
39 {
40 typedef std::discrete_distribution<> D;
41 typedef D::param_type P;
42 P pa = {10, 30};
43 std::vector<double> p = pa.probabilities();
44 assert(p.size() == 2);
45 assert(p[0] == 0.25);
46 assert(p[1] == 0.75);
47 }
48 {
49 typedef std::discrete_distribution<> D;
50 typedef D::param_type P;
51 P pa = {30, 10};
52 std::vector<double> p = pa.probabilities();
53 assert(p.size() == 2);
54 assert(p[0] == 0.75);
55 assert(p[1] == 0.25);
56 }
57 {
58 typedef std::discrete_distribution<> D;
59 typedef D::param_type P;
60 P pa = {30, 0, 10};
61 std::vector<double> p = pa.probabilities();
62 assert(p.size() == 3);
63 assert(p[0] == 0.75);
64 assert(p[1] == 0);
65 assert(p[2] == 0.25);
66 }
67 {
68 typedef std::discrete_distribution<> D;
69 typedef D::param_type P;
70 P pa = {0, 30, 10};
71 std::vector<double> p = pa.probabilities();
72 assert(p.size() == 3);
73 assert(p[0] == 0);
74 assert(p[1] == 0.75);
75 assert(p[2] == 0.25);
76 }
77 {
78 typedef std::discrete_distribution<> D;
79 typedef D::param_type P;
80 P pa = {0, 0, 10};
81 std::vector<double> p = pa.probabilities();
82 assert(p.size() == 3);
83 assert(p[0] == 0);
84 assert(p[1] == 0);
85 assert(p[2] == 1);
86 }
Howard Hinnant73d21a42010-09-04 23:28:19 +000087#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant551d8e42010-05-19 01:53:57 +000088}