| 1 | // |
| 2 | // Copyright 2020 Debabrata Mandal <mandaldebabrata123@gmail.com> |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0 |
| 5 | // See accompanying file LICENSE_1_0.txt or copy at |
| 6 | // http://www.boost.org/LICENSE_1_0.txt |
| 7 | // |
| 8 | |
| 9 | #include <boost/gil/histogram.hpp> |
| 10 | |
| 11 | #include <boost/core/lightweight_test.hpp> |
| 12 | |
| 13 | namespace gil = boost::gil; |
| 14 | |
| 15 | void check_cumulative() |
| 16 | { |
| 17 | gil::histogram<int> h1; |
| 18 | for (int i = 0; i < 8; i++) |
| 19 | { |
| 20 | h1(i) = 1; |
| 21 | } |
| 22 | auto h2 = cumulative_histogram(hist: h1); |
| 23 | bool check1 = true; |
| 24 | for (int i = 0; i < 8; i++) |
| 25 | { |
| 26 | if(h2(i) != i+1) |
| 27 | check1 = false; |
| 28 | } |
| 29 | BOOST_TEST(check1); |
| 30 | |
| 31 | gil::histogram<int , int> h3; |
| 32 | h3(1, 3) = 1; |
| 33 | h3(1, 4) = 2; |
| 34 | h3(2, 1) = 3; |
| 35 | h3(2, 2) = 1; |
| 36 | h3(2, 5) = 2; |
| 37 | h3(3, 2) = 3; |
| 38 | h3(3, 9) = 1; |
| 39 | auto h4 = cumulative_histogram(hist: h3); |
| 40 | BOOST_TEST(h4(1, 3) == 1); |
| 41 | BOOST_TEST(h4(1, 4) == 3); |
| 42 | BOOST_TEST(h4(2, 1) == 3); |
| 43 | BOOST_TEST(h4(2, 2) == 4); |
| 44 | BOOST_TEST(h4(2, 5) == 9); |
| 45 | BOOST_TEST(h4(3, 2) == 7); |
| 46 | BOOST_TEST(h4(3, 9) == 13); |
| 47 | } |
| 48 | |
| 49 | int main() { |
| 50 | |
| 51 | check_cumulative(); |
| 52 | |
| 53 | return boost::report_errors(); |
| 54 | } |
| 55 | |