2 * Copyright Nick Thompson, 2019
3 * Use, modification and distribution are subject to the
4 * Boost Software License, Version 1.0. (See accompanying file
5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include "math_unit_test.hpp"
12 #include <boost/core/demangle.hpp>
13 #include <boost/math/distributions/empirical_cumulative_distribution_function.hpp>
14 #ifdef BOOST_HAS_FLOAT128
15 #include <boost/multiprecision/float128.hpp>
16 using boost::multiprecision::float128;
19 using boost::math::empirical_cumulative_distribution_function;
24 std::vector<Z> v{6,3,4,1,2,5};
26 auto ecdf = empirical_cumulative_distribution_function(std::move(v));
28 CHECK_ULP_CLOSE(1.0/6.0, ecdf(1), 1);
29 CHECK_ULP_CLOSE(2.0/6.0, ecdf(2), 1);
30 CHECK_ULP_CLOSE(3.0/6.0, ecdf(3), 1);
31 CHECK_ULP_CLOSE(4.0/6.0, ecdf(4), 1);
32 CHECK_ULP_CLOSE(5.0/6.0, ecdf(5), 1);
33 CHECK_ULP_CLOSE(6.0/6.0, ecdf(6), 1);
37 v = {6,3,4,1,1,1,2,4};
38 ecdf = empirical_cumulative_distribution_function(std::move(v));
39 CHECK_ULP_CLOSE(3.0/8.0, ecdf(1), 1);
40 CHECK_ULP_CLOSE(4.0/8.0, ecdf(2), 1);
41 CHECK_ULP_CLOSE(5.0/8.0, ecdf(3), 1);
42 CHECK_ULP_CLOSE(7.0/8.0, ecdf(4), 1);
43 CHECK_ULP_CLOSE(7.0/8.0, ecdf(5), 1);
44 CHECK_ULP_CLOSE(8.0/8.0, ecdf(6), 1);
51 std::vector<Real> v(n);
52 for (size_t i = 0; i < n; ++i) {
53 v[i] = Real(i+1)/Real(n);
56 auto ecdf = empirical_cumulative_distribution_function(std::move(v));
58 for (size_t i = 0; i < n; ++i) {
59 CHECK_ULP_CLOSE(Real(i+1)/Real(n), ecdf(Real(i+1)/Real(n)), 1);
66 test_uniform_z<int>();
67 test_uniform<double>();
68 return boost::math::test::report_errors();