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

Add variance of N-sided die as unit test [CI SKIP]

This commit is contained in:
Nick Thompson
2019-01-18 10:00:43 -07:00
parent 8930420005
commit ff366e85a2
2 changed files with 20 additions and 3 deletions

View File

@@ -228,6 +228,23 @@ void test_variance()
}
Real m2 = boost::math::tools::variance(v);
BOOST_TEST(abs(m1 - m2) < tol*abs(m1));
// Wikipedia example for a variance of N sided die:
// https://en.wikipedia.org/wiki/Variance
for (size_t j = 16; j < 2048; j *= 2)
{
v.resize(1024);
Real n = v.size();
for (size_t i = 0; i < v.size(); ++i)
{
v[i] = i + 1;
}
sigma_sq = boost::math::tools::variance(v);
BOOST_TEST(abs(sigma_sq - (n*n-1)/Real(12)) <= tol*sigma_sq);
}
}
template<class Z>