You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

timedata_tests.cpp 1019B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2011-2014 The Bitcoin Core developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. //
  5. #include "timedata.h"
  6. #include "test/test_bitcoin.h"
  7. #include <boost/test/unit_test.hpp>
  8. using namespace std;
  9. BOOST_FIXTURE_TEST_SUITE(timedata_tests, BasicTestingSetup)
  10. BOOST_AUTO_TEST_CASE(util_MedianFilter)
  11. {
  12. CMedianFilter<int> filter(5, 15);
  13. BOOST_CHECK_EQUAL(filter.median(), 15);
  14. filter.input(20); // [15 20]
  15. BOOST_CHECK_EQUAL(filter.median(), 17);
  16. filter.input(30); // [15 20 30]
  17. BOOST_CHECK_EQUAL(filter.median(), 20);
  18. filter.input(3); // [3 15 20 30]
  19. BOOST_CHECK_EQUAL(filter.median(), 17);
  20. filter.input(7); // [3 7 15 20 30]
  21. BOOST_CHECK_EQUAL(filter.median(), 15);
  22. filter.input(18); // [3 7 18 20 30]
  23. BOOST_CHECK_EQUAL(filter.median(), 18);
  24. filter.input(0); // [0 3 7 18 30]
  25. BOOST_CHECK_EQUAL(filter.median(), 7);
  26. }
  27. BOOST_AUTO_TEST_SUITE_END()