| 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 |
// <random> |
| 10 |
|
| 11 |
// template<class RealType = double> |
| 12 |
// class gamma_distribution |
| 13 |
|
| 14 |
// explicit gamma_distribution(RealType alpha = 1.0, RealType beta = 1.0); // before C++20 |
| 15 |
// gamma_distribution() : gamma_distribution(1.0) {} // C++20 |
| 16 |
// explicit gamma_distribution(RealType alpha, RealType beta = 1.0); // C++20 |
| 17 |
|
| 18 |
#include <random> |
| 19 |
#include <cassert> |
| 20 |
|
| 21 |
#include "test_macros.h" |
| 22 |
#if TEST_STD_VER >= 11 |
| 23 |
#include "make_implicit.h" |
| 24 |
#include "test_convertible.h" |
| 25 |
#endif |
| 26 |
|
| 27 |
template <class T> |
| 28 |
void test_implicit() { |
| 29 |
#if TEST_STD_VER >= 11 |
| 30 |
typedef std::gamma_distribution<T> D; |
| 31 |
static_assert(test_convertible<D>(), ""); |
| 32 |
assert(D(1) == make_implicit<D>()); |
| 33 |
static_assert(!test_convertible<D, T>(), ""); |
| 34 |
static_assert(!test_convertible<D, T, T>(), ""); |
| 35 |
#endif |
| 36 |
} |
| 37 |
|
| 38 |
int main(int, char**) |
| 39 |
{ |
| 40 |
{ |
| 41 |
typedef std::gamma_distribution<> D; |
| 42 |
D d; |
| 43 |
assert(d.alpha() == 1); |
| 44 |
assert(d.beta() == 1); |
| 45 |
} |
| 46 |
{ |
| 47 |
typedef std::gamma_distribution<> D; |
| 48 |
D d(14.5); |
| 49 |
assert(d.alpha() == 14.5); |
| 50 |
assert(d.beta() == 1); |
| 51 |
} |
| 52 |
{ |
| 53 |
typedef std::gamma_distribution<> D; |
| 54 |
D d(14.5, 5.25); |
| 55 |
assert(d.alpha() == 14.5); |
| 56 |
assert(d.beta() == 5.25); |
| 57 |
} |
| 58 |
|
| 59 |
test_implicit<float>(); |
| 60 |
test_implicit<double>(); |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |