2022-06-08 01:36:46 +02:00
|
|
|
// Copyright (c) 2014-2022 The Dash Core developers
|
2016-12-14 16:28:55 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <governance/governance.h>
|
2016-12-14 16:28:55 +01:00
|
|
|
|
2022-02-25 18:19:25 +01:00
|
|
|
#include <test/util/setup_common.h>
|
2016-12-14 16:28:55 +01:00
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(ratecheck_tests, BasicTestingSetup)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ratecheck_test)
|
|
|
|
{
|
|
|
|
CRateCheckBuffer buffer;
|
|
|
|
|
|
|
|
BOOST_CHECK(buffer.GetCount() == 0);
|
2018-02-21 20:26:53 +01:00
|
|
|
BOOST_CHECK(buffer.GetMinTimestamp() == std::numeric_limits<int64_t>::max());
|
2016-12-14 16:28:55 +01:00
|
|
|
BOOST_CHECK(buffer.GetMaxTimestamp() == 0);
|
|
|
|
BOOST_CHECK(buffer.GetRate() == 0.0);
|
|
|
|
|
|
|
|
buffer.AddTimestamp(1);
|
|
|
|
|
2018-01-26 02:10:45 +01:00
|
|
|
BOOST_TEST_MESSAGE("buffer.GetMinTimestamp() = " << buffer.GetMinTimestamp());
|
2016-12-14 16:28:55 +01:00
|
|
|
|
|
|
|
BOOST_CHECK(buffer.GetCount() == 1);
|
|
|
|
BOOST_CHECK(buffer.GetMinTimestamp() == 1);
|
|
|
|
BOOST_CHECK(buffer.GetMaxTimestamp() == 1);
|
|
|
|
BOOST_CHECK(buffer.GetRate() == 0.0);
|
|
|
|
|
|
|
|
buffer.AddTimestamp(2);
|
|
|
|
BOOST_CHECK(buffer.GetCount() == 2);
|
|
|
|
BOOST_CHECK(buffer.GetMinTimestamp() == 1);
|
|
|
|
BOOST_CHECK(buffer.GetMaxTimestamp() == 2);
|
2017-08-23 16:22:23 +02:00
|
|
|
//BOOST_CHECK(fabs(buffer.GetRate() - 2.0) < 1.0e-9);
|
|
|
|
BOOST_CHECK(buffer.GetRate() == 0.0);
|
2016-12-14 16:28:55 +01:00
|
|
|
|
|
|
|
buffer.AddTimestamp(3);
|
|
|
|
BOOST_CHECK(buffer.GetCount() == 3);
|
|
|
|
BOOST_CHECK(buffer.GetMinTimestamp() == 1);
|
|
|
|
BOOST_CHECK(buffer.GetMaxTimestamp() == 3);
|
|
|
|
|
|
|
|
int64_t nMin = buffer.GetMinTimestamp();
|
|
|
|
int64_t nMax = buffer.GetMaxTimestamp();
|
|
|
|
double dRate = buffer.GetRate();
|
|
|
|
|
2018-01-26 02:10:45 +01:00
|
|
|
BOOST_TEST_MESSAGE("buffer.GetCount() = " << buffer.GetCount());
|
|
|
|
BOOST_TEST_MESSAGE("nMin = " << nMin);
|
|
|
|
BOOST_TEST_MESSAGE("nMax = " << nMax);
|
|
|
|
BOOST_TEST_MESSAGE("buffer.GetRate() = " << dRate);
|
2016-12-14 16:28:55 +01:00
|
|
|
|
2017-08-23 16:22:23 +02:00
|
|
|
//BOOST_CHECK(fabs(buffer.GetRate() - (3.0/2.0)) < 1.0e-9);
|
|
|
|
BOOST_CHECK(buffer.GetRate() == 0.0);
|
2016-12-14 16:28:55 +01:00
|
|
|
|
|
|
|
buffer.AddTimestamp(4);
|
|
|
|
BOOST_CHECK(buffer.GetCount() == 4);
|
|
|
|
BOOST_CHECK(buffer.GetMinTimestamp() == 1);
|
|
|
|
BOOST_CHECK(buffer.GetMaxTimestamp() == 4);
|
2017-08-23 16:22:23 +02:00
|
|
|
//BOOST_CHECK(fabs(buffer.GetRate() - (4.0/3.0)) < 1.0e-9);
|
|
|
|
BOOST_CHECK(buffer.GetRate() == 0.0);
|
2016-12-14 16:28:55 +01:00
|
|
|
|
|
|
|
buffer.AddTimestamp(5);
|
|
|
|
BOOST_CHECK(buffer.GetCount() == 5);
|
|
|
|
BOOST_CHECK(buffer.GetMinTimestamp() == 1);
|
|
|
|
BOOST_CHECK(buffer.GetMaxTimestamp() == 5);
|
|
|
|
BOOST_CHECK(fabs(buffer.GetRate() - (5.0/4.0)) < 1.0e-9);
|
|
|
|
|
|
|
|
buffer.AddTimestamp(6);
|
|
|
|
BOOST_CHECK(buffer.GetCount() == 5);
|
|
|
|
BOOST_CHECK(buffer.GetMinTimestamp() == 2);
|
|
|
|
BOOST_CHECK(buffer.GetMaxTimestamp() == 6);
|
|
|
|
BOOST_CHECK(fabs(buffer.GetRate() - (5.0/4.0)) < 1.0e-9);
|
|
|
|
|
|
|
|
CRateCheckBuffer buffer2;
|
|
|
|
|
2018-01-26 02:10:45 +01:00
|
|
|
BOOST_TEST_MESSAGE("Before loop tests");
|
2016-12-14 16:28:55 +01:00
|
|
|
for(int64_t i = 1; i < 11; ++i) {
|
2018-01-26 02:10:45 +01:00
|
|
|
BOOST_TEST_MESSAGE("In loop: i = " << i);
|
2016-12-14 16:28:55 +01:00
|
|
|
buffer2.AddTimestamp(i);
|
|
|
|
BOOST_CHECK(buffer2.GetCount() == (i <= 5 ? i : 5));
|
2018-02-21 20:26:53 +01:00
|
|
|
BOOST_CHECK(buffer2.GetMinTimestamp() == std::max(int64_t(1), i - 4));
|
2016-12-14 16:28:55 +01:00
|
|
|
BOOST_CHECK(buffer2.GetMaxTimestamp() == i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|