52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
/*
|
|
* This file is part of the Flowee project
|
|
* Copyright (C) 2011-2015 The Bitcoin Core developers
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
//
|
|
#include "timedata.h"
|
|
#include "test/test_bitcoin.h"
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(timedata_tests, BasicTestingSetup)
|
|
|
|
BOOST_AUTO_TEST_CASE(util_MedianFilter)
|
|
{
|
|
CMedianFilter<int> filter(5, 15);
|
|
|
|
BOOST_CHECK_EQUAL(filter.median(), 15);
|
|
|
|
filter.input(20); // [15 20]
|
|
BOOST_CHECK_EQUAL(filter.median(), 17);
|
|
|
|
filter.input(30); // [15 20 30]
|
|
BOOST_CHECK_EQUAL(filter.median(), 20);
|
|
|
|
filter.input(3); // [3 15 20 30]
|
|
BOOST_CHECK_EQUAL(filter.median(), 17);
|
|
|
|
filter.input(7); // [3 7 15 20 30]
|
|
BOOST_CHECK_EQUAL(filter.median(), 15);
|
|
|
|
filter.input(18); // [3 7 18 20 30]
|
|
BOOST_CHECK_EQUAL(filter.median(), 18);
|
|
|
|
filter.input(0); // [0 3 7 18 30]
|
|
BOOST_CHECK_EQUAL(filter.median(), 7);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|