|
| 1 | +#include <stan/math/prim.hpp> |
| 2 | +#include <test/unit/math/prim/prob/vector_rng_test_helper.hpp> |
| 3 | +#include <test/unit/math/prim/prob/VectorIntRNGTestRig.hpp> |
| 4 | +#include <boost/random/mersenne_twister.hpp> |
| 5 | +#include <boost/math/distributions.hpp> |
| 6 | +#include <gtest/gtest.h> |
| 7 | +#include <limits> |
| 8 | +#include <vector> |
| 9 | + |
| 10 | +class BetaNegBinomialTestRig : public VectorIntRNGTestRig { |
| 11 | + public: |
| 12 | + BetaNegBinomialTestRig() |
| 13 | + : VectorIntRNGTestRig(10000, 10, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 14 | + {1.1, 3.1, 8.1}, {1, 3, 8}, {-3.0, -2.0, 0.0}, |
| 15 | + {-3, -2, 0}, {3.1, 4.1, 5.1}, {3, 4, 5}, |
| 16 | + {-2.1, -0.5, 0.0}, {-3, -1, 0}, {1.1, 3.1, 8.1}, |
| 17 | + {1, 3, 8}, {-3.0, -2.0, 0.0}, {-3, -2, 0}) {} |
| 18 | + |
| 19 | + template <typename T1, typename T2, typename T3, typename T_rng> |
| 20 | + auto generate_samples(const T1& N, const T2& alpha, const T3& beta, |
| 21 | + T_rng& rng) const { |
| 22 | + return stan::math::beta_neg_binomial_rng(N, alpha, beta, rng); |
| 23 | + } |
| 24 | + |
| 25 | + template <typename T1> |
| 26 | + double pmf(int y, T1 r, double alpha, double beta) const { |
| 27 | + return std::exp(stan::math::beta_neg_binomial_lpmf(y, r, alpha, beta)); |
| 28 | + } |
| 29 | +}; |
| 30 | + |
| 31 | +TEST(ProbDistributionsBetaNegBinomial, errorCheck) { |
| 32 | + check_dist_throws_int_first_argument(BetaNegBinomialTestRig()); |
| 33 | +} |
| 34 | + |
| 35 | +TEST(ProbDistributionsBetaNegBinomial, distributionCheck) { |
| 36 | + check_counts_int_real_real(BetaNegBinomialTestRig()); |
| 37 | +} |
| 38 | + |
| 39 | +TEST(ProbDistributionBetaNegBinomial, error_check) { |
| 40 | + boost::random::mt19937 rng; |
| 41 | + EXPECT_NO_THROW(stan::math::beta_neg_binomial_rng(4, 0.6, 2.0, rng)); |
| 42 | + |
| 43 | + EXPECT_THROW(stan::math::beta_neg_binomial_rng(-4, 0.6, 2, rng), |
| 44 | + std::domain_error); |
| 45 | + EXPECT_THROW(stan::math::beta_neg_binomial_rng(4, -0.6, 2, rng), |
| 46 | + std::domain_error); |
| 47 | + EXPECT_THROW(stan::math::beta_neg_binomial_rng(4, 0.6, -2, rng), |
| 48 | + std::domain_error); |
| 49 | + EXPECT_THROW(stan::math::beta_neg_binomial_rng( |
| 50 | + 4, stan::math::positive_infinity(), 2, rng), |
| 51 | + std::domain_error); |
| 52 | + EXPECT_THROW(stan::math::beta_neg_binomial_rng( |
| 53 | + 4, 0.6, stan::math::positive_infinity(), rng), |
| 54 | + std::domain_error); |
| 55 | +} |
0 commit comments