Skip to content

Commit

Permalink
Merge #10280: [test] Unit test amount.h/amount.cpp
Browse files Browse the repository at this point in the history
dcb69fd [test] Unit test amount.h/amount.cpp (Jimmy Song)

Tree-SHA512: dc50e6158322a282a8b8b60c8eab7ce327a33c48113a1455b8a1784f07e6277ad499e85ec978199468a2dc34e9e288287c8803c215f810fa2d841cdda9a414f5
  • Loading branch information
MarcoFalke committed Apr 26, 2017
2 parents cf57825 + dcb69fd commit 47535d7
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/test/amount_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@

BOOST_FIXTURE_TEST_SUITE(amount_tests, BasicTestingSetup)

BOOST_AUTO_TEST_CASE(MoneyRangeTest)
{
BOOST_CHECK_EQUAL(MoneyRange(CAmount(-1)), false);
BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY + CAmount(1)), false);
BOOST_CHECK_EQUAL(MoneyRange(CAmount(1)), true);
}

BOOST_AUTO_TEST_CASE(GetFeeTest)
{
CFeeRate feeRate;
CFeeRate feeRate, altFeeRate;

feeRate = CFeeRate(0);
// Must always return 0
Expand Down Expand Up @@ -53,6 +60,11 @@ BOOST_AUTO_TEST_CASE(GetFeeTest)
BOOST_CHECK_EQUAL(feeRate.GetFee(8), -1); // Special case: returns -1 instead of 0
BOOST_CHECK_EQUAL(feeRate.GetFee(9), -1);

// check alternate constructor
feeRate = CFeeRate(1000);
altFeeRate = CFeeRate(feeRate);
BOOST_CHECK_EQUAL(feeRate.GetFee(100), altFeeRate.GetFee(100));

// Check full constructor
// default value
BOOST_CHECK(CFeeRate(CAmount(-1), 1000) == CFeeRate(-1));
Expand All @@ -68,4 +80,28 @@ BOOST_AUTO_TEST_CASE(GetFeeTest)
CFeeRate(MAX_MONEY, std::numeric_limits<size_t>::max() >> 1).GetFeePerK();
}

BOOST_AUTO_TEST_CASE(BinaryOperatorTest)
{
CFeeRate a, b;
a = CFeeRate(1);
b = CFeeRate(2);
BOOST_CHECK(a < b);
BOOST_CHECK(b > a);
BOOST_CHECK(a == a);
BOOST_CHECK(a <= b);
BOOST_CHECK(a <= a);
BOOST_CHECK(b >= a);
BOOST_CHECK(b >= b);
// a should be 0.00000002 BTC/kB now
a += a;
BOOST_CHECK(a == b);
}

BOOST_AUTO_TEST_CASE(ToStringTest)
{
CFeeRate feeRate;
feeRate = CFeeRate(1);
BOOST_CHECK_EQUAL(feeRate.ToString(), "0.00000001 BTC/kB");
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 47535d7

Please sign in to comment.