diff options
author | Jimmy Song <jaejoon@gmail.com> | 2017-04-25 21:04:11 -0700 |
---|---|---|
committer | Jimmy Song <jaejoon@gmail.com> | 2017-04-26 07:25:57 -0700 |
commit | dcb69fde5aae3ef572e299e57a45712f005daf8b (patch) | |
tree | a560a77a2ddb11611e4e3f5f5d73e9d4ff2fe916 /src | |
parent | e0a7e1994e6f3ebbf076feb50552440a365fd317 (diff) |
[test] Unit test amount.h/amount.cpp
Add tests for MoneyRange, binary operators, ToString and a constructor
Diffstat (limited to 'src')
-rw-r--r-- | src/test/amount_tests.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp index fd6f88b366..c95def5e87 100644 --- a/src/test/amount_tests.cpp +++ b/src/test/amount_tests.cpp @@ -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 @@ -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)); @@ -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() |