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