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 // discrete_distribution(initializer_list<double> wl); 16 17 #include <random> 18 #include <cassert> 19 20 int main() 21 { 22 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 23 { 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 } 80 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 81 } 82