ctor_init_func.pass.cpp (2253B)
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 // UNSUPPORTED: c++98, c++03 11 12 // <random> 13 14 // template<class RealType = double> 15 // class piecewise_linear_distribution 16 17 // piecewise_linear_distribution(initializer_list<result_type> bl, 18 // UnaryOperation fw); 19 20 #include <iostream> 21 22 #include <random> 23 #include <cassert> 24 25 double f(double x) 26 { 27 return x*2; 28 } 29 30 int main() 31 { 32 { 33 typedef std::piecewise_linear_distribution<> D; 34 D d({}, f); 35 std::vector<double> iv = d.intervals(); 36 assert(iv.size() == 2); 37 assert(iv[0] == 0); 38 assert(iv[1] == 1); 39 std::vector<double> dn = d.densities(); 40 assert(dn.size() == 2); 41 assert(dn[0] == 1); 42 assert(dn[1] == 1); 43 } 44 { 45 typedef std::piecewise_linear_distribution<> D; 46 D d({12}, f); 47 std::vector<double> iv = d.intervals(); 48 assert(iv.size() == 2); 49 assert(iv[0] == 0); 50 assert(iv[1] == 1); 51 std::vector<double> dn = d.densities(); 52 assert(dn.size() == 2); 53 assert(dn[0] == 1); 54 assert(dn[1] == 1); 55 } 56 { 57 typedef std::piecewise_linear_distribution<> D; 58 D d({10, 12}, f); 59 std::vector<double> iv = d.intervals(); 60 assert(iv.size() == 2); 61 assert(iv[0] == 10); 62 assert(iv[1] == 12); 63 std::vector<double> dn = d.densities(); 64 assert(dn.size() == 2); 65 assert(dn[0] == 20./44); 66 assert(dn[1] == 24./44); 67 } 68 { 69 typedef std::piecewise_linear_distribution<> D; 70 D d({6, 10, 14}, f); 71 std::vector<double> iv = d.intervals(); 72 assert(iv.size() == 3); 73 assert(iv[0] == 6); 74 assert(iv[1] == 10); 75 assert(iv[2] == 14); 76 std::vector<double> dn = d.densities(); 77 assert(dn.size() == 3); 78 assert(dn[0] == 0.075); 79 assert(dn[1] == 0.125); 80 assert(dn[2] == 0.175); 81 } 82 }