blob: 2dbc48bcc471b4cb7c0090cf87ff3112f7b4f029 [file] [log] [blame]
Howard Hinnantd6d11712010-05-20 15:11:46 +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 RealType = double>
13// class piecewise_constant_distribution
14
15// param_type(initializer_list<result_type> bl, UnaryOperation fw);
16
17#include <random>
18#include <cassert>
19
20double f(double x)
21{
22 return x*2;
23}
24
25int main()
26{
Howard Hinnant73d21a42010-09-04 23:28:19 +000027#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd6d11712010-05-20 15:11:46 +000028 {
29 typedef std::piecewise_constant_distribution<> D;
30 typedef D::param_type P;
31 P pa({}, f);
32 std::vector<double> iv = pa.intervals();
33 assert(iv.size() == 2);
34 assert(iv[0] == 0);
35 assert(iv[1] == 1);
36 std::vector<double> dn = pa.densities();
37 assert(dn.size() == 1);
38 assert(dn[0] == 1);
39 }
40 {
41 typedef std::piecewise_constant_distribution<> D;
42 typedef D::param_type P;
43 P pa({12}, f);
44 std::vector<double> iv = pa.intervals();
45 assert(iv.size() == 2);
46 assert(iv[0] == 0);
47 assert(iv[1] == 1);
48 std::vector<double> dn = pa.densities();
49 assert(dn.size() == 1);
50 assert(dn[0] == 1);
51 }
52 {
53 typedef std::piecewise_constant_distribution<> D;
54 typedef D::param_type P;
55 P pa({12, 14}, f);
56 std::vector<double> iv = pa.intervals();
57 assert(iv.size() == 2);
58 assert(iv[0] == 12);
59 assert(iv[1] == 14);
60 std::vector<double> dn = pa.densities();
61 assert(dn.size() == 1);
62 assert(dn[0] == 0.5);
63 }
64 {
65 typedef std::piecewise_constant_distribution<> D;
66 typedef D::param_type P;
67 P pa({5.5, 7.5, 11.5}, f);
68 std::vector<double> iv = pa.intervals();
69 assert(iv.size() == 3);
70 assert(iv[0] == 5.5);
71 assert(iv[1] == 7.5);
72 assert(iv[2] == 11.5);
73 std::vector<double> dn = pa.densities();
74 assert(dn.size() == 2);
75 assert(dn[0] == 0.203125);
76 assert(dn[1] == 0.1484375);
77 }
Howard Hinnant73d21a42010-09-04 23:28:19 +000078#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd6d11712010-05-20 15:11:46 +000079}