Debian Codegraph @

libcxx/test/std/numerics/rand/rand.dist/rand.dist.bern/rand.dist.bern.bernoulli/ctor_double.pass.cpp

raw
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 // class bernoulli_distribution
12
13 // explicit bernoulli_distribution(double p = 0.5); // before C++20
14 // bernoulli_distribution() : bernoulli_distribution(0.5) {} // C++20
15 // explicit bernoulli_distribution(double p); // C++20
16
17 #include <random>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #if TEST_STD_VER >= 11
22 #include "make_implicit.h"
23 #include "test_convertible.h"
24 #endif
25
26 int main(int, char**)
27 {
28 {
29 typedef std::bernoulli_distribution D;
30 D d;
31 assert(d.p() == 0.5);
32 }
33 {
34 typedef std::bernoulli_distribution D;
35 D d(0);
36 assert(d.p() == 0);
37 }
38 {
39 typedef std::bernoulli_distribution D;
40 D d(0.75);
41 assert(d.p() == 0.75);
42 }
43
44 #if TEST_STD_VER >= 11
45 {
46 typedef std::bernoulli_distribution D;
47 static_assert(test_convertible<D>(), "");
48 assert(D(0.5) == make_implicit<D>());
49 static_assert(!test_convertible<D, double>(), "");
50 }
51 #endif
52
53 return 0;
54 }