| 1 | // (C) Copyright Eric Niebler, Olivier Gygi 2006. |
| 2 | // Use, modification and distribution are subject to the |
| 3 | // Boost Software License, Version 1.0. (See accompanying file |
| 4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #include <boost/test/unit_test.hpp> |
| 7 | #include <boost/accumulators/accumulators.hpp> |
| 8 | #include <boost/accumulators/statistics/stats.hpp> |
| 9 | #include <boost/accumulators/statistics/weighted_sum.hpp> |
| 10 | #include <boost/accumulators/statistics/variates/covariate.hpp> |
| 11 | |
| 12 | using namespace boost; |
| 13 | using namespace unit_test; |
| 14 | using namespace accumulators; |
| 15 | |
| 16 | /////////////////////////////////////////////////////////////////////////////// |
| 17 | // test_stat |
| 18 | // |
| 19 | void test_stat() |
| 20 | { |
| 21 | accumulator_set<int, stats<tag::weighted_sum, tag::weighted_sum_of_variates<int, tag::covariate1> >, int> acc; |
| 22 | |
| 23 | acc(1, weight = 2, covariate1 = 3); |
| 24 | BOOST_CHECK_EQUAL(2, weighted_sum(acc)); |
| 25 | BOOST_CHECK_EQUAL(6, weighted_sum_of_variates(acc)); |
| 26 | |
| 27 | acc(2, weight = 3, covariate1 = 6); |
| 28 | BOOST_CHECK_EQUAL(8, weighted_sum(acc)); |
| 29 | BOOST_CHECK_EQUAL(24, weighted_sum_of_variates(acc)); |
| 30 | |
| 31 | acc(4, weight = 6, covariate1 = 9); |
| 32 | BOOST_CHECK_EQUAL(32, weighted_sum(acc)); |
| 33 | BOOST_CHECK_EQUAL(78, weighted_sum_of_variates(acc)); |
| 34 | } |
| 35 | |
| 36 | /////////////////////////////////////////////////////////////////////////////// |
| 37 | // init_unit_test_suite |
| 38 | // |
| 39 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
| 40 | { |
| 41 | test_suite *test = BOOST_TEST_SUITE("weighted_sum test" ); |
| 42 | |
| 43 | test->add(BOOST_TEST_CASE(&test_stat)); |
| 44 | |
| 45 | return test; |
| 46 | } |
| 47 | |