2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

added median tests.

[SVN r3541]
This commit is contained in:
Paul A. Bristow
2006-12-20 15:50:50 +00:00
parent 2f47640e6c
commit 4863b82990
4 changed files with 24 additions and 16 deletions

View File

@@ -156,6 +156,10 @@ void test_spots(RealType)
BOOST_CHECK_THROW(mode(beta_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(1))), std::domain_error);
// mode is undefined, and throws domain_error!
BOOST_CHECK_THROW(median(beta_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(1))), std::domain_error);
// median is undefined, and throws domain_error!
BOOST_CHECK_THROW( // For various bad arguments.
pdf(
beta_distribution<RealType>(static_cast<RealType>(-1), static_cast<RealType>(1)), // bad alpha < 0.

View File

@@ -588,24 +588,24 @@ void test_spots(RealType)
{
// This is a visual sanity check that everything is OK:
binomial_distribution<RealType> my8dist(8., 0.25); // Note: double values (matching the distribution definition) avoid the need for any casting.
cout << "mean(my8dist) = " << boost::math::mean(my8dist) << endl; // mean(my8dist) = 2
cout << "my8dist.trials() = " << my8dist.trials() << endl; // my8dist.trials() = 8
cout << "my8dist.success_fraction() = " << my8dist.success_fraction() << endl; // my8dist.success_fraction() = 0.25
//cout << "mean(my8dist) = " << boost::math::mean(my8dist) << endl; // mean(my8dist) = 2
//cout << "my8dist.trials() = " << my8dist.trials() << endl; // my8dist.trials() = 8
//cout << "my8dist.success_fraction() = " << my8dist.success_fraction() << endl; // my8dist.success_fraction() = 0.25
BOOST_CHECK_CLOSE(my8dist.trials(), static_cast<RealType>(8), tol2);
BOOST_CHECK_CLOSE(my8dist.success_fraction(), static_cast<RealType>(0.25), tol2);
{
int n = static_cast<int>(boost::math::tools::real_cast<double>(my8dist.trials()));
RealType sumcdf = 0.;
for (int k = 0; k <= n; k++)
{
cout << k << ' ' << pdf(my8dist, static_cast<RealType>(k));
sumcdf += pdf(my8dist, static_cast<RealType>(k));
cout << ' ' << sumcdf;
cout << ' ' << cdf(my8dist, static_cast<RealType>(k));
cout << ' ' << sumcdf - cdf(my8dist, static_cast<RealType>(k)) << endl;
} // for k
}
//{
// int n = static_cast<int>(boost::math::tools::real_cast<double>(my8dist.trials()));
// RealType sumcdf = 0.;
// for (int k = 0; k <= n; k++)
// {
// cout << k << ' ' << pdf(my8dist, static_cast<RealType>(k));
// sumcdf += pdf(my8dist, static_cast<RealType>(k));
// cout << ' ' << sumcdf;
// cout << ' ' << cdf(my8dist, static_cast<RealType>(k));
// cout << ' ' << sumcdf - cdf(my8dist, static_cast<RealType>(k)) << endl;
// } // for k
// }
// n = 8, p =0.25
//k pdf cdf
//0 0.1001129150390625 0.1001129150390625

View File

@@ -318,6 +318,10 @@ void test_spots(RealType T)
BOOST_CHECK_CLOSE(
mean(dist)
, static_cast<RealType>(0), tol2);
// median:
BOOST_CHECK_CLOSE(
median(dist)
, static_cast<RealType>(0), tol2);
// skewness:
BOOST_CHECK_CLOSE(
skewness(dist)

View File

@@ -530,7 +530,7 @@ int test_main(int, char* [])
BOOST_CHECK_EQUAL(tristd.mode(), 0);
BOOST_CHECK_EQUAL(tristd.upper(), 1);
cout << median(tristd) << endl;
cout << range(tristd).first << ' ' << range(tristd).second << endl;
triangular_distribution<> tri011(0, 1, 1); // Using default RealType double.
// mode is upper