blob: 90fbc408c9277df2c147a47b4cc3428e62286044 [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// discrete_distribution(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 D d = {};
26 std::vector<double> p = d.probabilities();
27 assert(p.size() == 1);
28 assert(p[0] == 1);
29 }
30 {
31 typedef std::discrete_distribution<> D;
32 D d = {10};
33 std::vector<double> p = d.probabilities();
34 assert(p.size() == 1);
35 assert(p[0] == 1);
36 }
37 {
38 typedef std::discrete_distribution<> D;
39 D d = {10, 30};
40 std::vector<double> p = d.probabilities();
41 assert(p.size() == 2);
42 assert(p[0] == 0.25);
43 assert(p[1] == 0.75);
44 }
45 {
46 typedef std::discrete_distribution<> D;
47 D d = {30, 10};
48 std::vector<double> p = d.probabilities();
49 assert(p.size() == 2);
50 assert(p[0] == 0.75);
51 assert(p[1] == 0.25);
52 }
53 {
54 typedef std::discrete_distribution<> D;
55 D d = {30, 0, 10};
56 std::vector<double> p = d.probabilities();
57 assert(p.size() == 3);
58 assert(p[0] == 0.75);
59 assert(p[1] == 0);
60 assert(p[2] == 0.25);
61 }
62 {
63 typedef std::discrete_distribution<> D;
64 D d = {0, 30, 10};
65 std::vector<double> p = d.probabilities();
66 assert(p.size() == 3);
67 assert(p[0] == 0);
68 assert(p[1] == 0.75);
69 assert(p[2] == 0.25);
70 }
71 {
72 typedef std::discrete_distribution<> D;
73 D d = {0, 0, 10};
74 std::vector<double> p = d.probabilities();
75 assert(p.size() == 3);
76 assert(p[0] == 0);
77 assert(p[1] == 0);
78 assert(p[2] == 1);
79 }
Howard Hinnant73d21a42010-09-04 23:28:19 +000080#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant551d8e42010-05-19 01:53:57 +000081}