-
-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathbeta_binomial_test.cpp
More file actions
58 lines (51 loc) · 2.05 KB
/
beta_binomial_test.cpp
File metadata and controls
58 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stan/math/prim.hpp>
#include <test/unit/math/prim/prob/vector_rng_test_helper.hpp>
#include <test/unit/math/prim/prob/VectorIntRNGTestRig.hpp>
#include <boost/random/mixmax.hpp>
#include <boost/math/distributions.hpp>
#include <gtest/gtest.h>
#include <limits>
#include <vector>
class BetaBinomialTestRig : public VectorIntRNGTestRig {
public:
BetaBinomialTestRig()
: VectorIntRNGTestRig(10000, 10, {0, 1, 2, 3, 4, 5, 6}, {}, {0, 1, 3, 8},
{}, {-1, -5, -7}, {0.1, 1.7, 3.99}, {1, 2, 3},
{-2.1, -0.5, 0.0}, {-3, -1, 0}, {0.1, 1.1, 4.99},
{1, 2, 3}, {-3.0, -2.0, 0.0}, {-3, -1, 0}) {}
template <typename T1, typename T2, typename T3, typename T_rng>
auto generate_samples(const T1& N, const T2& alpha, const T3& beta,
T_rng& rng) const {
return stan::math::beta_binomial_rng(N, alpha, beta, rng);
}
template <typename T1>
double pmf(int y, T1 N, double alpha, double beta) const {
if (y <= N) {
return std::exp(stan::math::beta_binomial_lpmf(y, N, alpha, beta));
} else {
return 0.0;
}
}
};
TEST(ProbDistributionsBetaBinomial, errorCheck) {
check_dist_throws_int_first_argument(BetaBinomialTestRig());
}
TEST(ProbDistributionsBetaBinomial, distributionCheck) {
check_counts_int_real_real(BetaBinomialTestRig());
}
TEST(ProbDistributionBetaBinomial, error_check) {
boost::random::mixmax rng;
EXPECT_NO_THROW(stan::math::beta_binomial_rng(4, 0.6, 2.0, rng));
EXPECT_THROW(stan::math::beta_binomial_rng(-4, 0.6, 2, rng),
std::domain_error);
EXPECT_THROW(stan::math::beta_binomial_rng(4, -0.6, 2, rng),
std::domain_error);
EXPECT_THROW(stan::math::beta_binomial_rng(4, 0.6, -2, rng),
std::domain_error);
EXPECT_THROW(
stan::math::beta_binomial_rng(4, stan::math::positive_infinity(), 2, rng),
std::domain_error);
EXPECT_THROW(stan::math::beta_binomial_rng(
4, 0.6, stan::math::positive_infinity(), rng),
std::domain_error);
}