aboutsummaryrefslogtreecommitdiff
path: root/src/test/util_tests.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2011-09-28 21:35:58 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-09-28 21:35:58 +0200
commita8b95ce6ed5e84d34748ecdd0ff1db4d03377cf0 (patch)
treef416d18e89f6e619a84d9e316134afc5380df282 /src/test/util_tests.cpp
parent59020408744664fde902406cf41de125859d461f (diff)
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
Diffstat (limited to 'src/test/util_tests.cpp')
-rw-r--r--src/test/util_tests.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
new file mode 100644
index 0000000000..337d901277
--- /dev/null
+++ b/src/test/util_tests.cpp
@@ -0,0 +1,36 @@
+#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()