bitcoin/src/test/util_tests.cpp
Wladimir J. van der Laan a8b95ce6ed use median filter for peer-reported reported number of blocks
- fixes problem that one misconfigured or malicious node can mess up progress bar
- implementation in src/util.h
- testcase in src/test/util_tests.cpp
2011-09-28 21:35:58 +02:00

36 lines
787 B
C++

#include <vector>
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include "../util.h"
using namespace std;
BOOST_AUTO_TEST_SUITE(util_tests)
BOOST_AUTO_TEST_CASE(util_MedianFilter)
{
CMedianFilter<int> filter(5, 15);
BOOST_CHECK(filter.median() == 15);
filter.input(20); // [15 20]
BOOST_CHECK(filter.median() == 17);
filter.input(30); // [15 20 30]
BOOST_CHECK(filter.median() == 20);
filter.input(3); // [3 15 20 30]
BOOST_CHECK(filter.median() == 17);
filter.input(7); // [3 7 15 20 30]
BOOST_CHECK(filter.median() == 15);
filter.input(18); // [3 7 18 20 30]
BOOST_CHECK(filter.median() == 18);
filter.input(0); // [0 3 7 18 30]
BOOST_CHECK(filter.median() == 7);
}
BOOST_AUTO_TEST_SUITE_END()