| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03 |
| 10 | |
| 11 | // <random> |
| 12 | |
| 13 | // template<class IntType = int> |
| 14 | // class discrete_distribution |
| 15 | |
| 16 | // param_type(initializer_list<double> wl); |
| 17 | |
| 18 | #include <random> |
| 19 | |
| 20 | #include <cassert> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include "test_macros.h" |
| 24 | |
| 25 | int main(int, char**) |
| 26 | { |
| 27 | { |
| 28 | typedef std::discrete_distribution<> D; |
| 29 | typedef D::param_type P; |
| 30 | P pa = {}; |
| 31 | std::vector<double> p = pa.probabilities(); |
| 32 | assert(p.size() == 1); |
| 33 | assert(p[0] == 1); |
| 34 | } |
| 35 | { |
| 36 | typedef std::discrete_distribution<> D; |
| 37 | typedef D::param_type P; |
| 38 | P pa = {10}; |
| 39 | std::vector<double> p = pa.probabilities(); |
| 40 | assert(p.size() == 1); |
| 41 | assert(p[0] == 1); |
| 42 | } |
| 43 | { |
| 44 | typedef std::discrete_distribution<> D; |
| 45 | typedef D::param_type P; |
| 46 | P pa = {10, 30}; |
| 47 | std::vector<double> p = pa.probabilities(); |
| 48 | assert(p.size() == 2); |
| 49 | assert(p[0] == 0.25); |
| 50 | assert(p[1] == 0.75); |
| 51 | } |
| 52 | { |
| 53 | typedef std::discrete_distribution<> D; |
| 54 | typedef D::param_type P; |
| 55 | P pa = {30, 10}; |
| 56 | std::vector<double> p = pa.probabilities(); |
| 57 | assert(p.size() == 2); |
| 58 | assert(p[0] == 0.75); |
| 59 | assert(p[1] == 0.25); |
| 60 | } |
| 61 | { |
| 62 | typedef std::discrete_distribution<> D; |
| 63 | typedef D::param_type P; |
| 64 | P pa = {30, 0, 10}; |
| 65 | std::vector<double> p = pa.probabilities(); |
| 66 | assert(p.size() == 3); |
| 67 | assert(p[0] == 0.75); |
| 68 | assert(p[1] == 0); |
| 69 | assert(p[2] == 0.25); |
| 70 | } |
| 71 | { |
| 72 | typedef std::discrete_distribution<> D; |
| 73 | typedef D::param_type P; |
| 74 | P pa = {0, 30, 10}; |
| 75 | std::vector<double> p = pa.probabilities(); |
| 76 | assert(p.size() == 3); |
| 77 | assert(p[0] == 0); |
| 78 | assert(p[1] == 0.75); |
| 79 | assert(p[2] == 0.25); |
| 80 | } |
| 81 | { |
| 82 | typedef std::discrete_distribution<> D; |
| 83 | typedef D::param_type P; |
| 84 | P pa = {0, 0, 10}; |
| 85 | std::vector<double> p = pa.probabilities(); |
| 86 | assert(p.size() == 3); |
| 87 | assert(p[0] == 0); |
| 88 | assert(p[1] == 0); |
| 89 | assert(p[2] == 1); |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |